tripal_chado.fields.inc 93 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000
  1. <?php
  2. /**
  3. * Implements hook_bundle_fields_info().
  4. *
  5. * This is a Tripal defined hook that supports integration with the
  6. * TripalEntity field.
  7. */
  8. function tripal_chado_bundle_fields_info($entity_type, $bundle) {
  9. $chado_bundle = db_select('chado_bundle', 'cb')
  10. ->fields('cb')
  11. ->condition('bundle_id', $bundle->id)
  12. ->execute()
  13. ->fetchObject();
  14. // Get the details about the mapping of this bundle to the Chado table:
  15. $details = array(
  16. 'chado_cvterm_id' => $chado_bundle->type_id,
  17. 'chado_table' => $chado_bundle->data_table,
  18. 'chado_type_table' => $chado_bundle->type_linker_table,
  19. 'chado_type_column' => $chado_bundle->type_column,
  20. 'chado_type_value' => $chado_bundle->type_value,
  21. );
  22. $info = array();
  23. // Create the fields for each column in the table.
  24. tripal_chado_bundle_fields_info_base($info, $details, $entity_type, $bundle);
  25. // Create custom fields.
  26. tripal_chado_bundle_fields_info_custom($info, $details, $entity_type, $bundle);
  27. // Create fields for linking tables.
  28. tripal_chado_bundle_fields_info_linker($info, $details, $entity_type, $bundle);
  29. return $info;
  30. }
  31. /**
  32. *
  33. * @param unknown $details
  34. */
  35. function tripal_chado_bundle_fields_info_base(&$info, $details, $entity_type, $bundle) {
  36. $table_name = $details['chado_table'];
  37. $type_table = $details['chado_type_table'];
  38. $type_column = $details['chado_type_column'];
  39. $cvterm_id = $details['chado_cvterm_id'];
  40. $type_value = $details['chado_type_value'];
  41. // Iterate through the columns of the table and see if fields have been
  42. // created for each one. If not, then create them.
  43. $schema = chado_get_schema($table_name);
  44. if (!$schema) {
  45. return;
  46. }
  47. $pkey = $schema['primary key'][0];
  48. // Get the list of columns for this table and create a new field for each one.
  49. $columns = $schema['fields'];
  50. foreach ($columns as $column_name => $details) {
  51. // Skip the source columns in the analysis table. We have a custom
  52. // field for those columns
  53. if ($table_name == 'analysis' and ($column_name == 'sourceuri' or
  54. $column_name == 'sourceversion' or $column_name == 'sourcename')) {
  55. continue;
  56. }
  57. // Skip the infraspecific type_id and name from the organism table as we
  58. // have a special field for those.
  59. if ($table_name == 'organism' and ($column_name == 'type_id' or
  60. $column_name == 'infraspecific_name')) {
  61. continue;
  62. }
  63. // Skip the cvterm.is_relationshptype.
  64. if ($table_name == 'cvterm' and $column_name == 'is_relationshiptype') {
  65. continue;
  66. }
  67. // The biosourceprovider_id and taxon_id are handled by custom fields.
  68. if ($table_name == 'biomaterial' and (
  69. $column_name == 'biosourceprovider_id' or $column_name == 'taxon_id')) {
  70. continue;
  71. }
  72. // Don't create base fields for the primary key and the type_id field.
  73. if ($column_name == $pkey or $column_name == $type_column) {
  74. continue;
  75. }
  76. $cvterm = chado_get_semweb_term($table_name, $column_name, array('return_object' => TRUE));
  77. if (!$cvterm) {
  78. tripal_report_error('tripal', TRIPAL_ERROR,
  79. 'Cannot create field for "%table_name.%column_name". Missing an appropriate vocabulary term',
  80. array('%table_name' => $table_name, '%column_name' => $column_name));
  81. drupal_set_message(t('Cannot create field for "%table_name.%column_name". Missing an appropriate vocabulary term',
  82. array('%table_name' => $table_name, '%column_name' => $column_name)), 'error');
  83. continue;
  84. }
  85. $field_name = strtolower($cvterm->dbxref_id->db_id->name . '__' . preg_replace('/[^\w]/', '_', $cvterm->name));
  86. $field_name = substr($field_name, 0, 32);
  87. // Skip the primary key field.
  88. if ($column_name == $schema['primary key'][0]) {
  89. continue;
  90. }
  91. // If the type_id defines the content type and it's part of the
  92. // base table and this column is the type_id then skip it.
  93. if (!$type_table and $type_column and $column_name == $type_column) {
  94. continue;
  95. }
  96. // Skip the type ID as it will be handled by a custom field.
  97. if ($column_name == 'type_id') {
  98. continue;
  99. }
  100. // Set some defaults for the field.
  101. $base_info = array(
  102. 'field_name' => $field_name,
  103. 'type' => '',
  104. 'cardinality' => 1,
  105. 'locked' => FALSE,
  106. 'storage' => array(
  107. 'type' => 'field_chado_storage',
  108. 'sql' => array(),
  109. ),
  110. );
  111. // Alter the field info array depending on the column details.
  112. switch($details['type']) {
  113. case 'char':
  114. $base_info['type'] = 'text';
  115. $base_info['settings']['max_length'] = $details['length'];
  116. break;
  117. case 'varchar':
  118. $base_info['type'] = 'text';
  119. $base_info['settings']['max_length'] = $details['length'];
  120. break;
  121. case 'text':
  122. $base_info['type'] = 'text';
  123. $base_info['settings']['max_length'] = 17179869184;
  124. $base_info['settings']['text_processing'] = 1;
  125. break;
  126. case 'blob':
  127. // not sure how to support a blob field.
  128. continue;
  129. break;
  130. case 'int':
  131. $base_info['type'] = 'number_integer';
  132. break;
  133. case 'float':
  134. $base_info['type'] = 'number_float';
  135. $base_info['settings']['precision'] = 10;
  136. $base_info['settings']['scale'] = 2;
  137. $base_info['settings']['decimal_separator'] = '.';
  138. break;
  139. case 'numeric':
  140. $base_info['type'] = 'number_decimal';
  141. break;
  142. case 'serial':
  143. // Serial fields are most likely not needed as a field.
  144. break;
  145. case 'boolean':
  146. $base_info['type'] = 'list_boolean';
  147. $base_info['settings']['allowed_values'] = array(0 => "No", 1 => "Yes");
  148. break;
  149. case 'datetime':
  150. // Use the Drupal Date and Date API to create the field/widget
  151. $base_info['type'] = 'datetime';
  152. break;
  153. }
  154. // Set some defaults for biomaterial table
  155. if ($table_name == 'biomaterial' and $column_name == 'name') {
  156. $base_info['type'] = 'text';
  157. $base_info['settings']['max_length'] = '2048';
  158. $base_info['settings']['text_processing'] = 0;
  159. }
  160. // Set some default semantic web information
  161. if ($column_name == 'uniquename') {
  162. $base_info['settings']['text_processing'] = 0;
  163. }
  164. // Sometimes the boolean fields are listed as integer. We need to
  165. // correct for that.
  166. if ($column_name == 'is_obsolete' or $column_name == 'is_analysis' or
  167. $column_name == 'is_relationshiptype' or $column_name == 'is_for_definition' or
  168. $column_name == 'is_view' or $column_name == 'is_updateable') {
  169. $base_info['type'] = 'list_boolean';
  170. $base_info['settings']['allowed_values'] = array(0 => "No", 1 => "Yes");
  171. }
  172. //
  173. // PUB TABLE
  174. //
  175. if ($table_name == 'pub' and (
  176. $column_name == 'uniquename' or $column_name == 'title' or
  177. $column_name == 'volumetitle')) {
  178. $base_info['type'] = 'text';
  179. $base_info['settings']['text_processing'] = 0;
  180. }
  181. $info[$field_name] = $base_info;
  182. }
  183. }
  184. /**
  185. *
  186. * @param unknown $details
  187. */
  188. function tripal_chado_bundle_fields_info_custom(&$info, $details, $entity_type, $bundle) {
  189. $table_name = $details['chado_table'];
  190. $type_table = $details['chado_type_table'];
  191. $type_column = $details['chado_type_column'];
  192. $cvterm_id = $details['chado_cvterm_id'];
  193. $type_value = $details['chado_type_value'];
  194. $schema = chado_get_schema($table_name);
  195. // Handle type_id fields that are not the type_column.
  196. if (array_key_exists('type_id', $schema['fields']) and 'type_id' != $type_column) {
  197. $field_name = 'schema__additional_type';
  198. $field_type = 'schema__additional_type';
  199. $info[$field_name] = array(
  200. 'field_name' => $field_name,
  201. 'type' => $field_type,
  202. 'cardinality' => 1,
  203. 'locked' => FALSE,
  204. 'storage' => array(
  205. 'type' => 'field_chado_storage',
  206. ),
  207. );
  208. }
  209. // BASE ARRAYDESIGN TABLE
  210. if ($table_name == 'arraydesign') {
  211. $field_name = 'ncit__technology_platform';
  212. $field_type = 'schema__additional_type';
  213. $info[$field_name] = array(
  214. 'field_name' => $field_name,
  215. 'type' => $field_type,
  216. 'cardinality' => 1,
  217. 'locked' => FALSE,
  218. 'storage' => array(
  219. 'type' => 'field_chado_storage',
  220. ),
  221. );
  222. $field_name = 'efo__substrate_type';
  223. $field_type = 'schema__additional_type';
  224. $info[$field_name] = array(
  225. 'field_name' => $field_name,
  226. 'type' => $field_type,
  227. 'cardinality' => 1,
  228. 'locked' => FALSE,
  229. 'storage' => array(
  230. 'type' => 'field_chado_storage',
  231. ),
  232. );
  233. }
  234. // BASE ORGANISM_ID
  235. if ($table_name != 'organism' and
  236. (array_key_exists('organism_id', $schema['fields']) or
  237. array_key_exists('taxon_id', $schema['fields']))) {
  238. $field_name = 'obi__organism';
  239. $field_type = 'obi__organism';
  240. $info[$field_name] = array(
  241. 'field_name' => $field_name,
  242. 'type' => $field_type,
  243. 'cardinality' => 1,
  244. 'locked' => FALSE,
  245. 'storage' => array(
  246. 'type' => 'field_chado_storage',
  247. ),
  248. );
  249. }
  250. if ($table_name == 'biomaterial') {
  251. $field_name = 'biomaterial__provider_id';
  252. $field_type = 'local__contact';
  253. $info[$field_name] = array(
  254. 'field_name' => $field_name,
  255. 'type' => $field_type,
  256. 'cardinality' => 1,
  257. 'locked' => FALSE,
  258. 'storage' => array(
  259. 'type' => 'field_chado_storage',
  260. ),
  261. );
  262. }
  263. if ($table_name == 'arraydesign') {
  264. $field_name = 'efo__array_manufacturer';
  265. $field_type = 'local__contact';
  266. $info[$field_name] = array(
  267. 'field_name' => $field_name,
  268. 'type' => $field_type,
  269. 'cardinality' => 1,
  270. 'locked' => FALSE,
  271. 'storage' => array(
  272. 'type' => 'field_chado_storage',
  273. ),
  274. );
  275. }
  276. // BASE ORGANISM_ID
  277. if ($table_name == 'cvterm') {
  278. $field_name = 'sio__vocabulary';
  279. $field_type = 'sio__vocabulary';
  280. $info[$field_name] = array(
  281. 'field_name' => $field_name,
  282. 'type' => $field_type,
  283. 'cardinality' => 1,
  284. 'locked' => FALSE,
  285. 'storage' => array(
  286. 'type' => 'field_chado_storage',
  287. ),
  288. );
  289. }
  290. // BASE DBXREF
  291. if (array_key_exists('dbxref_id', $schema['fields'])) {
  292. $field_name = 'data__accession';
  293. $field_type = 'data__accession';
  294. $info[$field_name] = array(
  295. 'field_name' => $field_name,
  296. 'type' => $field_type,
  297. 'cardinality' => 1,
  298. 'locked' => FALSE,
  299. 'storage' => array(
  300. 'type' => 'field_chado_storage',
  301. ),
  302. );
  303. }
  304. // FEATURE MD5CHECKSUM
  305. if ($table_name == 'feature') {
  306. $field_name = 'data__sequence_checksum';
  307. $field_type = 'data__sequence_checksum';
  308. $info[$field_name] = array(
  309. 'field_name' => $field_name,
  310. 'type' => $field_type,
  311. 'cardinality' => 1,
  312. 'locked' => FALSE,
  313. 'storage' => array(
  314. 'type' => 'field_chado_storage',
  315. ),
  316. );
  317. }
  318. // FEATURE RESIDUES
  319. if ($table_name == 'feature') {
  320. $field_name = 'data__sequence';
  321. $field_type = 'data__sequence';
  322. $info[$field_name] = array(
  323. 'field_name' => $field_name,
  324. 'type' => $field_type,
  325. 'cardinality' => 1,
  326. 'locked' => FALSE,
  327. 'storage' => array(
  328. 'type' => 'field_chado_storage',
  329. ),
  330. );
  331. }
  332. // FEATURE SEQLEN
  333. if ($table_name == 'feature') {
  334. $field_name = 'data__sequence_length';
  335. $field_type = 'data__sequence_length';
  336. $info[$field_name] = array(
  337. 'field_name' => $field_name,
  338. 'type' => $field_type,
  339. 'cardinality' => 1,
  340. 'locked' => FALSE,
  341. 'storage' => array(
  342. 'type' => 'field_chado_storage',
  343. ),
  344. );
  345. }
  346. // PROTEIN & CDS
  347. if ($table_name == 'feature' and
  348. ($bundle->label == 'mRNA' or $bundle->label == 'transcript')) {
  349. $field_name = 'data__protein_sequence';
  350. $field_type = 'data__protein_sequence';
  351. $info[$field_name] = array(
  352. 'field_name' => $field_name,
  353. 'type' => $field_type,
  354. 'cardinality' => 1,
  355. 'locked' => FALSE,
  356. 'storage' => array(
  357. 'type' => 'field_chado_storage',
  358. ),
  359. );
  360. // $field_name = 'so__cds';
  361. // $field_type = 'so__cds';
  362. // $info[$field_name] = array(
  363. // 'field_name' => $field_name,
  364. // 'type' => $field_type,
  365. // 'cardinality' => 1,
  366. // 'locked' => FALSE,
  367. // 'storage' => array(
  368. // 'type' => 'field_chado_storage',
  369. // ),
  370. // );
  371. }
  372. // // GENE TRANSCRIPTS
  373. // $rel_table = $table_name . '_relationship';
  374. // if (chado_table_exists($rel_table) and $bundle->label == 'gene') {
  375. // $field_name = 'so__transcript';
  376. // $field_type = 'so__transcript';
  377. // $info[$field_name] = array(
  378. // 'field_name' => $field_name,
  379. // 'type' => $field_type,
  380. // 'cardinality' => FIELD_CARDINALITY_UNLIMITED,
  381. // 'locked' => FALSE,
  382. // 'storage' => array(
  383. // 'type' => 'field_chado_storage',
  384. // ),
  385. // );
  386. // }
  387. // ORGANISM TYPE_ID
  388. if ($table_name == 'organism' and array_key_exists('type_id', $schema['fields'])) {
  389. $field_name = 'taxrank__infraspecific_taxon';
  390. $field_type = 'taxrank__infraspecific_taxon';
  391. $info[$field_name] = array(
  392. 'field_name' => $field_name,
  393. 'type' => $field_type,
  394. 'cardinality' => 1,
  395. 'locked' => FALSE,
  396. 'storage' => array(
  397. 'type' => 'field_chado_storage',
  398. ),
  399. );
  400. }
  401. // FEATUREMAP UNITTYPE_ID
  402. if ($table_name == 'featuremap') {
  403. $field_name = 'uo__unit';
  404. $field_type = 'uo__unit';
  405. $info[$field_name] = array(
  406. 'field_name' => $field_name,
  407. 'type' => $field_type,
  408. 'cardinality' => 1,
  409. 'locked' => FALSE,
  410. 'storage' => array(
  411. 'type' => 'field_chado_storage',
  412. ),
  413. );
  414. }
  415. // Analysis source
  416. if ($table_name == 'analysis') {
  417. $field_name = 'local__source_data';
  418. $field_type = 'local__source_data';
  419. $info[$field_name] = array(
  420. 'field_name' => $field_name,
  421. 'type' => $field_type,
  422. 'cardinality' => 1,
  423. 'locked' => FALSE,
  424. 'storage' => array(
  425. 'type' => 'field_chado_storage',
  426. ),
  427. );
  428. }
  429. // Add an image field to the Organism type. This is a Drupal field and
  430. // not stored in Chado, but is used for backwards compatibility.
  431. if ($table_name == 'organism') {
  432. $field_name = 'data__image';
  433. $info[$field_name] = array(
  434. 'field_name' => $field_name,
  435. 'type' => 'image',
  436. 'cardinality' => 1,
  437. 'locked' => FALSE,
  438. 'storage' => array(
  439. 'type' => 'field_sql_storage',
  440. ),
  441. );
  442. }
  443. // Add field for viewing the phylogenetic tree.
  444. if ($table_name == 'phylotree') {
  445. $field_name = 'operation__phylotree_vis';
  446. $field_type = 'operation__phylotree_vis';
  447. $info[$field_name] = array(
  448. 'field_name' => $field_name,
  449. 'type' => $field_type,
  450. 'cardinality' => 1,
  451. 'locked' => FALSE,
  452. 'storage' => array(
  453. 'type' => 'field_chado_storage',
  454. ),
  455. );
  456. }
  457. // Protocol.
  458. if ($table_name != 'protocol' and
  459. array_key_exists('protocol_id', $schema['fields'])) {
  460. $field_name = 'sep__protocol';
  461. $field_type = 'sep__protocol';
  462. $info[$field_name] = array(
  463. 'field_name' => $field_name,
  464. 'type' => $field_type,
  465. 'cardinality' => 1,
  466. 'locked' => FALSE,
  467. 'storage' => array(
  468. 'type' => 'field_chado_storage',
  469. ),
  470. );
  471. }
  472. // Assay operator.
  473. if ($table_name == 'assay') {
  474. $field_name = 'assay__operator_id';
  475. $field_type = 'local__contact';
  476. $info[$field_name] = array(
  477. 'field_name' => $field_name,
  478. 'type' => $field_type,
  479. 'cardinality' => 1,
  480. 'locked' => FALSE,
  481. 'storage' => array(
  482. 'type' => 'field_chado_storage',
  483. ),
  484. );
  485. $field_name = 'efo__array_design';
  486. $field_type = 'efo__array_design';
  487. $info[$field_name] = array(
  488. 'field_name' => $field_name,
  489. 'type' => $field_type,
  490. 'cardinality' => 1,
  491. 'locked' => FALSE,
  492. 'storage' => array(
  493. 'type' => 'field_chado_storage',
  494. ),
  495. );
  496. }
  497. // For the pub_id field in the base table.
  498. $schema = chado_get_schema($table_name);
  499. if (array_key_exists('pub_id', $schema['fields'])) {
  500. // Remove the schema__publication added by the
  501. // tripal_chado_bunde_instnaces_info_base function.
  502. unset($info['schema__publication']);
  503. $field_name = 'schema__publication_single';
  504. $field_type = 'schema__publication';
  505. $info[$field_name] = array(
  506. 'field_name' => $field_name,
  507. 'type' => $field_type,
  508. 'cardinality' => 1,
  509. 'locked' => FALSE,
  510. 'storage' => array(
  511. 'type' => 'field_chado_storage',
  512. ),
  513. );
  514. }
  515. }
  516. /**
  517. *
  518. * @param $details
  519. */
  520. function tripal_chado_bundle_fields_info_linker(&$info, $details, $entity_type, $bundle) {
  521. $table_name = $details['chado_table'];
  522. $type_table = $details['chado_type_table'];
  523. $type_column = $details['chado_type_column'];
  524. $cvterm_id = $details['chado_cvterm_id'];
  525. $type_value = $details['chado_type_value'];
  526. // CONTACTS
  527. $contact_table = $table_name . '_contact';
  528. if (chado_table_exists($contact_table)) {
  529. $schema = chado_get_schema($contact_table);
  530. $pkey = $schema['primary key'][0];
  531. $field_name = $table_name . '_contact';
  532. $field_type = 'chado_linker__contact';
  533. $info[$field_name] = array(
  534. 'field_name' => $field_name,
  535. 'type' => $field_type,
  536. 'cardinality' => FIELD_CARDINALITY_UNLIMITED,
  537. 'locked' => FALSE,
  538. 'storage' => array(
  539. 'type' => 'field_chado_storage',
  540. ),
  541. );
  542. }
  543. // DBXREF
  544. $dbxref_table = $table_name . '_dbxref';
  545. if (chado_table_exists($dbxref_table)) {
  546. $field_name = 'sbo__database_cross_reference';
  547. $field_type = 'sbo__database_cross_reference';
  548. $info[$field_name] = array(
  549. 'field_name' => $field_name,
  550. 'type' => $field_type,
  551. 'cardinality' => FIELD_CARDINALITY_UNLIMITED,
  552. 'locked' => FALSE,
  553. 'storage' => array(
  554. 'type' => 'field_chado_storage',
  555. ),
  556. );
  557. }
  558. // EXPRESSION
  559. // TODO: this should only show up on gene or mRNA bunldes, not every feature.
  560. // $expression_table = $table_name . '_expression';
  561. // if (chado_table_exists($expression_table)) {
  562. // $field_name = 'go__gene_expression';
  563. // $field_type = 'go__gene_expression';
  564. // $info[$field_name] = array(
  565. // 'field_name' => $field_name,
  566. // 'type' => $field_type,
  567. // 'cardinality' => FIELD_CARDINALITY_UNLIMITED,
  568. // 'locked' => FALSE,
  569. // 'storage' => array(
  570. // 'type' => 'field_chado_storage',
  571. // ),
  572. // );
  573. // }
  574. // FEATURELOC
  575. if ($table_name == 'feature') {
  576. $field_name = 'data__sequence_coordinates';
  577. $field_type = 'data__sequence_coordinates';
  578. $info[$field_name] = array(
  579. 'field_name' => $field_name,
  580. 'type' => $field_type,
  581. 'cardinality' => FIELD_CARDINALITY_UNLIMITED,
  582. 'locked' => FALSE,
  583. 'storage' => array(
  584. 'type' => 'field_chado_storage',
  585. ),
  586. );
  587. }
  588. // FEATUREPOS
  589. if ($table_name == 'feature') {
  590. $field_name = 'ogi__location_on_map';
  591. $field_type = 'ogi__location_on_map';
  592. $info[$field_name] = array(
  593. 'field_name' => $field_name,
  594. 'type' => $field_type,
  595. 'cardinality' => FIELD_CARDINALITY_UNLIMITED,
  596. 'locked' => FALSE,
  597. 'storage' => array(
  598. 'type' => 'field_chado_storage',
  599. ),
  600. );
  601. }
  602. // // GENOTYPE
  603. // $genotype_table = $table_name . '_genotype';
  604. // if (chado_table_exists($genotype_table)) {
  605. // $field_name = 'so__genotype';
  606. // $field_type = 'so__genotype';
  607. // $info[$field_name] = array(
  608. // 'field_name' => $field_name,
  609. // 'type' => $field_type,
  610. // 'cardinality' => FIELD_CARDINALITY_UNLIMITED,
  611. // 'locked' => FALSE,
  612. // 'storage' => array(
  613. // 'type' => 'field_chado_storage',
  614. // ),
  615. // );
  616. // }
  617. // // PHENOTYPE
  618. // $phenotype_table = $table_name . '_phenotype';
  619. // if (chado_table_exists($phenotype_table)) {
  620. // $field_name = 'sbo__phenotype';
  621. // $field_type = 'sbo__phenotype';
  622. // $info[$field_name] = array(
  623. // 'field_name' => $field_name,
  624. // 'type' => $field_type,
  625. // 'cardinality' => FIELD_CARDINALITY_UNLIMITED,
  626. // 'locked' => FALSE,
  627. // 'storage' => array(
  628. // 'type' => 'field_chado_storage',
  629. // ),
  630. // );
  631. // }
  632. // PROPERTIES
  633. $prop_table = $table_name . 'prop';
  634. if (chado_table_exists($prop_table)) {
  635. // Get the list of existing property types for this table.
  636. $sql = 'SELECT DISTINCT type_id FROM {' . $prop_table . '}';
  637. $props = chado_query($sql);
  638. while ($prop = $props->fetchObject()) {
  639. $term = chado_generate_var('cvterm', array('cvterm_id' => $prop->type_id));
  640. // The tripal_analysis_KEGG, tripal_analysis_blast, and
  641. // tripal_analysis_interpro modules store results in the analysisprop
  642. // table which is probably not the best place, but we don't want to
  643. // create a ton of fields for this, so skip them.
  644. if ($prop_table == 'analysisprop' and
  645. ($term->dbxref_id->db_id->name == 'KEGG_BRITE' or
  646. $term->dbxref_id->db_id->name == 'tripal')) {
  647. continue;
  648. }
  649. $field_name = strtolower(preg_replace('/[^\w]/','_', $term->dbxref_id->db_id->name . '__' . $term->name));
  650. $field_name = substr($field_name, 0, 32);
  651. $field_type = 'chado_linker__prop';
  652. $info[$field_name] = array(
  653. 'field_name' => $field_name,
  654. 'type' => $field_type,
  655. 'cardinality' => 1,
  656. 'locked' => FALSE,
  657. 'storage' => array(
  658. 'type' => 'field_chado_storage',
  659. ),
  660. );
  661. }
  662. }
  663. // CVTERMS
  664. $term_table = $table_name . '_cvterm';
  665. if (chado_table_exists($term_table)) {
  666. $schema = chado_get_schema($term_table);
  667. $pkey = $schema['primary key'][0];
  668. $lkey = key($schema['foreign keys'][$table_name]['columns']);
  669. $rkey = $schema['foreign keys'][$table_name]['columns'][$lkey];
  670. $field_name = 'sio__annotation';
  671. $field_type = 'sio__annotation';
  672. $info[$field_name] = array(
  673. 'field_name' => $field_name,
  674. 'type' => $field_type,
  675. 'cardinality' => FIELD_CARDINALITY_UNLIMITED,
  676. 'locked' => FALSE,
  677. 'storage' => array(
  678. 'type' => 'field_chado_storage',
  679. ),
  680. );
  681. }
  682. // PUBLICATIONS
  683. $pub_table = $table_name . '_pub';
  684. if (chado_table_exists($pub_table)) {
  685. $field_name = 'schema__publication';
  686. $field_type = 'schema__publication';
  687. $info[$field_name] = array(
  688. 'field_name' => $field_name,
  689. 'type' => $field_type,
  690. 'cardinality' => FIELD_CARDINALITY_UNLIMITED,
  691. 'locked' => FALSE,
  692. 'storage' => array(
  693. 'type' => 'field_chado_storage',
  694. ),
  695. );
  696. }
  697. // PUBLICATIONS (in reverse)
  698. // We want to be able to show all of the content that a publication links
  699. // to. The sio__references field does that.
  700. if ($table_name == 'pub') {
  701. $field_name = 'sio__references';
  702. $field_type = 'sio__references';
  703. $info[$field_name] = array(
  704. 'field_name' => $field_name,
  705. 'type' => $field_type,
  706. 'cardinality' => FIELD_CARDINALITY_UNLIMITED,
  707. 'locked' => FALSE,
  708. 'storage' => array(
  709. 'type' => 'field_chado_storage',
  710. ),
  711. );
  712. }
  713. // RELATIONSHIPS
  714. // If the linker table does not exists then we don't want to add attach.
  715. $rel_table = $table_name . '_relationship';
  716. if (chado_table_exists($rel_table)) {
  717. $field_name = 'sbo__relationship';
  718. $field_type = 'sbo__relationship';
  719. $info[$field_name] = array(
  720. 'field_name' => $field_name,
  721. 'type' => $field_type,
  722. 'cardinality' => FIELD_CARDINALITY_UNLIMITED,
  723. 'locked' => FALSE,
  724. 'storage' => array(
  725. 'type' => 'field_chado_storage',
  726. ),
  727. );
  728. }
  729. // SYNONYMS
  730. $syn_table = $table_name . '_synonym';
  731. if (chado_table_exists($syn_table)) {
  732. $field_name = 'schema__alternate_name';
  733. $field_type = 'schema__alternate_name';
  734. $info[$field_name] = array(
  735. 'field_name' => $field_name,
  736. 'type' => $field_type,
  737. 'cardinality' => FIELD_CARDINALITY_UNLIMITED,
  738. 'locked' => FALSE,
  739. 'storage' => array(
  740. 'type' => 'field_chado_storage',
  741. ),
  742. 'settings' => array(
  743. ),
  744. );
  745. }
  746. }
  747. /**
  748. * Impelments hook_create_tripalfield_instance().
  749. *
  750. * This is a Tripal defined hook that supports integration with the
  751. * TripalEntity field.
  752. */
  753. function tripal_chado_bundle_instances_info($entity_type, $bundle) {
  754. $chado_bundle = db_select('chado_bundle', 'cb')
  755. ->fields('cb')
  756. ->condition('bundle_id', $bundle->id)
  757. ->execute()
  758. ->fetchObject();
  759. $details = array(
  760. 'chado_cvterm_id' => $chado_bundle->type_id,
  761. 'chado_table' => $chado_bundle->data_table,
  762. 'chado_type_table' => $chado_bundle->type_linker_table,
  763. 'chado_type_column' => $chado_bundle->type_column,
  764. 'chado_type_value' => $chado_bundle->type_value,
  765. );
  766. $info = array();
  767. tripal_chado_bundle_instances_info_base($info, $entity_type, $bundle, $details);
  768. tripal_chado_bundle_instances_info_custom($info, $entity_type, $bundle, $details);
  769. tripal_chado_bundle_instances_info_linker($info, $entity_type, $bundle, $details);
  770. return $info;
  771. }
  772. /**
  773. * Helper function for the hook_create_tripalfield_instance().
  774. *
  775. * Add the field instances that corresond to the columns of the base table.
  776. *
  777. * @param $entity_type
  778. * @param $bundle
  779. * @param $details
  780. */
  781. function tripal_chado_bundle_instances_info_base(&$info, $entity_type, $bundle, $details) {
  782. $fields = array();
  783. // Get Chado information
  784. $table_name = $details['chado_table'];
  785. $type_table = $details['chado_type_table'];
  786. $type_column = $details['chado_type_column'];
  787. $cvterm_id = $details['chado_cvterm_id'];
  788. $type_value = $details['chado_type_value'];
  789. // Iterate through the columns of the table and see if fields have been
  790. // created for each one. If not, then create them.
  791. $schema = chado_get_schema($table_name);
  792. if (!$schema) {
  793. return;
  794. }
  795. $pkey = $schema['primary key'][0];
  796. $columns = $schema['fields'];
  797. foreach ($columns as $column_name => $details) {
  798. // Skip the source columns in the analysis table. We have a custom
  799. // field for those columns
  800. if ($table_name == 'analysis' and ($column_name == 'sourceuri' or
  801. $column_name == 'sourceversion' or $column_name == 'sourcename')) {
  802. continue;
  803. }
  804. // Skip the infraspecific type_id and name from the organism table as we
  805. // have a special field for those.
  806. if ($table_name == 'organism' and ($column_name == 'type_id' or
  807. $column_name == 'infraspecific_name')) {
  808. continue;
  809. }
  810. // Skip the cvterm.is_relationshptype.
  811. if ($table_name == 'cvterm' and $column_name == 'is_relationshiptype') {
  812. continue;
  813. }
  814. // The biosourceprovider_id and taxon_id are handled by custom fields.
  815. if ($table_name == 'biomaterial' and (
  816. $column_name == 'biosourceprovider_id' or $column_name == 'taxon_id')) {
  817. continue;
  818. }
  819. // Don't create base fields for the primary key and the type_id field.
  820. if ($column_name == $pkey or $column_name == $type_column) {
  821. continue;
  822. }
  823. $cvterm = chado_get_semweb_term($table_name, $column_name, array('return_object' => TRUE));
  824. if (!$cvterm) {
  825. // We already provided an error when creating the base field. So
  826. // don't create another one here.
  827. continue;
  828. }
  829. $field_name = strtolower($cvterm->dbxref_id->db_id->name . '__' . preg_replace('/[^\w]/', '_', $cvterm->name));
  830. $field_name = substr($field_name, 0, 32);
  831. // Skip the primary key field.
  832. if ($column_name == $schema['primary key'][0]) {
  833. continue;
  834. }
  835. // If the type_id defines the content type and it's part of the
  836. // base table and this column is the type_id then skip it.
  837. if (!$type_table and $type_column and $column_name == $type_column) {
  838. continue;
  839. }
  840. // Skip the type ID as it will be handled by a custom field.
  841. if ($column_name == 'type_id') {
  842. continue;
  843. }
  844. $base_info = array(
  845. 'field_name' => $field_name,
  846. 'entity_type' => 'TripalEntity',
  847. 'bundle' => $bundle->name,
  848. 'label' => ucwords(preg_replace('/_/', ' ', $column_name)),
  849. 'description' => '',
  850. 'required' => FALSE,
  851. 'settings' => array(
  852. 'auto_attach' => TRUE,
  853. 'term_vocabulary' => $cvterm->dbxref_id->db_id->name,
  854. 'term_name' => $cvterm->name,
  855. 'term_accession' => $cvterm->dbxref_id->accession,
  856. 'chado_table' => $table_name,
  857. 'chado_column' => $column_name,
  858. 'base_table' => $table_name,
  859. ),
  860. 'widget' => array(
  861. 'settings' => array(
  862. 'display_label' => 1,
  863. ),
  864. ),
  865. 'display' => array(
  866. 'default' => array(
  867. 'label' => 'inline',
  868. 'region' =>'Left',
  869. 'settings' => array(),
  870. ),
  871. ),
  872. );
  873. // Determine if the field is required.
  874. if (array_key_exists('not null', $details) and $details['not null'] === TRUE) {
  875. $base_info['required'] = TRUE;
  876. }
  877. // Alter the field info array depending on the column details.
  878. switch($details['type']) {
  879. case 'char':
  880. $base_info['widget']['type'] = 'text_textfield';
  881. break;
  882. case 'varchar':
  883. $base_info['widget']['type'] = 'text_textfield';
  884. break;
  885. case 'text':
  886. $base_info['display']['default']['label'] = 'above';
  887. $base_info['widget']['type'] = 'text_textarea';
  888. $base_info['settings']['text_processing'] = '1';
  889. $base_info['settings']['format'] = 'full_html';
  890. break;
  891. case 'blob':
  892. // not sure how to support a blob field.
  893. continue;
  894. break;
  895. case 'int':
  896. $base_info['widget']['type'] = 'number';
  897. break;
  898. case 'float':
  899. $base_info['widget']['type'] = 'number';
  900. break;
  901. case 'numeric':
  902. $base_info['widget']['type'] = 'number';
  903. break;
  904. case 'serial':
  905. // Serial fields are most likely not needed as a field.
  906. break;
  907. case 'boolean':
  908. $base_info['widget']['type'] = 'options_onoff';
  909. $base_info['required'] = FALSE;
  910. break;
  911. case 'datetime':
  912. $base_info['widget']['type'] = 'date_select';
  913. $base_info['widget']['settings']['increment'] = 1;
  914. $base_info['widget']['settings']['tz_handling'] = 'none';
  915. $base_info['widget']['settings']['collapsible'] = TRUE;
  916. // TODO: Add settings so that the minutes increment by 1.
  917. // And turn off the timezone, as the Chado field doesn't support it.
  918. break;
  919. }
  920. // Set some default semantic web information
  921. if ($column_name == 'uniquename') {
  922. $base_info['label'] = 'Identifier';
  923. $base_info['widget']['type'] = 'text_textfield';
  924. if ($details['type'] == 'text') {
  925. unset($base_info['display']['default']['label']);
  926. unset($base_info['settings']['text_processing']);
  927. unset($base_info['settings']['format']);
  928. }
  929. }
  930. if ($base_info['label'] == 'Timeaccessioned') {
  931. $base_info['label'] = 'Time Accessioned';
  932. $base_info['description'] = 'The time that this record was first added to the database.';
  933. }
  934. if ($base_info['label'] == 'Timelastmodified') {
  935. $base_info['label'] = 'Time Last Modified';
  936. $base_info['description'] = 'The time that this record was last modified. The default is the current time.';
  937. }
  938. // Sometimes the boolean fields are listed as integer. We need to
  939. // correct for that.
  940. if ($column_name == 'is_obsolete' or $column_name == 'is_analysis' or
  941. $column_name == 'is_relationshiptype' or $column_name == 'is_for_definition' or
  942. $column_name == 'is_view' or $column_name == 'is_updateable') {
  943. $base_info['widget']['type'] = 'options_onoff';
  944. $base_info['required'] = FALSE;
  945. }
  946. //
  947. // ORGANISM TABLE
  948. //
  949. if ($table_name == 'organism' and $column_name == 'comment') {
  950. $base_info['label'] = 'Description';
  951. }
  952. //
  953. // BIOMATERIAL TABLE
  954. //
  955. if ($table_name == 'biomaterial' and $column_name == 'name') {
  956. $base_info['widget'] = array();
  957. $base_info['widget']['type'] = 'text_textfield';
  958. unset($base_info['display']['default']['label']);
  959. unset($base_info['settings']['text_processing']);
  960. unset($base_info['settings']['format']);
  961. }
  962. //
  963. // FEATUREMAP TABLE
  964. //
  965. if ($table_name == 'featuremap' and $column_name == 'name') {
  966. $base_info['required'] = TRUE;
  967. }
  968. //
  969. // PUB TABLE
  970. //
  971. if ($table_name == 'pub') {
  972. if ($column_name == 'title' or $column_name == 'type_id') {
  973. $base_info['required'] = TRUE;
  974. }
  975. if($column_name == 'uniquename' or $column_name == 'title' or $column_name == 'volumetitle') {
  976. $base_info['widget']['type'] = 'text_textfield';
  977. $base_info['settings']['text_processing'] = '0';
  978. }
  979. if($column_name == 'uniquename') {
  980. $base_info['label'] = 'Unique Local Identifier';
  981. $base_info['required'] = TRUE;
  982. $base_info['description'] = 'This publication is housed in Chado whic requires a unique identifer (or name) be provided for every publication. This identifier need not be shown to end-users but it is required. Each site must decide on a format for this unique name.';
  983. }
  984. if($column_name == 'title') {
  985. $base_info['description'] = 'The title of the published work.';
  986. }
  987. if($column_name == 'series_name') {
  988. $base_info['description'] = 'The name media that produces a series of publications (e.g. journal, conference proceedings, etc.).';
  989. }
  990. if($column_name == 'issue') {
  991. $base_info['description'] = 'The issue of the series (e.g. journal) where the publication was printed.';
  992. }
  993. if($column_name == 'volume') {
  994. $base_info['description'] = 'The volume of the series (e.g. journal) where the publication was printed.';
  995. }
  996. if($column_name == 'pyear') {
  997. $base_info['label'] = 'Publication Year';
  998. $base_info['required'] = TRUE;
  999. }
  1000. if($column_name == 'pages') {
  1001. $base_info['label'] = 'Page Numbers';
  1002. }
  1003. if($column_name == 'pubplace') {
  1004. $base_info['label'] = 'Publication Location';
  1005. }
  1006. if($column_name == 'volumetitle') {
  1007. $base_info['label'] = 'Volumn Title';
  1008. $base_info['label'] = 'The title of the volume (if applicable).';
  1009. }
  1010. if($column_name == 'miniref') {
  1011. $base_info['label'] = 'Mini Local identifier';
  1012. $base_info['description'] = 'Some sites use small identifiers for each publication. if your site uses this please provide the proper miniref for this publication.';
  1013. }
  1014. }
  1015. //
  1016. // ANALYSIS TABLE
  1017. //
  1018. if ($table_name == 'analysis' and $column_name == 'name') {
  1019. $base_info['required'] = TRUE;
  1020. }
  1021. if ($table_name == 'analysis' and $column_name == 'program') {
  1022. $base_info['description'] = 'The program name (e.g. blastx, blastp, sim4, genscan. If the analysis was not derived from a software package then provide a very brief description of the pipeline, workflow or method.';
  1023. $base_info['label'] = 'Program, Pipeline, Workflow or Method Name';
  1024. }
  1025. if ($table_name == 'analysis' and $column_name == 'algorithm') {
  1026. $base_info['label'] = 'Algorithm';
  1027. $base_info['description'] = 'The name of the algorithm used to produce the dataset if different from the program.';
  1028. }
  1029. if ($table_name == 'analysis' and $column_name == 'programversion') {
  1030. $base_info['label'] = 'Program Version';
  1031. $base_info['description'] = 'The version of the program used to perform this analysis. (e.g. TBLASTX 2.0MP-WashU [09-Nov-2000]. Enter "n/a" if no version is available or applicable.';
  1032. }
  1033. if ($table_name == 'analysis' and $column_name == 'timeexecuted') {
  1034. $base_info['label'] = 'Date Performed';
  1035. $base_info['description'] = 'The date and time when the analysis was performed.';
  1036. }
  1037. if ($table_name == 'analysis' and ($column_name == 'sourceuri' or
  1038. $column_name == 'sourceversion' or $column_name == 'sourcename')) {
  1039. // Skip the source columns in the analysis table. We have a custom
  1040. // field for those columns
  1041. continue;
  1042. }
  1043. //
  1044. // PROJECT TABLE
  1045. //
  1046. if ($table_name == 'project' and $column_name == 'description') {
  1047. $base_info['label'] = 'Short Description';
  1048. }
  1049. //
  1050. // CONTACT TABLE
  1051. //
  1052. if ($table_name == 'contact' and $column_name == 'description') {
  1053. $base_info['label'] = 'Short Description';
  1054. }
  1055. //
  1056. // PROTOCOL TABLE
  1057. //
  1058. if ($table_name == 'protocol') {
  1059. if ($column_name == 'protocoldescription') {
  1060. $base_info['label'] = 'Protocol Description';
  1061. }
  1062. if ($column_name == 'uri') {
  1063. $base_info['label'] = 'URI';
  1064. $base_info['widget']['type'] = 'text_textfield';
  1065. $base_info['settings']['text_processing'] = '0';
  1066. }
  1067. if ($column_name == 'name') {
  1068. $base_info['widget']['type'] = 'text_textfield';
  1069. $base_info['settings']['text_processing'] = '0';
  1070. }
  1071. if ($column_name == 'hardwaredescription') {
  1072. $base_info['label'] = 'Instrument Description';
  1073. $base_info['description'] = 'The description of instruments used for this protocol';
  1074. }
  1075. if ($column_name == 'softwaredescription') {
  1076. $base_info['label'] = 'Software Description';
  1077. $base_info['description'] = 'The description of software used for this protocol';
  1078. }
  1079. if ($column_name == 'pub_id') {
  1080. $base_info['label'] = 'Publication';
  1081. }
  1082. }
  1083. //
  1084. // ASSAY TABLE
  1085. //
  1086. if ($table_name == 'assay') {
  1087. if ($column_name == 'name') {
  1088. $base_info['widget']['type'] = 'text_textfield';
  1089. $base_info['settings']['text_processing'] = '0';
  1090. $base_info['required'] = TRUE;
  1091. $base_info['description'] = 'A unique name for this assay..';
  1092. }
  1093. if ($column_name == 'protcol_id') {
  1094. $base_info['label'] = 'Protocol';
  1095. }
  1096. if ($column_name == 'arraybatchidentifier') {
  1097. $base_info['label'] = 'Array Batch Identifier';
  1098. $base_info['widget']['type'] = 'text_textfield';
  1099. $base_info['settings']['text_processing'] = '0';
  1100. $base_info['description'] = 'A unique identifier for the array batch.';
  1101. }
  1102. if ($column_name == 'operator_id') {
  1103. $base_info['label'] = 'Operator';
  1104. $base_info['description'] = 'The individual who performed the assay.';
  1105. }
  1106. if ($column_name == 'arrayidentifier') {
  1107. $base_info['label'] = 'Array Identifier';
  1108. $base_info['widget']['type'] = 'text_textfield';
  1109. $base_info['settings']['text_processing'] = '0';
  1110. $base_info['description'] = 'A unique alternate identifier for the array.';
  1111. }
  1112. if ($column_name == 'arraydesign_id') {
  1113. $base_info['label'] = 'Array Design';
  1114. }
  1115. if ($column_name == 'assaydate') {
  1116. $base_info['label'] = 'Assay Date';
  1117. $base_info['description'] = 'The date the assay was performed';
  1118. }
  1119. }
  1120. //
  1121. // ARRAYDESIGN TABLE
  1122. //
  1123. if ($table_name == 'arraydesign') {
  1124. if ($column_name == 'name' or $column_name == 'version' or
  1125. $column_name == 'array_dimensions' or $column_name == 'element_dimensions') {
  1126. $base_info['widget']['type'] = 'text_textfield';
  1127. $base_info['settings']['text_processing'] = '0';
  1128. }
  1129. if ($column_name == 'platformtype_id') {
  1130. $base_info['label'] = 'Platform type';
  1131. }
  1132. if ($column_name == 'substratetype_id') {
  1133. $base_info['label'] = 'Substrate Type';
  1134. }
  1135. if ($column_name == 'manufacturer_id') {
  1136. $base_info['label'] = 'Manufacturer';
  1137. }
  1138. }
  1139. $info[$field_name] = $base_info;
  1140. }
  1141. }
  1142. /**
  1143. * Helper function for the hook_create_tripalfield_instance().
  1144. *
  1145. * Adds custom fields for base fields. These override the settings provided
  1146. * in the tripal_chado_create_tripalfield_instance_base() function.
  1147. *
  1148. * @param $entity_type
  1149. * @param $bundle
  1150. * @param $details
  1151. */
  1152. function tripal_chado_bundle_instances_info_custom(&$info, $entity_type, $bundle, $details) {
  1153. $table_name = $details['chado_table'];
  1154. $type_table = $details['chado_type_table'];
  1155. $type_column = $details['chado_type_column'];
  1156. $cvterm_id = $details['chado_cvterm_id'];
  1157. $type_value = $details['chado_type_value'];
  1158. $schema = chado_get_schema($table_name);
  1159. // An additional type for publications
  1160. if (array_key_exists('type_id', $schema['fields']) and 'type_id' != $type_column) {
  1161. $field_name = 'schema__additional_type';
  1162. $is_required = FALSE;
  1163. if (array_key_exists('not null', $schema['fields']['type_id']) and
  1164. $schema['fields']['type_id']['not null']) {
  1165. $is_required = TRUE;
  1166. }
  1167. $label = ucwords(preg_replace('/_/', ' ', $table_name)) . ' Type';
  1168. $default_vocab = '';
  1169. $parent_term = '';
  1170. switch($table_name) {
  1171. case 'pub':
  1172. $default_vocab = 'tripal_pub';
  1173. $label = 'Publication Type';
  1174. $parent_term = 'TPUB:0000015';
  1175. $description = 'Select the type.';
  1176. break;
  1177. case 'contact':
  1178. $default_vocab = 'tripal_contact';
  1179. $parent_term = 'TContact:0000001';
  1180. $description = 'Select the type.';
  1181. break;
  1182. default:
  1183. $description = t('Enter the name of the term that specifies the type. ' .
  1184. 'The type must be the name of a term in a controlled vocabulary and ' .
  1185. 'the controlled vocabulary should already be loaded into this site.');
  1186. }
  1187. $info[$field_name] = array(
  1188. 'field_name' => $field_name,
  1189. 'entity_type' => $entity_type,
  1190. 'bundle' => $bundle->name,
  1191. 'label' => $label,
  1192. 'description' => $description,
  1193. 'required' => $is_required,
  1194. 'settings' => array(
  1195. 'auto_attach' => TRUE,
  1196. 'chado_table' => $table_name,
  1197. 'chado_column' => 'type_id',
  1198. 'base_table' => $table_name,
  1199. 'vocabulary' => $default_vocab,
  1200. 'parent_term' => $parent_term,
  1201. ),
  1202. 'widget' => array(
  1203. 'type' => 'schema__additional_type_widget',
  1204. 'settings' => array(
  1205. 'display_label' => 1,
  1206. ),
  1207. ),
  1208. 'display' => array(
  1209. 'default' => array(
  1210. 'label' => 'inline',
  1211. 'type' => 'schema__additional_type_formatter',
  1212. 'settings' => array(),
  1213. ),
  1214. ),
  1215. );
  1216. }
  1217. if ($table_name == 'arraydesign') {
  1218. $field_name = 'ncit__technology_platform';
  1219. $default_vocab = '';
  1220. $parent_term = '';
  1221. $description = 'Select the platform type.';
  1222. $info[$field_name] = array(
  1223. 'field_name' => $field_name,
  1224. 'entity_type' => $entity_type,
  1225. 'bundle' => $bundle->name,
  1226. 'label' => 'Platform Type',
  1227. 'description' => $description,
  1228. 'required' => TRUE,
  1229. 'settings' => array(
  1230. 'auto_attach' => TRUE,
  1231. 'chado_table' => $table_name,
  1232. 'chado_column' => 'platformtype_id',
  1233. 'base_table' => $table_name,
  1234. 'vocabulary' => $default_vocab,
  1235. 'parent_term' => $parent_term,
  1236. 'term_vocabulary' => 'NCIT',
  1237. 'term_name' => 'Technology Platform',
  1238. 'term_accession' => 'C45378',
  1239. ),
  1240. 'widget' => array(
  1241. 'type' => 'schema__additional_type_widget',
  1242. 'settings' => array(
  1243. 'display_label' => 1,
  1244. ),
  1245. ),
  1246. 'display' => array(
  1247. 'default' => array(
  1248. 'label' => 'inline',
  1249. 'type' => 'schema__additional_type_formatter',
  1250. 'settings' => array(),
  1251. ),
  1252. ),
  1253. );
  1254. $field_name = 'efo__substrate_type';
  1255. $default_vocab = '';
  1256. $parent_term = '';
  1257. $description = 'Select the substrate type.';
  1258. $info[$field_name] = array(
  1259. 'field_name' => $field_name,
  1260. 'entity_type' => $entity_type,
  1261. 'bundle' => $bundle->name,
  1262. 'label' => 'Substrate Type',
  1263. 'description' => $description,
  1264. 'required' => FALSE,
  1265. 'settings' => array(
  1266. 'auto_attach' => TRUE,
  1267. 'chado_table' => $table_name,
  1268. 'chado_column' => 'substratetype_id',
  1269. 'base_table' => $table_name,
  1270. 'vocabulary' => $default_vocab,
  1271. 'parent_term' => $parent_term,
  1272. 'term_vocabulary' => 'EFO',
  1273. 'term_name' => 'substrate type',
  1274. 'term_accession' => '0005522',
  1275. ),
  1276. 'widget' => array(
  1277. 'type' => 'schema__additional_type_widget',
  1278. 'settings' => array(
  1279. 'display_label' => 1,
  1280. ),
  1281. ),
  1282. 'display' => array(
  1283. 'default' => array(
  1284. 'label' => 'inline',
  1285. 'type' => 'schema__additional_type_formatter',
  1286. 'settings' => array(),
  1287. ),
  1288. ),
  1289. );
  1290. }
  1291. // BASE ORGANISM_ID
  1292. if ($table_name != 'organism' and
  1293. (array_key_exists('organism_id', $schema['fields']) or
  1294. array_key_exists('taxon_id', $schema['fields']))) {
  1295. $field_name = 'obi__organism';
  1296. $is_required = FALSE;
  1297. $table_column = 'organism_id';
  1298. if ($table_name == 'biomaterial') {
  1299. $is_required = FALSE;
  1300. $table_column = 'taxon_id';
  1301. }
  1302. elseif (array_key_exists('not null', $schema['fields']['organism_id']) and
  1303. $schema['fields']['organism_id']['not null']) {
  1304. $is_required = TRUE;
  1305. }
  1306. $info[$field_name] = array(
  1307. 'field_name' => $field_name,
  1308. 'entity_type' => $entity_type,
  1309. 'bundle' => $bundle->name,
  1310. 'label' => 'Organism',
  1311. 'description' => 'The full scientific name for a species..',
  1312. 'required' => $is_required,
  1313. 'settings' => array(
  1314. 'auto_attach' => TRUE,
  1315. 'chado_table' => $table_name,
  1316. 'chado_column' => $table_column,
  1317. 'base_table' => $table_name,
  1318. ),
  1319. 'widget' => array(
  1320. 'type' => 'obi__organism_widget',
  1321. 'settings' => array(
  1322. 'display_label' => 1,
  1323. ),
  1324. ),
  1325. 'display' => array(
  1326. 'default' => array(
  1327. 'label' => 'inline',
  1328. 'type' => 'obi__organism_formatter',
  1329. 'settings' => array(),
  1330. ),
  1331. ),
  1332. );
  1333. }
  1334. if ($table_name == 'biomaterial') {
  1335. $field_name = 'biomaterial__provider_id';
  1336. $field_type = 'local__contact';
  1337. $info[$field_name] = array(
  1338. 'field_name' => $field_name,
  1339. 'entity_type' => $entity_type,
  1340. 'bundle' => $bundle->name,
  1341. 'label' => 'Contact',
  1342. 'description' => 'An indvidual or organization that serves as a contact for this record.',
  1343. 'required' => FALSE,
  1344. 'settings' => array(
  1345. 'auto_attach' => FALSE,
  1346. 'chado_table' => 'biomaterial',
  1347. 'chado_column' => 'biosourceprovider_id',
  1348. 'base_table' => 'biomaterial',
  1349. ),
  1350. 'widget' => array(
  1351. 'type' => 'local__contact_widget',
  1352. 'settings' => array(
  1353. 'display_label' => 1,
  1354. ),
  1355. ),
  1356. 'display' => array(
  1357. 'default' => array(
  1358. 'label' => 'inline',
  1359. 'type' => 'local__contact_formatter',
  1360. 'settings' => array(),
  1361. ),
  1362. ),
  1363. );
  1364. }
  1365. if ($table_name == 'arraydesign') {
  1366. $field_name = 'efo__array_manufacturer';
  1367. $field_type = 'local__contact';
  1368. $info[$field_name] = array(
  1369. 'field_name' => $field_name,
  1370. 'entity_type' => $entity_type,
  1371. 'bundle' => $bundle->name,
  1372. 'label' => 'Manufacturer',
  1373. 'description' => 'A manufacturer\'s contact details',
  1374. 'required' => TRUE,
  1375. 'settings' => array(
  1376. 'auto_attach' => FALSE,
  1377. 'chado_table' => 'arraydesign',
  1378. 'chado_column' => 'manufacturer_id',
  1379. 'base_table' => 'arraydesign',
  1380. 'term_vocabulary' => 'EFO',
  1381. 'term_name' => 'aarray manufacturer',
  1382. 'term_accession' => '0001728',
  1383. ),
  1384. 'widget' => array(
  1385. 'type' => 'local__contact_widget',
  1386. 'settings' => array(
  1387. 'display_label' => 1,
  1388. ),
  1389. ),
  1390. 'display' => array(
  1391. 'default' => array(
  1392. 'label' => 'inline',
  1393. 'type' => 'local__contact_formatter',
  1394. 'settings' => array(),
  1395. ),
  1396. ),
  1397. );
  1398. }
  1399. // BASE CVTERM
  1400. if ($table_name == 'cvterm') {
  1401. $field_name = 'sio__vocabulary';
  1402. $is_required = TRUE;
  1403. $info[$field_name] = array(
  1404. 'field_name' => $field_name,
  1405. 'entity_type' => $entity_type,
  1406. 'bundle' => $bundle->name,
  1407. 'label' => 'Vocabulary',
  1408. 'description' => 'A controlled vocabulary.',
  1409. 'required' => $is_required,
  1410. 'settings' => array(
  1411. 'auto_attach' => TRUE,
  1412. 'chado_table' => $table_name,
  1413. 'chado_column' => 'cv_id',
  1414. 'base_table' => $table_name,
  1415. ),
  1416. 'widget' => array(
  1417. 'type' => 'sio__vocabulary_widget',
  1418. 'settings' => array(
  1419. 'display_label' => 1,
  1420. ),
  1421. ),
  1422. 'display' => array(
  1423. 'default' => array(
  1424. 'label' => 'inline',
  1425. 'type' => 'sio__vocabulary_formatter',
  1426. 'settings' => array(),
  1427. ),
  1428. ),
  1429. );
  1430. }
  1431. // BASE DBXREF
  1432. if (array_key_exists('dbxref_id', $schema['fields'])) {
  1433. $field_name = 'data__accession';
  1434. $info[$field_name] = array(
  1435. 'field_name' => $field_name,
  1436. 'entity_type' => $entity_type,
  1437. 'bundle' => $bundle->name,
  1438. 'label' => 'Accession',
  1439. 'description' => 'This field specifies the unique stable accession (ID) for
  1440. this record. It requires that this site have a database entry.',
  1441. 'required' => FALSE,
  1442. 'settings' => array(
  1443. 'auto_attach' => TRUE,
  1444. 'chado_table' => $table_name,
  1445. 'chado_column' => 'dbxref_id',
  1446. 'base_table' => $table_name,
  1447. ),
  1448. 'widget' => array(
  1449. 'type' => 'data__accession_widget',
  1450. 'settings' => array(
  1451. 'display_label' => 1,
  1452. ),
  1453. ),
  1454. 'display' => array(
  1455. 'default' => array(
  1456. 'label' => 'inline',
  1457. 'type' => 'data__accession_formatter',
  1458. 'settings' => array(),
  1459. ),
  1460. ),
  1461. );
  1462. }
  1463. // FEATURE MD5CHECKSUM
  1464. if ($table_name == 'feature') {
  1465. $field_name = 'data__sequence_checksum';
  1466. $info[$field_name] = array(
  1467. 'field_name' => $field_name,
  1468. 'entity_type' => $entity_type,
  1469. 'bundle' => $bundle->name,
  1470. 'label' => 'Sequence Checksum',
  1471. 'description' => 'The MD5 checksum for the sequence. The checksum here
  1472. will always be unique for the raw unformatted sequence. To verify that the
  1473. sequence has not been corrupted, download the raw sequence and use an MD5 tool
  1474. to calculate the value. If the value calculated is identical the one shown
  1475. here, then the downloaded sequence is uncorrupted.',
  1476. 'required' => FALSE,
  1477. 'settings' => array(
  1478. 'auto_attach' => TRUE,
  1479. 'chado_table' => $table_name,
  1480. 'chado_column' => 'md5checksum',
  1481. 'base_table' => $table_name,
  1482. ),
  1483. 'widget' => array(
  1484. 'type' => 'data__sequence_checksum_widget',
  1485. 'settings' => array(
  1486. 'display_label' => 1,
  1487. 'md5_fieldname' => 'feature__md5checksum',
  1488. ),
  1489. ),
  1490. 'display' => array(
  1491. 'default' => array(
  1492. 'label' => 'inline',
  1493. 'type' => 'data__sequence_checksum_formatter',
  1494. 'settings' => array(),
  1495. ),
  1496. ),
  1497. );
  1498. }
  1499. // FEATURE RESIDUES
  1500. if ($table_name == 'feature') {
  1501. $field_name = 'data__sequence';
  1502. $info[$field_name] = array(
  1503. 'field_name' => $field_name,
  1504. 'entity_type' => $entity_type,
  1505. 'bundle' => $bundle->name,
  1506. 'label' => 'Sequence',
  1507. 'description' => 'One or more molecular sequences, possibly with associated annotation.',
  1508. 'required' => FALSE,
  1509. 'settings' => array(
  1510. 'auto_attach' => FALSE,
  1511. 'chado_table' => $table_name,
  1512. 'chado_column' => 'residues',
  1513. 'base_table' => $table_name,
  1514. ),
  1515. 'widget' => array(
  1516. 'type' => 'data__sequence_widget',
  1517. 'settings' => array(
  1518. 'display_label' => 1,
  1519. ),
  1520. ),
  1521. 'display' => array(
  1522. 'default' => array(
  1523. 'label' => 'above',
  1524. 'type' => 'data__sequence_formatter',
  1525. 'settings' => array(),
  1526. ),
  1527. ),
  1528. );
  1529. }
  1530. // FEATURE SEQLEN
  1531. if ($table_name == 'feature') {
  1532. $field_name = 'data__sequence_length';
  1533. $info[$field_name] = array(
  1534. 'field_name' => $field_name,
  1535. 'entity_type' => $entity_type,
  1536. 'bundle' => $bundle->name,
  1537. 'label' => 'Sequence Length',
  1538. 'description' => 'The number of residues in the raw sequence. This length
  1539. is only for the assigned raw sequence and does not represent the length of any
  1540. sequences derived from alignments. If this value is zero but aligned sequences
  1541. are present then this record has no official assigned sequence.',
  1542. 'required' => FALSE,
  1543. 'settings' => array(
  1544. 'auto_attach' => TRUE,
  1545. 'chado_table' => $table_name,
  1546. 'chado_column' => 'seqlen',
  1547. 'base_table' => $table_name,
  1548. ),
  1549. 'widget' => array(
  1550. 'type' => 'data__sequence_length_widget',
  1551. 'settings' => array(
  1552. 'display_label' => 1,
  1553. ),
  1554. ),
  1555. 'display' => array(
  1556. 'default' => array(
  1557. 'label' => 'inline',
  1558. 'type' => 'data__sequence_length_formatter',
  1559. 'settings' => array(),
  1560. ),
  1561. ),
  1562. );
  1563. }
  1564. // PROTEIN & CDS SEQUENCES.
  1565. if ($table_name == 'feature' and
  1566. ($bundle->label == 'mRNA' or $bundle->label == 'transcript')) {
  1567. $field_name = 'data__protein_sequence';
  1568. $info[$field_name] = array(
  1569. 'field_name' => $field_name,
  1570. 'entity_type' => $entity_type,
  1571. 'bundle' => $bundle->name,
  1572. 'label' => 'Protein Sequence',
  1573. 'description' => 'Protein sequences.',
  1574. 'required' => FALSE,
  1575. 'settings' => array(
  1576. 'auto_attach' => FALSE,
  1577. 'chado_table' => 'feature',
  1578. 'chado_column' => 'residues',
  1579. 'base_table' => 'feature',
  1580. ),
  1581. 'widget' => array(
  1582. 'type' => 'data__protein_sequence_widget',
  1583. 'settings' => array(
  1584. 'display_label' => 1,
  1585. ),
  1586. ),
  1587. 'display' => array(
  1588. 'default' => array(
  1589. 'label' => 'above',
  1590. 'type' => 'data__protein_sequence_formatter',
  1591. 'settings' => array(),
  1592. ),
  1593. ),
  1594. );
  1595. // $field_name = 'so__cds';
  1596. // $info[$field_name] = array(
  1597. // 'field_name' => $field_name,
  1598. // 'entity_type' => $entity_type,
  1599. // 'bundle' => $bundle->name,
  1600. // 'label' => 'Coding Sequence',
  1601. // 'description' => 'Coding sequences.',
  1602. // 'required' => FALSE,
  1603. // 'settings' => array(
  1604. // 'auto_attach' => FALSE,
  1605. // 'chado_table' => 'featureloc',
  1606. // 'chado_column' => '',
  1607. // 'base_table' => 'featureloc',
  1608. // ),
  1609. // 'widget' => array(
  1610. // 'type' => 'so__cds_widget',
  1611. // 'settings' => array(
  1612. // 'display_label' => 1,
  1613. // ),
  1614. // ),
  1615. // 'display' => array(
  1616. // 'default' => array(
  1617. // 'label' => 'above',
  1618. // 'type' => 'so__cds_formatter',
  1619. // 'settings' => array(),
  1620. // ),
  1621. // ),
  1622. // );
  1623. }
  1624. // // GENE TRANSCRIPTS
  1625. // $rel_table = $table_name . '_relationship';
  1626. // if (chado_table_exists($rel_table) and $bundle->label == 'gene') {
  1627. // $field_name = 'so__transcript';
  1628. // $info[$field_name] = array(
  1629. // 'field_name' => $field_name,
  1630. // 'entity_type' => $entity_type,
  1631. // 'bundle' => $bundle->name,
  1632. // 'label' => 'Transcripts',
  1633. // 'description' => 'Transcripts that are part of this gene.',
  1634. // 'required' => FALSE,
  1635. // 'settings' => array(
  1636. // 'auto_attach' => FALSE,
  1637. // 'chado_table' => $rel_table,
  1638. // 'chado_column' => '',
  1639. // 'base_table' => $table_name,
  1640. // ),
  1641. // 'widget' => array(
  1642. // 'type' => 'so__transcript_widget',
  1643. // 'settings' => array(
  1644. // 'display_label' => 1,
  1645. // ),
  1646. // ),
  1647. // 'display' => array(
  1648. // 'default' => array(
  1649. // 'label' => 'above',
  1650. // 'type' => 'so__transcript_formatter',
  1651. // 'settings' => array(),
  1652. // ),
  1653. // ),
  1654. // );
  1655. // }
  1656. // ORGANISM TYPE_ID
  1657. if ($table_name == 'organism' and array_key_exists('type_id', $schema['fields'])) {
  1658. $field_name = 'taxrank__infraspecific_taxon';
  1659. $info[$field_name] = array(
  1660. 'field_name' => $field_name,
  1661. 'entity_type' => $entity_type,
  1662. 'bundle' => $bundle->name,
  1663. 'label' => 'Infraspecific Taxon',
  1664. 'description' => 'The Infraspecific Taxon.',
  1665. 'required' => FALSE,
  1666. 'settings' => array(
  1667. 'auto_attach' => TRUE,
  1668. 'chado_table' => 'organism',
  1669. 'chado_column' => 'type_id',
  1670. 'base_table' => 'organism',
  1671. ),
  1672. 'widget' => array(
  1673. 'type' => 'taxrank__infraspecific_taxon_widget',
  1674. 'settings' => array(
  1675. 'display_label' => 1,
  1676. ),
  1677. ),
  1678. 'display' => array(
  1679. 'default' => array(
  1680. 'label' => 'inline',
  1681. 'type' => 'taxrank__infraspecific_taxon_formatter',
  1682. 'settings' => array(),
  1683. ),
  1684. ),
  1685. );
  1686. }
  1687. // FEATURE MAP UNITS
  1688. if ($table_name == 'featuremap') {
  1689. $field_name = 'uo__unit';
  1690. $info[$field_name] = array(
  1691. 'field_name' => $field_name,
  1692. 'entity_type' => $entity_type,
  1693. 'bundle' => $bundle->name,
  1694. 'label' => 'Units',
  1695. 'description' => 'The map\'s unit type.',
  1696. 'required' => TRUE,
  1697. 'settings' => array(
  1698. 'auto_attach' => TRUE,
  1699. 'chado_table' => $table_name,
  1700. 'chado_column' => 'unittype_id',
  1701. 'base_table' => $table_name,
  1702. ),
  1703. 'widget' => array(
  1704. 'type' => 'uo__unit_widget',
  1705. 'settings' => array(
  1706. 'display_label' => 1,
  1707. ),
  1708. ),
  1709. 'display' => array(
  1710. 'default' => array(
  1711. 'label' => 'inline',
  1712. 'type' => 'uo__unit_formatter',
  1713. 'settings' => array(),
  1714. ),
  1715. ),
  1716. );
  1717. }
  1718. // the analysis source.
  1719. if ($table_name == 'analysis') {
  1720. $field_name = 'local__source_data';
  1721. $info[$field_name] = array(
  1722. 'field_name' => $field_name,
  1723. 'entity_type' => $entity_type,
  1724. 'bundle' => $bundle->name,
  1725. 'label' => 'Data Source',
  1726. 'description' => 'The source where data was obtained for this analysis.',
  1727. 'required' => FALSE,
  1728. 'settings' => array(
  1729. 'auto_attach' => TRUE,
  1730. 'chado_table' => $table_name,
  1731. 'chado_column' => 'analysis_id',
  1732. 'base_table' => $table_name,
  1733. ),
  1734. 'widget' => array(
  1735. 'type' => 'local__source_data_widget',
  1736. 'settings' => array(
  1737. 'display_label' => 1,
  1738. ),
  1739. ),
  1740. 'display' => array(
  1741. 'default' => array(
  1742. 'label' => 'inline',
  1743. 'type' => 'local__source_data_formatter',
  1744. 'settings' => array(),
  1745. ),
  1746. ),
  1747. );
  1748. }
  1749. // Add an image field to the Organism type. This is a Drupal field and
  1750. // not stored in Chado, but is used for backwards compatibility.
  1751. if ($table_name == 'organism') {
  1752. $field_name = 'data__image';
  1753. $info[$field_name] = array(
  1754. 'field_name' => $field_name,
  1755. 'entity_type' => $entity_type,
  1756. 'bundle' => $bundle->name,
  1757. 'label' => 'Organism Image',
  1758. 'description' => 'An image for the organism',
  1759. 'required' => FALSE,
  1760. 'settings' => array(
  1761. 'term_vocabulary' => 'data',
  1762. 'term_name' => 'Image',
  1763. 'term_accession' => '2968',
  1764. ),
  1765. 'display' => array(
  1766. 'default' => array(
  1767. 'label' => 'hidden',
  1768. ),
  1769. ),
  1770. );
  1771. }
  1772. // Phylotree Viewer
  1773. if ($table_name == 'phylotree') {
  1774. $field_name = 'operation__phylotree_vis';
  1775. $schema = chado_get_schema('phylotree');
  1776. $pkey = $schema['primary key'][0];
  1777. $info[$field_name] = array(
  1778. 'field_name' => $field_name,
  1779. 'entity_type' => $entity_type,
  1780. 'bundle' => $bundle->name,
  1781. 'label' => 'Tree View',
  1782. 'description' => 'Rendering of a phylogenetic tree.',
  1783. 'required' => FALSE,
  1784. 'settings' => array(
  1785. 'auto_attach' => FALSE,
  1786. 'chado_table' => 'phylotree',
  1787. 'chado_column' => 'type_id',
  1788. 'base_table' => 'phylotree',
  1789. ),
  1790. 'widget' => array(
  1791. 'type' => 'operation__phylotree_vis_widget',
  1792. 'settings' => array(
  1793. 'display_label' => 0,
  1794. ),
  1795. ),
  1796. 'display' => array(
  1797. 'default' => array(
  1798. 'label' => 'hidden',
  1799. 'type' => 'operation__phylotree_vis_formatter',
  1800. 'settings' => array(),
  1801. ),
  1802. ),
  1803. );
  1804. }
  1805. // PROTOCOL FIELD
  1806. if ($table_name != 'protocol' and
  1807. (array_key_exists('protocol_id', $schema['fields']))) {
  1808. $field_name = 'sep__protocol';
  1809. $is_required = FALSE;
  1810. $table_column = 'protocol_id';
  1811. if (array_key_exists('not null', $schema['fields']['protocol_id']) and
  1812. $schema['fields']['protocol_id']['not null']) {
  1813. $is_required = TRUE;
  1814. }
  1815. $info[$field_name] = array(
  1816. 'field_name' => $field_name,
  1817. 'entity_type' => $entity_type,
  1818. 'bundle' => $bundle->name,
  1819. 'label' => 'Protocol',
  1820. 'description' => 'The parameterizable description of a process',
  1821. 'required' => $is_required,
  1822. 'settings' => array(
  1823. 'auto_attach' => TRUE,
  1824. 'chado_table' => $table_name,
  1825. 'chado_column' => $table_column,
  1826. 'base_table' => $table_name,
  1827. ),
  1828. 'widget' => array(
  1829. 'type' => 'sep__protocol_widget',
  1830. 'settings' => array(
  1831. 'display_label' => 1,
  1832. ),
  1833. ),
  1834. 'display' => array(
  1835. 'default' => array(
  1836. 'label' => 'inline',
  1837. 'type' => 'sep__protocol_formatter',
  1838. 'settings' => array(),
  1839. ),
  1840. ),
  1841. );
  1842. }
  1843. // pub_id field in table.
  1844. $schema = chado_get_schema($table_name);
  1845. if (array_key_exists('pub_id', $schema['fields'])) {
  1846. // Remove the schema__publication added by the
  1847. // tripal_chado_bunde_instnaces_info_base function.
  1848. unset($info['schema__publication']);
  1849. $field_name = 'schema__publication_single';
  1850. $info[$field_name] = array(
  1851. 'field_name' => $field_name,
  1852. 'entity_type' => $entity_type,
  1853. 'bundle' => $bundle->name,
  1854. 'label' => 'Publication',
  1855. 'description' => 'This record has been referenced or is sourced from these publications.',
  1856. 'required' => FALSE,
  1857. 'settings' => array(
  1858. 'auto_attach' => TRUE,
  1859. 'chado_table' => $table_name,
  1860. 'chado_column' => 'pub_id',
  1861. 'base_table' => $table_name,
  1862. ),
  1863. 'widget' => array(
  1864. 'type' => 'schema__publication_widget',
  1865. 'settings' => array(
  1866. 'display_label' => 1,
  1867. ),
  1868. ),
  1869. 'display' => array(
  1870. 'default' => array(
  1871. 'label' => 'hidden',
  1872. 'type' => 'schema__publication_formatter',
  1873. 'settings' => array(),
  1874. ),
  1875. ),
  1876. );
  1877. }
  1878. if ($table_name == 'assay') {
  1879. // Remove the ncit__operator added by the
  1880. // tripal_chado_bunde_instnaces_info_base function.
  1881. unset($info['ncit__operator']);
  1882. $field_name = 'assay__operator_id';
  1883. $info[$field_name] = array(
  1884. 'field_name' => $field_name,
  1885. 'entity_type' => $entity_type,
  1886. 'bundle' => $bundle->name,
  1887. 'label' => 'Operator',
  1888. 'description' => 'The individual responsible for performing the assay.',
  1889. 'required' => TRUE,
  1890. 'settings' => array(
  1891. 'auto_attach' => TRUE,
  1892. 'chado_table' => 'assay',
  1893. 'chado_column' => 'operator_id',
  1894. 'base_table' => 'assay',
  1895. 'term_vocabulary' => 'NCIT',
  1896. 'term_name' => 'Operator',
  1897. 'term_accession' => 'C48036',
  1898. ),
  1899. 'widget' => array(
  1900. 'type' => 'local__contact_widget',
  1901. 'settings' => array(
  1902. 'display_label' => 1,
  1903. ),
  1904. ),
  1905. 'display' => array(
  1906. 'default' => array(
  1907. 'label' => 'inline',
  1908. 'type' => 'local__contact_formatter',
  1909. 'settings' => array(),
  1910. ),
  1911. ),
  1912. );
  1913. $field_name = 'efo__array_design';
  1914. $info[$field_name] = array(
  1915. 'field_name' => $field_name,
  1916. 'entity_type' => $entity_type,
  1917. 'bundle' => $bundle->name,
  1918. 'label' => 'Array design',
  1919. 'description' => 'An instrument design which describes the design of the array.',
  1920. 'required' => TRUE,
  1921. 'settings' => array(
  1922. 'auto_attach' => TRUE,
  1923. 'chado_table' => 'assay',
  1924. 'chado_column' => 'arraydesign_id',
  1925. 'base_table' => 'assay',
  1926. 'term_vocabulary' => 'EFO',
  1927. 'term_name' => 'array design',
  1928. 'term_accession' => '0000269',
  1929. ),
  1930. 'widget' => array(
  1931. 'type' => 'efo__array_design_widget',
  1932. 'settings' => array(
  1933. 'display_label' => 1,
  1934. ),
  1935. ),
  1936. 'display' => array(
  1937. 'default' => array(
  1938. 'label' => 'inline',
  1939. 'type' => 'efo__array_design_formatter',
  1940. 'settings' => array(),
  1941. ),
  1942. ),
  1943. );
  1944. }
  1945. }
  1946. /**
  1947. *
  1948. * @param unknown $entity_type
  1949. * @param unknown $bundle
  1950. * @param unknown $details
  1951. */
  1952. function tripal_chado_bundle_instances_info_linker(&$info, $entity_type, $bundle, $details) {
  1953. $table_name = $details['chado_table'];
  1954. $type_table = $details['chado_type_table'];
  1955. $type_column = $details['chado_type_column'];
  1956. $cvterm_id = $details['chado_cvterm_id'];
  1957. $type_value = $details['chado_type_value'];
  1958. // CONTACTS
  1959. $contact_table = $table_name . '_contact';
  1960. if (chado_table_exists($contact_table)) {
  1961. $field_name = $table_name . '_contact';
  1962. $info[$field_name] = $info[$field_name] = array(
  1963. 'field_name' => $field_name,
  1964. 'entity_type' => $entity_type,
  1965. 'bundle' => $bundle->name,
  1966. 'label' => 'Contact',
  1967. 'description' => 'Associates an indviddual or organization with this record',
  1968. 'required' => FALSE,
  1969. 'settings' => array(
  1970. 'auto_attach' => FALSE,
  1971. 'chado_table' => $contact_table,
  1972. 'base_table' => $table_name,
  1973. 'chado_column' => 'contact_id',
  1974. ),
  1975. 'widget' => array(
  1976. 'type' => 'local__contact_widget',
  1977. 'settings' => array(
  1978. 'display_label' => 1,
  1979. ),
  1980. ),
  1981. 'display' => array(
  1982. 'default' => array(
  1983. 'label' => 'hidden',
  1984. 'type' => 'local__contact_formatter',
  1985. 'settings' => array(),
  1986. ),
  1987. ),
  1988. );
  1989. }
  1990. // DBXREF
  1991. $dbxref_table = $table_name . '_dbxref';
  1992. if (chado_table_exists($dbxref_table)) {
  1993. $field_name = 'sbo__database_cross_reference';
  1994. $schema = chado_get_schema($dbxref_table);
  1995. $pkey = $schema['primary key'][0];
  1996. $info[$field_name] = array(
  1997. 'field_name' => $field_name,
  1998. 'entity_type' => $entity_type,
  1999. 'bundle' => $bundle->name,
  2000. 'label' => 'Cross Reference',
  2001. 'description' => 'The IDs where this record may be available in other external online databases.',
  2002. 'required' => FALSE,
  2003. 'settings' => array(
  2004. 'auto_attach' => FALSE,
  2005. 'chado_table' => $dbxref_table,
  2006. 'chado_column' => $pkey,
  2007. 'base_table' => $table_name,
  2008. ),
  2009. 'widget' => array(
  2010. 'type' => 'sbo__database_cross_reference_widget',
  2011. 'settings' => array(
  2012. 'display_label' => 1,
  2013. ),
  2014. ),
  2015. 'display' => array(
  2016. 'default' => array(
  2017. 'label' => 'hidden',
  2018. 'type' => 'sbo__database_cross_reference_formatter',
  2019. 'settings' => array(),
  2020. ),
  2021. ),
  2022. );
  2023. }
  2024. // EXPRESSION
  2025. // TODO: this should only show up on gene or mRNA and the GO must be
  2026. // laoded or this field will crash things.
  2027. // $expression_table = $table_name . '_expression';
  2028. // if (chado_table_exists($expression_table)) {
  2029. // $field_name = 'go__gene_expression';
  2030. // $schema = chado_get_schema($expression_table);
  2031. // $pkey = $schema['primary key'][0];
  2032. // $info[$field_name] = array(
  2033. // 'field_name' => $field_name,
  2034. // 'entity_type' => $entity_type,
  2035. // 'bundle' => $bundle->name,
  2036. // 'label' => 'Gene expression',
  2037. // 'description' => 'Information about the expression of this record.',
  2038. // 'required' => FALSE,
  2039. // 'settings' => array(
  2040. // 'auto_attach' => FALSE,
  2041. // 'chado_table' => $expression_table,
  2042. // 'chado_column' => $pkey,
  2043. // 'base_table' => $table_name,
  2044. // ),
  2045. // 'widget' => array(
  2046. // 'type' => 'go__gene_expression_widget',
  2047. // 'settings' => array(
  2048. // 'display_label' => 1,
  2049. // ),
  2050. // ),
  2051. // 'display' => array(
  2052. // 'default' => array(
  2053. // 'label' => 'above',
  2054. // 'type' => 'go__gene_expression_formatter',
  2055. // 'settings' => array(),
  2056. // ),
  2057. // ),
  2058. // );
  2059. // }
  2060. // FEATURELOC
  2061. if ($table_name == 'feature') {
  2062. $field_name = 'data__sequence_coordinates';
  2063. $schema = chado_get_schema('featureloc');
  2064. $pkey = $schema['primary key'][0];
  2065. $info[$field_name] = array(
  2066. 'field_name' => $field_name,
  2067. 'entity_type' => $entity_type,
  2068. 'bundle' => $bundle->name,
  2069. 'label' => 'Sequence Coordinates',
  2070. 'description' => 'The locations on other genomic sequences where this
  2071. record has been aligned.',
  2072. 'required' => FALSE,
  2073. 'settings' => array(
  2074. 'auto_attach' => FALSE,
  2075. 'chado_table' => 'featureloc',
  2076. 'chado_column' => $pkey,
  2077. 'base_table' => 'feature',
  2078. ),
  2079. 'widget' => array(
  2080. 'type' => 'data__sequence_coordinates_widget',
  2081. 'settings' => array(
  2082. 'display_label' => 1,
  2083. ),
  2084. ),
  2085. 'display' => array(
  2086. 'default' => array(
  2087. 'label' => 'hidden',
  2088. 'type' => 'data__sequence_coordinates_formatter',
  2089. 'settings' => array(),
  2090. ),
  2091. ),
  2092. );
  2093. }
  2094. // FEATUREPOS
  2095. if ($table_name == 'feature') {
  2096. $field_name = 'ogi__location_on_map';
  2097. $schema = chado_get_schema('featurepos');
  2098. $pkey = $schema['primary key'][0];
  2099. $info[$field_name] = array(
  2100. 'field_name' => $field_name,
  2101. 'entity_type' => $entity_type,
  2102. 'bundle' => $bundle->name,
  2103. 'label' => 'Location on Map',
  2104. 'description' => 'The positions on a genetic map.',
  2105. 'required' => FALSE,
  2106. 'settings' => array(
  2107. 'auto_attach' => FALSE,
  2108. 'chado_table' => 'featurepos',
  2109. 'chado_column' => $pkey,
  2110. 'base_table' => 'feature',
  2111. ),
  2112. 'widget' => array(
  2113. 'type' => 'ogi__location_on_map_widget',
  2114. 'settings' => array(
  2115. 'display_label' => 1,
  2116. ),
  2117. ),
  2118. 'display' => array(
  2119. 'default' => array(
  2120. 'label' => 'hidden',
  2121. 'type' => 'ogi__location_on_map_formatter',
  2122. 'settings' => array(),
  2123. ),
  2124. ),
  2125. );
  2126. }
  2127. // // GENOTYPE
  2128. // $genotype_table = $table_name . '_genotype';
  2129. // if (chado_table_exists($genotype_table)) {
  2130. // $field_name = 'so__genotype';
  2131. // $schema = chado_get_schema($genotype_table);
  2132. // $pkey = $schema['primary key'][0];
  2133. // $info[$field_name] = array(
  2134. // 'field_name' => $field_name,
  2135. // 'entity_type' => $entity_type,
  2136. // 'bundle' => $bundle->name,
  2137. // 'label' => 'Genotype',
  2138. // 'description' => 'The genotypes associated with this record.',
  2139. // 'required' => FALSE,
  2140. // 'settings' => array(
  2141. // 'auto_attach' => FALSE,
  2142. // 'chado_table' => $genotype_table,
  2143. // 'chado_column' => $pkey,
  2144. // 'base_table' => $table_name,
  2145. // ),
  2146. // 'widget' => array(
  2147. // 'type' => 'so__genotype_widget',
  2148. // 'settings' => array(
  2149. // 'display_label' => 1,
  2150. // ),
  2151. // ),
  2152. // 'display' => array(
  2153. // 'default' => array(
  2154. // 'label' => 'hidden',
  2155. // 'type' => 'so__genotype_formatter',
  2156. // 'settings' => array(),
  2157. // ),
  2158. // ),
  2159. // );
  2160. // }
  2161. // // PHENOTYPE
  2162. // $phenotype_table = $table_name . '_phenotype';
  2163. // if (chado_table_exists($phenotype_table)) {
  2164. // $field_name = 'sbo__phenotype';
  2165. // $schema = chado_get_schema($phenotype_table);
  2166. // $pkey = $schema['primary key'][0];
  2167. // $info[$field_name] = array(
  2168. // 'field_name' => $field_name,
  2169. // 'entity_type' => $entity_type,
  2170. // 'bundle' => $bundle->name,
  2171. // 'label' => 'Phenotype',
  2172. // 'description' => 'The phenotypes associated with this record.',
  2173. // 'required' => FALSE,
  2174. // 'settings' => array(
  2175. // 'auto_attach' => FALSE,
  2176. // 'chado_table' => $phenotype_table,
  2177. // 'chado_column' => $pkey,
  2178. // 'base_table' => $table_name,
  2179. // ),
  2180. // 'widget' => array(
  2181. // 'type' => 'sbo__phenotype_widget',
  2182. // 'settings' => array(
  2183. // 'display_label' => 1,
  2184. // ),
  2185. // ),
  2186. // 'display' => array(
  2187. // 'default' => array(
  2188. // 'label' => 'hidden',
  2189. // 'type' => 'sbo__phenotype_formatter',
  2190. // 'settings' => array(),
  2191. // ),
  2192. // ),
  2193. // );
  2194. // }
  2195. // PROPERTIES
  2196. $prop_table = $table_name . 'prop';
  2197. if (chado_table_exists($prop_table)) {
  2198. $tschema = chado_get_schema($table_name);
  2199. $schema = chado_get_schema($prop_table);
  2200. $tpkey = $tschema['primary key'][0];
  2201. $pkey = $schema['primary key'][0];
  2202. // Property tables can be a bit tricky because not all property types
  2203. // in the prop table are appropriate for each type of data. Also som
  2204. // bundle types are resolved via a property. So, we have to distinguish
  2205. // between these two cases.
  2206. $sql = '';
  2207. $args = array();
  2208. // First, is this the case where all of the records in the table are
  2209. // of this type? If so, then all properties apply
  2210. if (!$type_column) {
  2211. $sql = 'SELECT DISTINCT type_id FROM {' . $prop_table . '}';
  2212. $props = chado_query($sql, $args);
  2213. }
  2214. // Second, if this is the case where a content type is uniquely identified
  2215. // by a type_id value in the base table, then only properties associated
  2216. // with that type ID should be used.
  2217. else if ($type_column and !$type_table) {
  2218. $sql = "
  2219. SELECT DISTINCT P.type_id
  2220. FROM {" . $prop_table . "} P
  2221. INNER JOIN {" . $table_name . "} T on T.$tpkey = P.$tpkey
  2222. WHERE T.$type_column = :cvterm_id
  2223. ";
  2224. $args[':cvterm_id'] = $cvterm_id;
  2225. $props = chado_query($sql, $args);
  2226. }
  2227. // Third, if this is the case where a content type is uniquely identified
  2228. // via a term/value pair in the prop table.
  2229. else if ($type_column and $type_table == $prop_table and !empty($type_value)) {
  2230. $sql = "
  2231. SELECT DISTINCT P2.type_id
  2232. FROM {" . $prop_table . "} P1
  2233. INNER JOIN {" . $table_name . "} T on T.$tpkey = P1.$tpkey
  2234. INNER JOIN {" . $prop_table . "} P2 on T.$tpkey = P2.$tpkey
  2235. WHERE P1.$type_column = :cvterm_id AND P1.value = :prop_value AND
  2236. P2.type_id != P1.type_id
  2237. ";
  2238. $args[':cvterm_id'] = $cvterm_id;
  2239. $args[':prop_value'] = $type_value;
  2240. $props = chado_query($sql, $args);
  2241. }
  2242. // Fourth, if this is the case where the content type is uinquely identifed
  2243. // via another table (e.g. cvterm linking table) and not this prop table.
  2244. else if ($type_column and $type_table != $prop_table and empty($type_value)) {
  2245. $sql = "
  2246. SELECT DISTINCT P.type_id
  2247. FROM {" . $prop_table . "} P
  2248. INNER JOIN {" . $table_name . "} T on T.$tpkey = P.$tpkey
  2249. INNER JOIN {" . $type_table . "} TT on TT.$tpkey = T.$tpkey
  2250. WHERE TT.$type_column = :cvterm_id
  2251. ";
  2252. $args[':cvterm_id'] = $cvterm_id;
  2253. $props = chado_query($sql, $args);
  2254. }
  2255. else {
  2256. // Do nothing;
  2257. }
  2258. if ($props) {
  2259. while ($prop = $props->fetchObject()) {
  2260. $term = chado_generate_var('cvterm', array('cvterm_id' => $prop->type_id));
  2261. $term = chado_expand_var($term, 'field', 'cvterm.definition');
  2262. // Skip the Publiation Type property for pubs as this is
  2263. // already handled by the pub.type_id field.
  2264. if ($term->name == 'Publication Type' and $term->cv_id->name == 'tripal_pub') {
  2265. continue;
  2266. }
  2267. // The tripal_analysis_KEGG, tripal_analysis_blast, and
  2268. // tripal_analysis_interpro modules store results in the analysisprop
  2269. // table which is probably not the best place, but we don't want to
  2270. // create a ton of fields for this.
  2271. if ($prop_table == 'analysisprop' and
  2272. ($term->dbxref_id->db_id->name == 'KEGG_BRITE' or
  2273. $term->dbxref_id->db_id->name == 'tripal')) {
  2274. continue;
  2275. }
  2276. $field_name = strtolower(preg_replace('/[^\w]/','_', $term->dbxref_id->db_id->name . '__' . $term->name));
  2277. $field_name = substr($field_name, 0, 32);
  2278. $info[$field_name] = array(
  2279. 'field_name' => $field_name,
  2280. 'entity_type' => $entity_type,
  2281. 'bundle' => $bundle->name,
  2282. 'label' => ucwords(preg_replace('/_/', ' ', $term->name)),
  2283. 'description' => $term->definition,
  2284. 'required' => FALSE,
  2285. 'settings' => array(
  2286. 'auto_attach' => TRUE,
  2287. 'term_vocabulary' => $term->dbxref_id->db_id->name,
  2288. 'term_accession' => $term->dbxref_id->accession,
  2289. 'term_name' => $term->name,
  2290. 'base_table' => $table_name,
  2291. 'chado_table' => $prop_table,
  2292. 'chado_column' => $pkey,
  2293. ),
  2294. 'widget' => array(
  2295. 'type' => 'chado_linker__prop_widget',
  2296. 'settings' => array(
  2297. 'display_label' => 1,
  2298. ),
  2299. ),
  2300. 'display' => array(
  2301. 'default' => array(
  2302. 'label' => 'hidden',
  2303. 'type' => 'chado_linker__prop_formatter',
  2304. 'settings' => array(),
  2305. ),
  2306. ),
  2307. );
  2308. // Make some customizations to some fields
  2309. if ($term->name == 'Citation' and $term->cv_id->name == 'tripal_pub') {
  2310. $info[$field_name]['required'] = TRUE;
  2311. $info[$field_name]['description'] = t('All publications must have a unique citation.
  2312. Please enter the full citation for this publication. For PubMed style citations list
  2313. the last name of the author followed by initials. Each author should be separated by a comma. Next comes
  2314. the title, followed by the series title (e.g. journal name), publication date (4 digit year, 3 character Month, day), volume, issue and page numbers. You may also use HTML to provide a link in the citation.
  2315. Below is an example: <pre>Medeiros PM, Ladio AH, Santos AM, Albuquerque UP. <a href="http://www.ncbi.nlm.nih.gov/pubmed/23462414" target="_blank">Does the selection of medicinal plants by Brazilian local populations
  2316. suffer taxonomic influence?</a> J Ethnopharmacol. 2013 Apr 19; 146(3):842-52.</pre>');
  2317. $info[$field_name]['settings']['rows'] = 3;
  2318. }
  2319. if ($term->name == 'Abstract' and $term->cv_id->name == 'tripal_pub') {
  2320. $info[$field_name]['settings']['rows'] = 5;
  2321. }
  2322. }
  2323. }
  2324. }
  2325. // CVTERMS
  2326. $term_table = $table_name . '_cvterm';
  2327. if (chado_table_exists($term_table)) {
  2328. $schema = chado_get_schema($term_table);
  2329. $pkey = $schema['primary key'][0];
  2330. $lkey = key($schema['foreign keys'][$table_name]['columns']);
  2331. $rkey = $schema['foreign keys'][$table_name]['columns'][$lkey];
  2332. $field_name = 'sio__annotation';
  2333. $info[$field_name] = array(
  2334. 'field_name' => $field_name,
  2335. 'entity_type' => $entity_type,
  2336. 'bundle' => $bundle->name,
  2337. 'label' => 'Annotations',
  2338. 'description' => 'Annotations that are associated with this record.',
  2339. 'required' => FALSE,
  2340. 'settings' => array(
  2341. 'auto_attach' => FALSE,
  2342. 'chado_table' => $term_table,
  2343. 'chado_column' => $pkey,
  2344. 'base_table' => $table_name,
  2345. ),
  2346. 'widget' => array(
  2347. 'type' => 'sio__annotation_widget',
  2348. 'settings' => array(
  2349. 'display_label' => 1,
  2350. ),
  2351. ),
  2352. 'display' => array(
  2353. 'default' => array(
  2354. 'label' => 'hidden',
  2355. 'type' => 'sio__annotation_formatter',
  2356. 'settings' => array(),
  2357. ),
  2358. ),
  2359. );
  2360. }
  2361. // PUBLICATIONS
  2362. $pub_table = $table_name . '_pub';
  2363. if (chado_table_exists($pub_table)) {
  2364. $field_name = 'schema__publication';
  2365. $schema = chado_get_schema($pub_table);
  2366. $pkey = $schema['primary key'][0];
  2367. $info[$field_name] = array(
  2368. 'field_name' => $field_name,
  2369. 'entity_type' => $entity_type,
  2370. 'bundle' => $bundle->name,
  2371. 'label' => 'Publication',
  2372. 'description' => 'This record has been referenced or is sourced from these publications.',
  2373. 'required' => FALSE,
  2374. 'settings' => array(
  2375. 'auto_attach' => FALSE,
  2376. 'chado_table' => $pub_table,
  2377. 'chado_column' => $pkey,
  2378. 'base_table' => $table_name,
  2379. ),
  2380. 'widget' => array(
  2381. 'type' => 'schema__publication_widget',
  2382. 'settings' => array(
  2383. 'display_label' => 1,
  2384. ),
  2385. ),
  2386. 'display' => array(
  2387. 'default' => array(
  2388. 'label' => 'hidden',
  2389. 'type' => 'schema__publication_formatter',
  2390. 'settings' => array(),
  2391. ),
  2392. ),
  2393. );
  2394. }
  2395. // PUBLICATIONS (in reverse)
  2396. // We want to be able to show all of the content that a publication links
  2397. // to. The sio__references field does that.
  2398. if ($table_name == 'pub') {
  2399. $field_name = 'sio__references';
  2400. $schema = chado_get_schema($table_name);
  2401. $pkey = $schema['primary key'][0];
  2402. $info[$field_name] = array(
  2403. 'field_name' => $field_name,
  2404. 'entity_type' => $entity_type,
  2405. 'bundle' => $bundle->name,
  2406. 'label' => 'References',
  2407. 'description' => 'Records that are referred to by the publication.',
  2408. 'required' => FALSE,
  2409. 'settings' => array(
  2410. 'auto_attach' => FALSE,
  2411. 'chado_table' => $table_name,
  2412. 'chado_column' => $pkey,
  2413. 'base_table' => $table_name,
  2414. ),
  2415. 'widget' => array(
  2416. 'type' => 'sio__references_widget',
  2417. 'settings' => array(
  2418. 'display_label' => 1,
  2419. ),
  2420. ),
  2421. 'display' => array(
  2422. 'default' => array(
  2423. 'label' => 'hidden',
  2424. 'type' => 'sio__references_formatter',
  2425. 'settings' => array(),
  2426. ),
  2427. ),
  2428. );
  2429. }
  2430. // RELATIONSHIPS
  2431. // If the linker table does not exists then we don't want to add attach.
  2432. $rel_table = $table_name . '_relationship';
  2433. if (chado_table_exists($rel_table)) {
  2434. $field_name = 'sbo__relationship';
  2435. $schema = chado_get_schema($rel_table);
  2436. $pkey = $schema['primary key'][0];
  2437. $info[$field_name] = array(
  2438. 'field_name' => $field_name,
  2439. 'entity_type' => $entity_type,
  2440. 'bundle' => $bundle->name,
  2441. 'label' => 'Relationship',
  2442. 'description' => 'Other records with relationships to this record.',
  2443. 'required' => FALSE,
  2444. 'settings' => array(
  2445. 'auto_attach' => FALSE,
  2446. 'chado_table' => $rel_table,
  2447. 'chado_column' => $pkey,
  2448. 'base_table' => $table_name,
  2449. ),
  2450. 'widget' => array(
  2451. 'type' => 'sbo__relationship_widget',
  2452. 'settings' => array(
  2453. 'display_label' => 1,
  2454. ),
  2455. ),
  2456. 'display' => array(
  2457. 'default' => array(
  2458. 'label' => 'hidden',
  2459. 'type' => 'sbo__relationship_formatter',
  2460. 'settings' => array(),
  2461. ),
  2462. ),
  2463. );
  2464. }
  2465. // SYNONYMS
  2466. $syn_table = $table_name . '_synonym';
  2467. if (chado_table_exists($syn_table)) {
  2468. $field_name = 'schema__alternate_name';
  2469. $schema = chado_get_schema($syn_table);
  2470. $pkey = $schema['primary key'][0];
  2471. $info[$field_name] = array(
  2472. 'field_name' => $field_name,
  2473. 'entity_type' => $entity_type,
  2474. 'bundle' => $bundle->name,
  2475. 'label' => 'Synonyms',
  2476. 'description' => 'Alternate names, aliases or synonyms for this record.',
  2477. 'required' => FALSE,
  2478. 'settings' => array(
  2479. 'auto_attach' => FALSE,
  2480. 'chado_table' => $syn_table,
  2481. 'chado_column' => $pkey,
  2482. 'base_table' => $table_name,
  2483. ),
  2484. 'widget' => array(
  2485. 'type' => 'schema__alternate_name_widget',
  2486. 'settings' => array(
  2487. 'display_label' => 1,
  2488. ),
  2489. ),
  2490. 'display' => array(
  2491. 'default' => array(
  2492. 'label' => 'hidden',
  2493. 'type' => 'schema__alternate_name_formatter',
  2494. 'settings' => array(),
  2495. ),
  2496. ),
  2497. );
  2498. }
  2499. }
  2500. /**
  2501. * Implements hook_bundle_create_user_field().
  2502. *
  2503. * A priviledged user has the ability to add new fields to the bundle. The
  2504. * chado_linker__prop and chado_linker__cvterm fields are allowed to be
  2505. * added dynamically by the user. But, Drupal doesn't know how to deal with
  2506. * it, so this function is called for any field attached to a TripalEntity
  2507. * bundle type. Any fields whose TripalField::$module argument is set to
  2508. * 'tripal_chado' and that can be added dynamically will result in a call
  2509. * to this function.
  2510. */
  2511. function tripal_chado_bundle_create_user_field($new_field, $bundle) {
  2512. // Get the table this bundle is mapped to.
  2513. $term = tripal_load_term_entity(array('term_id' => $bundle->term_id));
  2514. $vocab = $term->vocab;
  2515. $params = array(
  2516. 'vocabulary' => $vocab->vocabulary,
  2517. 'accession' => $term->accession,
  2518. );
  2519. $chado_table = $bundle->data_table;
  2520. $chado_type_table = $bundle->type_linker_table;
  2521. $chado_type_column = $bundle->type_column;
  2522. $chado_type_id = $bundle->type_id;
  2523. $chado_type_value = $bundle->type_value;
  2524. // We allow site admins to add new chado_linker__prop fields to an entity.
  2525. // This function will allow us to properly add them. But at this point we
  2526. // don't know the controlled vocabulary term. We'll have to use the
  2527. // defaults and let the user set it using the interface.
  2528. if ($new_field['type'] == 'chado_linker__prop') {
  2529. $table_name = $chado_table . 'prop';
  2530. if (chado_table_exists($table_name)) {
  2531. $schema = chado_get_schema($table_name);
  2532. $pkey = $schema['primary key'][0];
  2533. $field_name = $new_field['field_name'];
  2534. $field_type = 'chado_linker__prop';
  2535. // First add the field.
  2536. field_create_field(array(
  2537. 'field_name' => $field_name,
  2538. 'type' => $field_type,
  2539. 'cardinality' => FIELD_CARDINALITY_UNLIMITED,
  2540. 'locked' => FALSE,
  2541. 'storage' => array(
  2542. 'type' => 'field_chado_storage',
  2543. ),
  2544. ));
  2545. // Now add the instance
  2546. field_create_instance(array(
  2547. 'field_name' => $field_name,
  2548. 'entity_type' => 'TripalEntity',
  2549. 'bundle' => $bundle->name,
  2550. 'label' => $new_field['label'],
  2551. 'description' => '',
  2552. 'required' => FALSE,
  2553. 'settings' => array(
  2554. 'auto_attach' => TRUE,
  2555. 'base_table' => $chado_table,
  2556. 'chado_table' => $table_name,
  2557. 'chado_column' => $pkey,
  2558. 'term_vocabulary' => '',
  2559. 'term_accession' => '',
  2560. 'term_name' => ''
  2561. ),
  2562. 'widget' => array(
  2563. 'type' => 'chado_linker__prop_widget',
  2564. 'settings' => array(
  2565. 'display_label' => 1,
  2566. ),
  2567. ),
  2568. 'display' => array(
  2569. 'default' => array(
  2570. 'label' => 'inline',
  2571. 'type' => 'chado_linker__prop_formatter',
  2572. 'settings' => array(),
  2573. ),
  2574. ),
  2575. ));
  2576. }
  2577. else {
  2578. drupal_set_message('Cannot add a property field to this entity. Chado does not support properties for this data type.', 'error');
  2579. }
  2580. }
  2581. // We allow site admins to add new chado_linker__cvterm fields to an entity.
  2582. // This function will allow us to properly add them. But at this point we
  2583. // don't know the controlled vocabulary term. We'll have to use the
  2584. // defaults and let the user set it using the interface.
  2585. if ($new_field['type'] == 'chado_linker__cvterm') {
  2586. $table_name = $chado_table . '_cvterm';
  2587. if (chado_table_exists($table_name)) {
  2588. $schema = chado_get_schema($table_name);
  2589. $pkey = $schema['primary key'][0];
  2590. $field_name = $new_field['field_name'];
  2591. $field_type = 'chado_linker__cvterm';
  2592. // First add the field.
  2593. field_create_field(array(
  2594. 'field_name' => $field_name,
  2595. 'type' => $field_type,
  2596. 'cardinality' => FIELD_CARDINALITY_UNLIMITED,
  2597. 'locked' => FALSE,
  2598. 'storage' => array(
  2599. 'type' => 'field_chado_storage',
  2600. ),
  2601. 'settings' => array(
  2602. 'base_table' => $chado_table,
  2603. 'chado_table' => $table_name,
  2604. 'chado_column' => $pkey,
  2605. ),
  2606. ));
  2607. // Now add the instance
  2608. field_create_instance(array(
  2609. 'field_name' => $field_name,
  2610. 'entity_type' => 'TripalEntity',
  2611. 'bundle' => $bundle->name,
  2612. 'label' => $new_field['label'],
  2613. 'description' => '',
  2614. 'required' => FALSE,
  2615. 'settings' => array(
  2616. 'auto_attach' => TRUE,
  2617. ),
  2618. 'widget' => array(
  2619. 'type' => 'chado_linker__cvterm_widget',
  2620. 'settings' => array(
  2621. 'display_label' => 1,
  2622. ),
  2623. ),
  2624. 'display' => array(
  2625. 'default' => array(
  2626. 'label' => 'above',
  2627. 'type' => 'chado_linker__cvterm_formatter',
  2628. 'settings' => array(),
  2629. ),
  2630. ),
  2631. ));
  2632. }
  2633. else {
  2634. drupal_set_message('Cannot add a property field to this entity. Chado does not support annotations for this data type.', 'error');
  2635. }
  2636. }
  2637. }
  2638. /**
  2639. * Allows for altering of a field's instance setting form.
  2640. *
  2641. * This appears to be a Drupal hook but is actually a custom function created
  2642. * by this module. It is called by the tripal_form_alter() function of this
  2643. * module.
  2644. *
  2645. * Here we put additional form elements for any field, regardless if it is
  2646. * a tripalField or not.
  2647. *
  2648. * @param $form
  2649. * The form array. Alterations to the form can be made within this array.
  2650. * @param $form_state
  2651. * The form state array.
  2652. */
  2653. function tripal_chado_field_instance_settings_form_alter(&$form, $form_state) {
  2654. global $language;
  2655. $field = $form['#field'];
  2656. $instance = $form['#instance'];
  2657. $base_table = array_key_exists('base_table', $instance['settings']) ? $instance['settings']['base_table'] : '';
  2658. $chado_table = array_key_exists('chado_table', $instance['settings']) ? $instance['settings']['chado_table'] : '';
  2659. $chado_column = array_key_exists('chado_column', $instance['settings']) ? $instance['settings']['chado_column'] : '';
  2660. if ($chado_table) {
  2661. // Construct a table for the vocabulary information.
  2662. $headers = array();
  2663. $rows = array();
  2664. $rows[] = array(
  2665. array(
  2666. 'data' => 'Base Table',
  2667. 'header' => TRUE,
  2668. 'width' => '20%',
  2669. ),
  2670. $base_table
  2671. );
  2672. $rows[] = array(
  2673. array(
  2674. 'data' => 'Record Table',
  2675. 'header' => TRUE,
  2676. 'width' => '20%',
  2677. ),
  2678. $chado_table
  2679. );
  2680. $rows[] = array(
  2681. array(
  2682. 'data' => 'ID Column',
  2683. 'header' => TRUE,
  2684. 'width' => '20%',
  2685. ),
  2686. $chado_column
  2687. );
  2688. $table = array(
  2689. 'header' => $headers,
  2690. 'rows' => $rows,
  2691. 'attributes' => array(
  2692. ),
  2693. 'sticky' => FALSE,
  2694. 'caption' => '',
  2695. 'colgroups' => array(),
  2696. 'empty' => '',
  2697. );
  2698. $form['chado_mapping'] = array(
  2699. '#type' => 'fieldset',
  2700. '#title' => 'Chado Mapping',
  2701. '#description' => t('This field maps to data in Chado to the following table:'),
  2702. );
  2703. $form['chado_mapping']['details'] = array(
  2704. '#type' => 'item',
  2705. '#markup' => theme_table($table),
  2706. );
  2707. }
  2708. }
  2709. /**
  2710. * Implements hook_form_FROM_ID_alter()
  2711. */
  2712. function tripal_chado_form_tripalbundle_form_alter(&$form, $form_state) {
  2713. global $language;
  2714. $bundle = $form['#bundle'];
  2715. $term = entity_load('TripalTerm', array('id' => $bundle->term_id));
  2716. $term = reset($term);
  2717. $vocab = $term->vocab;
  2718. $params = array(
  2719. 'vocabulary' => $vocab->vocabulary,
  2720. 'accession' => $term->accession,
  2721. );
  2722. $chado_table = $bundle->data_table;
  2723. $chado_column = $bundle->type_column;
  2724. $chado_type_table = $bundle->type_linker_table;
  2725. $chado_type_id = $bundle->type_id;
  2726. $chado_type_value = $bundle->type_value;
  2727. // Construct a table for the vocabulary information.
  2728. $headers = array();
  2729. $rows = array();
  2730. $rows[] = array(
  2731. array(
  2732. 'data' => 'Chado Table',
  2733. 'header' => TRUE,
  2734. 'width' => '20%',
  2735. ),
  2736. $chado_table
  2737. );
  2738. if ($chado_column) {
  2739. $rows[] = array(
  2740. array(
  2741. 'data' => 'Type Column',
  2742. 'header' => TRUE,
  2743. 'width' => '20%',
  2744. ),
  2745. $chado_column
  2746. );
  2747. }
  2748. if ($chado_type_table) {
  2749. $rows[] = array(
  2750. array(
  2751. 'data' => 'Association Table',
  2752. 'header' => TRUE,
  2753. 'width' => '20%',
  2754. ),
  2755. $chado_type_table
  2756. );
  2757. }
  2758. if ($chado_type_table and $chado_type_id) {
  2759. $rows[] = array(
  2760. array(
  2761. 'data' => 'CVTerm Table ID',
  2762. 'header' => TRUE,
  2763. 'width' => '20%',
  2764. ),
  2765. $chado_type_id
  2766. );
  2767. }
  2768. if ($chado_type_value) {
  2769. $rows[] = array(
  2770. array(
  2771. 'data' => 'Property Value',
  2772. 'header' => TRUE,
  2773. 'width' => '20%',
  2774. ),
  2775. $chado_type_value
  2776. );
  2777. }
  2778. $table = array(
  2779. 'header' => $headers,
  2780. 'rows' => $rows,
  2781. 'attributes' => array(
  2782. ),
  2783. 'sticky' => FALSE,
  2784. 'caption' => '',
  2785. 'colgroups' => array(),
  2786. 'empty' => '',
  2787. );
  2788. $form['chado_mapping'] = array(
  2789. '#type' => 'item',
  2790. '#title' => 'Chado Mapping',
  2791. '#markup' => theme_table($table),
  2792. '#description' => t('This content type maps to the table in Chado
  2793. listed above. Chado allows multiple data types to be housed
  2794. in a single table. Therefore, the column that is used to
  2795. differentiate between data types is also listed above.'),
  2796. '#weight' => 0,
  2797. );
  2798. }
  2799. /**
  2800. * Implements hook_field_views_data_alter();
  2801. */
  2802. function tripal_chado_field_views_data_alter(&$result, $field, $module) {
  2803. // This module creates the data__image field for managing images on
  2804. // bio_data content types. But we want it to render correctly
  2805. // so we need to set some handlers.
  2806. if ($field['field_name'] == 'data__image') {
  2807. foreach ($result as $key => $fields) {
  2808. // It's not clear how to identify our bundle types, but they do have
  2809. // a double underscore in their name to separate the vocabulary from
  2810. // the accession, so we'll use that to find them.
  2811. if (preg_match('/__/', $key)) {
  2812. $result[$key]['data__image']['field']['handler'] = 'tripal_views_handler_field_image';
  2813. }
  2814. }
  2815. }
  2816. }