tripal_chado.fields.inc 93 KB

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