tripal_chado.fields.inc 93 KB

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