tripal_chado.fields.inc 73 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364
  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. // Don't create base fields for the primary key and the type_id field.
  68. if ($column_name == $pkey or $column_name == $type_column) {
  69. continue;
  70. }
  71. $cvterm = tripal_get_chado_semweb_term($table_name, $column_name, array('return_object' => TRUE));
  72. if (!$cvterm) {
  73. tripal_report_error('tripal', TRIPAL_ERROR,
  74. 'Cannot create field for "%table_name.%column_name". Missing an appropriate vocabulary term',
  75. array('%table_name' => $table_name, '%column_name' => $column_name));
  76. drupal_set_message(t('Cannot create field for "%table_name.%column_name". Missing an appropriate vocabulary term',
  77. array('%table_name' => $table_name, '%column_name' => $column_name)), 'error');
  78. continue;
  79. }
  80. $field_name = strtolower($cvterm->dbxref_id->db_id->name . '__' . preg_replace('/[^\w]/', '_', $cvterm->name));
  81. $field_name = substr($field_name, 0, 32);
  82. // Skip the primary key field.
  83. if ($column_name == $schema['primary key'][0]) {
  84. continue;
  85. }
  86. // If the type_id defines the content type and it's part of the
  87. // base table and this column is the type_id then skip it.
  88. if (!$type_table and $type_column and $column_name == $type_column) {
  89. continue;
  90. }
  91. // Set some defaults for the field.
  92. $base_info = array(
  93. 'field_name' => $field_name,
  94. 'type' => '',
  95. 'cardinality' => 1,
  96. 'locked' => FALSE,
  97. 'storage' => array(
  98. 'type' => 'field_chado_storage',
  99. 'sql' => array(),
  100. ),
  101. );
  102. // Alter the field info array depending on the column details.
  103. switch($details['type']) {
  104. case 'char':
  105. $base_info['type'] = 'text';
  106. $base_info['settings']['max_length'] = $details['length'];
  107. break;
  108. case 'varchar':
  109. $base_info['type'] = 'text';
  110. $base_info['settings']['max_length'] = $details['length'];
  111. break;
  112. case 'text':
  113. $base_info['type'] = 'text';
  114. $base_info['settings']['max_length'] = 17179869184;
  115. $base_info['settings']['text_processing'] = 1;
  116. break;
  117. case 'blob':
  118. // not sure how to support a blob field.
  119. continue;
  120. break;
  121. case 'int':
  122. $base_info['type'] = 'number_integer';
  123. break;
  124. case 'float':
  125. $base_info['type'] = 'number_float';
  126. $base_info['settings']['precision'] = 10;
  127. $base_info['settings']['scale'] = 2;
  128. $base_info['settings']['decimal_separator'] = '.';
  129. break;
  130. case 'numeric':
  131. $base_info['type'] = 'number_decimal';
  132. break;
  133. case 'serial':
  134. // Serial fields are most likely not needed as a field.
  135. break;
  136. case 'boolean':
  137. $base_info['type'] = 'list_boolean';
  138. $base_info['settings']['allowed_values'] = array(0 => "No", 1 => "Yes");
  139. break;
  140. case 'datetime':
  141. // Use the Drupal Date and Date API to create the field/widget
  142. $base_info['type'] = 'datetime';
  143. break;
  144. }
  145. // Set some default semantic web information
  146. if ($column_name == 'uniquename') {
  147. $base_info['settings']['text_processing'] = 0;
  148. }
  149. //
  150. // PUB TABLE
  151. //
  152. if ($table_name == 'pub' and (
  153. $column_name == 'uniquename' or $column_name == 'title' or
  154. $column_name == 'volumetitle')) {
  155. $base_info['type'] = 'text';
  156. $base_info['settings']['text_processing'] = 0;
  157. }
  158. $info[$field_name] = $base_info;
  159. }
  160. }
  161. /**
  162. *
  163. * @param unknown $details
  164. */
  165. function tripal_chado_bundle_fields_info_custom(&$info, $details, $entity_type, $bundle) {
  166. $table_name = $details['chado_table'];
  167. $type_table = $details['chado_type_table'];
  168. $type_column = $details['chado_type_column'];
  169. $cvterm_id = $details['chado_cvterm_id'];
  170. $type_value = $details['chado_type_value'];
  171. $schema = chado_get_schema($table_name);
  172. // An additional type for the publication
  173. if ($table_name == 'pub') {
  174. $field_name = 'schema__additional_type';
  175. $field_type = 'schema__additional_type';
  176. $info[$field_name] = array(
  177. 'field_name' => $field_name,
  178. 'type' => $field_type,
  179. 'cardinality' => 1,
  180. 'locked' => FALSE,
  181. 'storage' => array(
  182. 'type' => 'field_chado_storage',
  183. ),
  184. );
  185. }
  186. // BASE ORGANISM_ID
  187. if ($table_name != 'organism' and
  188. array_key_exists('organism_id', $schema['fields'])) {
  189. $field_name = 'obi__organism';
  190. $field_type = 'obi__organism';
  191. $info[$field_name] = array(
  192. 'field_name' => $field_name,
  193. 'type' => $field_type,
  194. 'cardinality' => 1,
  195. 'locked' => FALSE,
  196. 'storage' => array(
  197. 'type' => 'field_chado_storage',
  198. ),
  199. );
  200. }
  201. // BASE ORGANISM_ID
  202. if ($table_name == 'cvterm') {
  203. $field_name = 'sio__vocabulary';
  204. $field_type = 'sio__vocabulary';
  205. $info[$field_name] = array(
  206. 'field_name' => $field_name,
  207. 'type' => $field_type,
  208. 'cardinality' => 1,
  209. 'locked' => FALSE,
  210. 'storage' => array(
  211. 'type' => 'field_chado_storage',
  212. ),
  213. );
  214. }
  215. // BASE DBXREF
  216. if (array_key_exists('dbxref_id', $schema['fields'])) {
  217. $field_name = 'data__accession';
  218. $field_type = 'data__accession';
  219. $info[$field_name] = array(
  220. 'field_name' => $field_name,
  221. 'type' => $field_type,
  222. 'cardinality' => 1,
  223. 'locked' => FALSE,
  224. 'storage' => array(
  225. 'type' => 'field_chado_storage',
  226. ),
  227. );
  228. }
  229. // FEATURE MD5CHECKSUM
  230. if ($table_name == 'feature') {
  231. $field_name = 'data__sequence_checksum';
  232. $field_type = 'data__sequence_checksum';
  233. $info[$field_name] = array(
  234. 'field_name' => $field_name,
  235. 'type' => $field_type,
  236. 'cardinality' => 1,
  237. 'locked' => FALSE,
  238. 'storage' => array(
  239. 'type' => 'field_chado_storage',
  240. ),
  241. );
  242. }
  243. // FEATURE RESIDUES
  244. if ($table_name == 'feature') {
  245. $field_name = 'data__sequence';
  246. $field_type = 'data__sequence';
  247. $info[$field_name] = array(
  248. 'field_name' => $field_name,
  249. 'type' => $field_type,
  250. 'cardinality' => 1,
  251. 'locked' => FALSE,
  252. 'storage' => array(
  253. 'type' => 'field_chado_storage',
  254. ),
  255. );
  256. }
  257. // FEATURE SEQLEN
  258. if ($table_name == 'feature') {
  259. $field_name = 'data__sequence_length';
  260. $field_type = 'data__sequence_length';
  261. $info[$field_name] = array(
  262. 'field_name' => $field_name,
  263. 'type' => $field_type,
  264. 'cardinality' => 1,
  265. 'locked' => FALSE,
  266. 'storage' => array(
  267. 'type' => 'field_chado_storage',
  268. ),
  269. );
  270. }
  271. // PROTEIN & CDS
  272. if ($table_name == 'feature' and
  273. ($bundle->label == 'mRNA' or $bundle->label == 'transcript')) {
  274. $field_name = 'data__protein_sequence';
  275. $field_type = 'data__protein_sequence';
  276. $info[$field_name] = array(
  277. 'field_name' => $field_name,
  278. 'type' => $field_type,
  279. 'cardinality' => 1,
  280. 'locked' => FALSE,
  281. 'storage' => array(
  282. 'type' => 'field_chado_storage',
  283. ),
  284. );
  285. // $field_name = 'so__cds';
  286. // $field_type = 'so__cds';
  287. // $info[$field_name] = array(
  288. // 'field_name' => $field_name,
  289. // 'type' => $field_type,
  290. // 'cardinality' => 1,
  291. // 'locked' => FALSE,
  292. // 'storage' => array(
  293. // 'type' => 'field_chado_storage',
  294. // ),
  295. // );
  296. }
  297. // // GENE TRANSCRIPTS
  298. // $rel_table = $table_name . '_relationship';
  299. // if (chado_table_exists($rel_table) and $bundle->label == 'gene') {
  300. // $field_name = 'so__transcript';
  301. // $field_type = 'so__transcript';
  302. // $info[$field_name] = array(
  303. // 'field_name' => $field_name,
  304. // 'type' => $field_type,
  305. // 'cardinality' => FIELD_CARDINALITY_UNLIMITED,
  306. // 'locked' => FALSE,
  307. // 'storage' => array(
  308. // 'type' => 'field_chado_storage',
  309. // ),
  310. // );
  311. // }
  312. // ORGANISM TYPE_ID
  313. if ($table_name == 'organism' and array_key_exists('type_id', $schema['fields'])) {
  314. $field_name = 'taxrank__infraspecific_taxon';
  315. $field_type = 'taxrank__infraspecific_taxon';
  316. $info[$field_name] = array(
  317. 'field_name' => $field_name,
  318. 'type' => $field_type,
  319. 'cardinality' => 1,
  320. 'locked' => FALSE,
  321. 'storage' => array(
  322. 'type' => 'field_chado_storage',
  323. ),
  324. );
  325. }
  326. // FEATUREMAP UNITTYPE_ID
  327. if ($table_name == 'featuremap') {
  328. $field_name = 'uo__unit';
  329. $field_type = 'uo__unit';
  330. $info[$field_name] = array(
  331. 'field_name' => $field_name,
  332. 'type' => $field_type,
  333. 'cardinality' => 1,
  334. 'locked' => FALSE,
  335. 'storage' => array(
  336. 'type' => 'field_chado_storage',
  337. ),
  338. );
  339. }
  340. // Analysis source
  341. if ($table_name == 'analysis') {
  342. $field_name = 'local__source_data';
  343. $field_type = 'local__source_data';
  344. $info[$field_name] = array(
  345. 'field_name' => $field_name,
  346. 'type' => $field_type,
  347. 'cardinality' => 1,
  348. 'locked' => FALSE,
  349. 'storage' => array(
  350. 'type' => 'field_chado_storage',
  351. ),
  352. );
  353. }
  354. // Add an image field to the Organism type. This is a Drupal field and
  355. // not stored in Chado, but is used for backwards compatibility.
  356. if ($table_name == 'organism') {
  357. $field_name = 'data__image';
  358. $info[$field_name] = array(
  359. 'field_name' => $field_name,
  360. 'type' => 'image',
  361. 'cardinality' => 1,
  362. 'locked' => FALSE,
  363. 'storage' => array(
  364. 'type' => 'field_sql_storage',
  365. ),
  366. );
  367. }
  368. }
  369. /**
  370. *
  371. * @param unknown $details
  372. */
  373. function tripal_chado_bundle_fields_info_linker(&$info, $details, $entity_type, $bundle) {
  374. $table_name = $details['chado_table'];
  375. $type_table = $details['chado_type_table'];
  376. $type_column = $details['chado_type_column'];
  377. $cvterm_id = $details['chado_cvterm_id'];
  378. $type_value = $details['chado_type_value'];
  379. // CONTACTS
  380. $contact_table = $table_name . '_contact';
  381. if (chado_table_exists($contact_table)) {
  382. $schema = chado_get_schema($contact_table);
  383. $pkey = $schema['primary key'][0];
  384. $field_name = $table_name . '_contact';
  385. $field_type = 'chado_linker__contact';
  386. $info[$field_name] = array(
  387. 'field_name' => $field_name,
  388. 'type' => $field_type,
  389. 'cardinality' => FIELD_CARDINALITY_UNLIMITED,
  390. 'locked' => FALSE,
  391. 'storage' => array(
  392. 'type' => 'field_chado_storage',
  393. ),
  394. );
  395. }
  396. // DBXREF
  397. $dbxref_table = $table_name . '_dbxref';
  398. if (chado_table_exists($dbxref_table)) {
  399. $field_name = 'sbo__database_cross_reference';
  400. $field_type = 'sbo__database_cross_reference';
  401. $info[$field_name] = array(
  402. 'field_name' => $field_name,
  403. 'type' => $field_type,
  404. 'cardinality' => FIELD_CARDINALITY_UNLIMITED,
  405. 'locked' => FALSE,
  406. 'storage' => array(
  407. 'type' => 'field_chado_storage',
  408. ),
  409. );
  410. }
  411. // EXPRESSION
  412. // TODO: this should only show up on gene or mRNA bunldes, not every feature.
  413. // $expression_table = $table_name . '_expression';
  414. // if (chado_table_exists($expression_table)) {
  415. // $field_name = 'go__gene_expression';
  416. // $field_type = 'go__gene_expression';
  417. // $info[$field_name] = array(
  418. // 'field_name' => $field_name,
  419. // 'type' => $field_type,
  420. // 'cardinality' => FIELD_CARDINALITY_UNLIMITED,
  421. // 'locked' => FALSE,
  422. // 'storage' => array(
  423. // 'type' => 'field_chado_storage',
  424. // ),
  425. // );
  426. // }
  427. // FEATURELOC
  428. if ($table_name == 'feature') {
  429. $field_name = 'data__sequence_coordinates';
  430. $field_type = 'data__sequence_coordinates';
  431. $info[$field_name] = array(
  432. 'field_name' => $field_name,
  433. 'type' => $field_type,
  434. 'cardinality' => FIELD_CARDINALITY_UNLIMITED,
  435. 'locked' => FALSE,
  436. 'storage' => array(
  437. 'type' => 'field_chado_storage',
  438. ),
  439. );
  440. }
  441. // FEATUREPOS
  442. if ($table_name == 'feature') {
  443. $field_name = 'ogi__location_on_map';
  444. $field_type = 'ogi__location_on_map';
  445. $info[$field_name] = array(
  446. 'field_name' => $field_name,
  447. 'type' => $field_type,
  448. 'cardinality' => FIELD_CARDINALITY_UNLIMITED,
  449. 'locked' => FALSE,
  450. 'storage' => array(
  451. 'type' => 'field_chado_storage',
  452. ),
  453. );
  454. }
  455. // // GENOTYPE
  456. // $genotype_table = $table_name . '_genotype';
  457. // if (chado_table_exists($genotype_table)) {
  458. // $field_name = 'so__genotype';
  459. // $field_type = 'so__genotype';
  460. // $info[$field_name] = array(
  461. // 'field_name' => $field_name,
  462. // 'type' => $field_type,
  463. // 'cardinality' => FIELD_CARDINALITY_UNLIMITED,
  464. // 'locked' => FALSE,
  465. // 'storage' => array(
  466. // 'type' => 'field_chado_storage',
  467. // ),
  468. // );
  469. // }
  470. // // PHENOTYPE
  471. // $phenotype_table = $table_name . '_phenotype';
  472. // if (chado_table_exists($phenotype_table)) {
  473. // $field_name = 'sbo__phenotype';
  474. // $field_type = 'sbo__phenotype';
  475. // $info[$field_name] = array(
  476. // 'field_name' => $field_name,
  477. // 'type' => $field_type,
  478. // 'cardinality' => FIELD_CARDINALITY_UNLIMITED,
  479. // 'locked' => FALSE,
  480. // 'storage' => array(
  481. // 'type' => 'field_chado_storage',
  482. // ),
  483. // );
  484. // }
  485. // PROPERTIES
  486. $prop_table = $table_name . 'prop';
  487. if (chado_table_exists($prop_table)) {
  488. // Get the list of existing property types for this table.
  489. $sql = 'SELECT DISTINCT type_id FROM {' . $prop_table . '}';
  490. $props = chado_query($sql);
  491. while ($prop = $props->fetchObject()) {
  492. $term = chado_generate_var('cvterm', array('cvterm_id' => $prop->type_id));
  493. // The tripal_analysis_KEGG, tripal_analysis_blast, and
  494. // tripal_analysis_interpro modules store results in the analysisprop
  495. // table which is probably not the best place, but we don't want to
  496. // create a ton of fields for this, so skip them.
  497. if ($prop_table == 'analysisprop' and
  498. ($term->dbxref_id->db_id->name == 'KEGG_BRITE' or
  499. $term->dbxref_id->db_id->name == 'tripal')) {
  500. continue;
  501. }
  502. $field_name = strtolower(preg_replace('/[^\w]/','_', $term->dbxref_id->db_id->name . '__' . $term->name));
  503. $field_name = substr($field_name, 0, 32);
  504. $field_type = 'chado_linker__prop';
  505. $info[$field_name] = array(
  506. 'field_name' => $field_name,
  507. 'type' => $field_type,
  508. 'cardinality' => 1,
  509. 'locked' => FALSE,
  510. 'storage' => array(
  511. 'type' => 'field_chado_storage',
  512. ),
  513. );
  514. }
  515. }
  516. // CVTERMS
  517. $term_table = $table_name . '_cvterm';
  518. if (chado_table_exists($term_table)) {
  519. $schema = chado_get_schema($term_table);
  520. $pkey = $schema['primary key'][0];
  521. $lkey = key($schema['foreign keys'][$table_name]['columns']);
  522. $rkey = $schema['foreign keys'][$table_name]['columns'][$lkey];
  523. $field_name = 'sio__annotation';
  524. $field_type = 'sio__annotation';
  525. $info[$field_name] = array(
  526. 'field_name' => $field_name,
  527. 'type' => $field_type,
  528. 'cardinality' => FIELD_CARDINALITY_UNLIMITED,
  529. 'locked' => FALSE,
  530. 'storage' => array(
  531. 'type' => 'field_chado_storage',
  532. ),
  533. );
  534. }
  535. // PUBLICATIONS
  536. $pub_table = $table_name . '_pub';
  537. if (chado_table_exists($pub_table)) {
  538. $field_name = 'schema__publication';
  539. $field_type = 'schema__publication';
  540. $info[$field_name] = array(
  541. 'field_name' => $field_name,
  542. 'type' => $field_type,
  543. 'cardinality' => FIELD_CARDINALITY_UNLIMITED,
  544. 'locked' => FALSE,
  545. 'storage' => array(
  546. 'type' => 'field_chado_storage',
  547. ),
  548. );
  549. }
  550. // PUBLICATIONS (in reverse)
  551. // We want to be able to show all of the content that a publication links
  552. // to. The sio__references field does that.
  553. if ($table_name == 'pub') {
  554. $field_name = 'sio__references';
  555. $field_type = 'sio__references';
  556. $info[$field_name] = array(
  557. 'field_name' => $field_name,
  558. 'type' => $field_type,
  559. 'cardinality' => FIELD_CARDINALITY_UNLIMITED,
  560. 'locked' => FALSE,
  561. 'storage' => array(
  562. 'type' => 'field_chado_storage',
  563. ),
  564. );
  565. }
  566. // RELATIONSHIPS
  567. // If the linker table does not exists then we don't want to add attach.
  568. $rel_table = $table_name . '_relationship';
  569. if (chado_table_exists($rel_table)) {
  570. $field_name = 'sbo__relationship';
  571. $field_type = 'sbo__relationship';
  572. $info[$field_name] = array(
  573. 'field_name' => $field_name,
  574. 'type' => $field_type,
  575. 'cardinality' => FIELD_CARDINALITY_UNLIMITED,
  576. 'locked' => FALSE,
  577. 'storage' => array(
  578. 'type' => 'field_chado_storage',
  579. ),
  580. );
  581. }
  582. // SYNONYMS
  583. $syn_table = $table_name . '_synonym';
  584. if (chado_table_exists($syn_table)) {
  585. $field_name = 'schema__alternate_name';
  586. $field_type = 'schema__alternate_name';
  587. $info[$field_name] = array(
  588. 'field_name' => $field_name,
  589. 'type' => $field_type,
  590. 'cardinality' => FIELD_CARDINALITY_UNLIMITED,
  591. 'locked' => FALSE,
  592. 'storage' => array(
  593. 'type' => 'field_chado_storage',
  594. ),
  595. 'settings' => array(
  596. ),
  597. );
  598. }
  599. }
  600. /**
  601. * Impelments hook_create_tripalfield_instance().
  602. *
  603. * This is a Tripal defined hook that supports integration with the
  604. * TripalEntity field.
  605. */
  606. function tripal_chado_bundle_instances_info($entity_type, $bundle) {
  607. $chado_bundle = db_select('chado_bundle', 'cb')
  608. ->fields('cb')
  609. ->condition('bundle_id', $bundle->id)
  610. ->execute()
  611. ->fetchObject();
  612. $details = array(
  613. 'chado_cvterm_id' => $chado_bundle->type_id,
  614. 'chado_table' => $chado_bundle->data_table,
  615. 'chado_type_table' => $chado_bundle->type_linker_table,
  616. 'chado_type_column' => $chado_bundle->type_column,
  617. 'chado_type_value' => $chado_bundle->type_value,
  618. );
  619. $info = array();
  620. tripal_chado_bundle_instances_info_base($info, $entity_type, $bundle, $details);
  621. tripal_chado_bundle_instances_info_custom($info, $entity_type, $bundle, $details);
  622. tripal_chado_bundle_instances_info_linker($info, $entity_type, $bundle, $details);
  623. return $info;
  624. }
  625. /**
  626. * Helper function for the hook_create_tripalfield_instance().
  627. *
  628. * Add the field instances that corresond to the columns of the base table.
  629. *
  630. * @param $entity_type
  631. * @param $bundle
  632. * @param $details
  633. */
  634. function tripal_chado_bundle_instances_info_base(&$info, $entity_type, $bundle, $details) {
  635. $fields = array();
  636. // Get Chado information
  637. $table_name = $details['chado_table'];
  638. $type_table = $details['chado_type_table'];
  639. $type_column = $details['chado_type_column'];
  640. $cvterm_id = $details['chado_cvterm_id'];
  641. $type_value = $details['chado_type_value'];
  642. // Iterate through the columns of the table and see if fields have been
  643. // created for each one. If not, then create them.
  644. $schema = chado_get_schema($table_name);
  645. if (!$schema) {
  646. return;
  647. }
  648. $pkey = $schema['primary key'][0];
  649. $columns = $schema['fields'];
  650. foreach ($columns as $column_name => $details) {
  651. // Skip the source columns in the analysis table. We have a custom
  652. // field for those columns
  653. if ($table_name == 'analysis' and ($column_name == 'sourceuri' or
  654. $column_name == 'sourceversion' or $column_name == 'sourcename')) {
  655. continue;
  656. }
  657. // Skip the infraspecific type_id and name from the organism table as we
  658. // have a special field for those.
  659. if ($table_name == 'organism' and ($column_name == 'type_id' or
  660. $column_name == 'infraspecific_name')) {
  661. continue;
  662. }
  663. // Don't create base fields for the primary key and the type_id field.
  664. if ($column_name == $pkey or $column_name == $type_column) {
  665. continue;
  666. }
  667. // Skip the type field that will always be custom
  668. if (($table_name == $type_table and $column_name == $type_column) or
  669. $column_name == 'type_id') {
  670. continue;
  671. }
  672. $cvterm = tripal_get_chado_semweb_term($table_name, $column_name, array('return_object' => TRUE));
  673. if (!$cvterm) {
  674. // We already provided an error when creating the base field. So
  675. // don't create another one here.
  676. continue;
  677. }
  678. $field_name = strtolower($cvterm->dbxref_id->db_id->name . '__' . preg_replace('/[^\w]/', '_', $cvterm->name));
  679. $field_name = substr($field_name, 0, 32);
  680. // Skip the primary key field.
  681. if ($column_name == $schema['primary key'][0]) {
  682. continue;
  683. }
  684. // If the type_id defines the content type and it's part of the
  685. // base table and this column is the type_id then skip it.
  686. if (!$type_table and $type_column and $column_name == $type_column) {
  687. continue;
  688. }
  689. $base_info = array(
  690. 'field_name' => $field_name,
  691. 'entity_type' => 'TripalEntity',
  692. 'bundle' => $bundle->name,
  693. 'label' => ucwords(preg_replace('/_/', ' ', $column_name)),
  694. 'description' => '',
  695. 'required' => FALSE,
  696. 'settings' => array(
  697. 'auto_attach' => TRUE,
  698. 'term_vocabulary' => $cvterm->dbxref_id->db_id->name,
  699. 'term_name' => $cvterm->name,
  700. 'term_accession' => $cvterm->dbxref_id->accession,
  701. 'chado_table' => $table_name,
  702. 'chado_column' => $column_name,
  703. 'base_table' => $table_name,
  704. ),
  705. 'widget' => array(
  706. 'settings' => array(
  707. 'display_label' => 1,
  708. ),
  709. ),
  710. 'display' => array(
  711. 'default' => array(
  712. 'label' => 'inline',
  713. 'region' =>'Left',
  714. 'settings' => array(),
  715. ),
  716. ),
  717. );
  718. // Determine if the field is required.
  719. if (array_key_exists('not null', $details) and $details['not null'] === TRUE) {
  720. $base_info['required'] = TRUE;
  721. }
  722. // Alter the field info array depending on the column details.
  723. switch($details['type']) {
  724. case 'char':
  725. $base_info['widget']['type'] = 'text_textfield';
  726. break;
  727. case 'varchar':
  728. $base_info['widget']['type'] = 'text_textfield';
  729. break;
  730. case 'text':
  731. $base_info['display']['default']['label'] = 'above';
  732. $base_info['widget']['type'] = 'text_textarea';
  733. $base_info['settings']['text_processing'] = '1';
  734. $base_info['settings']['format'] = 'full_html';
  735. break;
  736. case 'blob':
  737. // not sure how to support a blob field.
  738. continue;
  739. break;
  740. case 'int':
  741. $base_info['widget']['type'] = 'number';
  742. break;
  743. case 'float':
  744. $base_info['widget']['type'] = 'number';
  745. break;
  746. case 'numeric':
  747. $base_info['widget']['type'] = 'number';
  748. break;
  749. case 'serial':
  750. // Serial fields are most likely not needed as a field.
  751. break;
  752. case 'boolean':
  753. $base_info['widget']['type'] = 'options_onoff';
  754. $base_info['required'] = FALSE;
  755. break;
  756. case 'datetime':
  757. $base_info['widget']['type'] = 'date_select';
  758. $base_info['widget']['settings']['increment'] = 1;
  759. $base_info['widget']['settings']['tz_handling'] = 'none';
  760. $base_info['widget']['settings']['collapsible'] = TRUE;
  761. // TODO: Add settings so that the minutes increment by 1.
  762. // And turn off the timezone, as the Chado field doesn't support it.
  763. break;
  764. }
  765. // Set some default semantic web information
  766. if ($column_name == 'uniquename') {
  767. $base_info['label'] = 'Identifier';
  768. $base_info['widget']['type'] = 'text_textfield';
  769. if ($details['type'] == 'text') {
  770. unset($base_info['display']['default']['label']);
  771. unset($base_info['settings']['text_processing']);
  772. unset($base_info['settings']['format']);
  773. }
  774. }
  775. if ($base_info['label'] == 'Timeaccessioned') {
  776. $base_info['label'] = 'Time Accessioned';
  777. $base_info['description'] = 'Please enter the time that this record was first added to the database.';
  778. }
  779. if ($base_info['label'] == 'Timelastmodified') {
  780. $base_info['label'] = 'Time Last Modified';
  781. $base_info['description'] = 'Please enter the time that this record was last modified. The default is the current time.';
  782. }
  783. //
  784. // ORGANISM TABLE
  785. //
  786. if ($table_name == 'organism' and $column_name == 'comment') {
  787. $base_info['label'] = 'Description';
  788. }
  789. //
  790. // FEATUREMAP TABLE
  791. //
  792. if ($table_name == 'featuremap' and $column_name == 'name') {
  793. $base_info['required'] = TRUE;
  794. }
  795. //
  796. // PUB TABLE
  797. //
  798. if ($table_name == 'pub') {
  799. if ($column_name == 'title' or $column_name == 'type_id') {
  800. $base_info['required'] = TRUE;
  801. }
  802. if($column_name == 'uniquename' or $column_name == 'title' or $column_name == 'volumetitle') {
  803. $base_info['widget']['type'] = 'text_textfield';
  804. $base_info['settings']['text_processing'] = '0';
  805. }
  806. if($column_name == 'uniquename') {
  807. $base_info['label'] = 'Unique Local Identifier';
  808. $base_info['required'] = TRUE;
  809. $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.';
  810. }
  811. if($column_name == 'title') {
  812. $base_info['description'] = 'The title of the published work.';
  813. }
  814. if($column_name == 'series_name') {
  815. $base_info['description'] = 'The name media that produces a series of publications (e.g. journal, conference proceedings, etc.).';
  816. }
  817. if($column_name == 'issue') {
  818. $base_info['description'] = 'The issue of the series (e.g. journal) where the publication was printed.';
  819. }
  820. if($column_name == 'volume') {
  821. $base_info['description'] = 'The volume of the series (e.g. journal) where the publication was printed.';
  822. }
  823. if($column_name == 'pyear') {
  824. $base_info['label'] = 'Publication Year';
  825. $base_info['required'] = TRUE;
  826. }
  827. if($column_name == 'pages') {
  828. $base_info['label'] = 'Page Numbers';
  829. }
  830. if($column_name == 'pubplace') {
  831. $base_info['label'] = 'Publication Location';
  832. }
  833. if($column_name == 'volumetitle') {
  834. $base_info['label'] = 'Volumn Title';
  835. $base_info['label'] = 'The title of the volume (if applicable).';
  836. }
  837. if($column_name == 'miniref') {
  838. $base_info['label'] = 'Mini Local identifier';
  839. $base_info['description'] = 'Some sites use small identifiers for each publication. if your site uses this please provide the proper miniref for this publication.';
  840. }
  841. }
  842. //
  843. // ANALYSIS TABLE
  844. //
  845. if ($table_name == 'analysis' and $column_name == 'name') {
  846. $base_info['required'] = TRUE;
  847. }
  848. if ($table_name == 'analysis' and $column_name == 'program') {
  849. $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.';
  850. $base_info['label'] = 'Program, Pipeline, Workflow or Method Name';
  851. }
  852. if ($table_name == 'analysis' and $column_name == 'algorithm') {
  853. $base_info['label'] = 'Source Version';
  854. $base_info['description'] = 'The name of the algorithm used to produce the dataset if different from the program.';
  855. }
  856. if ($table_name == 'analysis' and $column_name == 'programversion') {
  857. $base_info['label'] = 'Program Version';
  858. $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.';
  859. }
  860. if ($table_name == 'analysis' and $column_name == 'timeexecuted') {
  861. $base_info['label'] = 'Date Performed';
  862. $base_info['description'] = 'The date and time when the analysis was performed.';
  863. }
  864. if ($table_name == 'analysis' and ($column_name == 'sourceuri' or
  865. $column_name == 'sourceversion' or $column_name == 'sourcename')) {
  866. // Skip the source columns in the analysis table. We have a custom
  867. // field for those columns
  868. continue;
  869. }
  870. //
  871. // PROJECT TABLE
  872. //
  873. if ($table_name == 'project' and $column_name == 'description') {
  874. $base_info['label'] = 'Short Description';
  875. }
  876. $info[$field_name] = $base_info;
  877. }
  878. }
  879. /**
  880. * Helper function for the hook_create_tripalfield_instance().
  881. *
  882. * Adds custom fields for base fields. These override the settings provided
  883. * in the tripal_chado_create_tripalfield_instance_base() function.
  884. *
  885. * @param $entity_type
  886. * @param $bundle
  887. * @param $details
  888. */
  889. function tripal_chado_bundle_instances_info_custom(&$info, $entity_type, $bundle, $details) {
  890. $table_name = $details['chado_table'];
  891. $type_table = $details['chado_type_table'];
  892. $type_column = $details['chado_type_column'];
  893. $cvterm_id = $details['chado_cvterm_id'];
  894. $type_value = $details['chado_type_value'];
  895. $schema = chado_get_schema($table_name);
  896. // An additional type for publications
  897. if ($table_name == 'pub') {
  898. $field_name = 'schema__additional_type';
  899. $is_required = FALSE;
  900. if (array_key_exists('not null', $schema['fields']['type_id']) and
  901. $schema['fields']['type_id']['not null']) {
  902. $is_required = TRUE;
  903. }
  904. $info[$field_name] = array(
  905. 'field_name' => $field_name,
  906. 'entity_type' => $entity_type,
  907. 'bundle' => $bundle->name,
  908. 'label' => 'Publication Type',
  909. 'description' => 'Select the publication type.',
  910. 'required' => $is_required,
  911. 'settings' => array(
  912. 'auto_attach' => TRUE,
  913. 'chado_table' => $table_name,
  914. 'chado_column' => 'type_id',
  915. 'base_table' => $table_name,
  916. 'vocabulary' => 'tripal_pub',
  917. 'parent_term' => 'TPUB:0000015',
  918. ),
  919. 'widget' => array(
  920. 'type' => 'schema__additional_type_widget',
  921. 'settings' => array(
  922. 'display_label' => 1,
  923. ),
  924. ),
  925. 'display' => array(
  926. 'default' => array(
  927. 'label' => 'inline',
  928. 'type' => 'schema__additional_type_formatter',
  929. 'settings' => array(),
  930. ),
  931. ),
  932. );
  933. }
  934. // BASE ORGANISM_ID
  935. if ($table_name != 'organism' and array_key_exists('organism_id', $schema['fields'])) {
  936. $field_name = 'obi__organism';
  937. $is_required = FALSE;
  938. if (array_key_exists('not null', $schema['fields']['organism_id']) and
  939. $schema['fields']['organism_id']['not null']) {
  940. $is_required = TRUE;
  941. }
  942. $info[$field_name] = array(
  943. 'field_name' => $field_name,
  944. 'entity_type' => $entity_type,
  945. 'bundle' => $bundle->name,
  946. 'label' => 'Organism',
  947. 'description' => 'The full scientific name for a species..',
  948. 'required' => $is_required,
  949. 'settings' => array(
  950. 'auto_attach' => TRUE,
  951. 'chado_table' => $table_name,
  952. 'chado_column' => 'organism_id',
  953. 'base_table' => $table_name,
  954. ),
  955. 'widget' => array(
  956. 'type' => 'obi__organism_widget',
  957. 'settings' => array(
  958. 'display_label' => 1,
  959. ),
  960. ),
  961. 'display' => array(
  962. 'default' => array(
  963. 'label' => 'inline',
  964. 'type' => 'obi__organism_formatter',
  965. 'settings' => array(),
  966. ),
  967. ),
  968. );
  969. }
  970. // BASE CVTERM
  971. if ($table_name == 'cvterm') {
  972. $field_name = 'sio__vocabulary';
  973. $is_required = TRUE;
  974. $info[$field_name] = array(
  975. 'field_name' => $field_name,
  976. 'entity_type' => $entity_type,
  977. 'bundle' => $bundle->name,
  978. 'label' => 'Vocabulary',
  979. 'description' => 'A controlled vocabulary.',
  980. 'required' => $is_required,
  981. 'settings' => array(
  982. 'auto_attach' => TRUE,
  983. 'chado_table' => $table_name,
  984. 'chado_column' => 'cv_id',
  985. 'base_table' => $table_name,
  986. ),
  987. 'widget' => array(
  988. 'type' => 'sio__vocabulary_widget',
  989. 'settings' => array(
  990. 'display_label' => 1,
  991. ),
  992. ),
  993. 'display' => array(
  994. 'default' => array(
  995. 'label' => 'inline',
  996. 'type' => 'sio__vocabulary_formatter',
  997. 'settings' => array(),
  998. ),
  999. ),
  1000. );
  1001. }
  1002. // BASE DBXREF
  1003. if (array_key_exists('dbxref_id', $schema['fields'])) {
  1004. $field_name = 'data__accession';
  1005. $info[$field_name] = array(
  1006. 'field_name' => $field_name,
  1007. 'entity_type' => $entity_type,
  1008. 'bundle' => $bundle->name,
  1009. 'label' => 'Accession',
  1010. 'description' => 'This field specifies the unique stable accession (ID) for
  1011. this record. It requires that this site have a database entry.',
  1012. 'required' => FALSE,
  1013. 'settings' => array(
  1014. 'auto_attach' => TRUE,
  1015. 'chado_table' => $table_name,
  1016. 'chado_column' => 'dbxref_id',
  1017. 'base_table' => $table_name,
  1018. ),
  1019. 'widget' => array(
  1020. 'type' => 'data__accession_widget',
  1021. 'settings' => array(
  1022. 'display_label' => 1,
  1023. ),
  1024. ),
  1025. 'display' => array(
  1026. 'default' => array(
  1027. 'label' => 'inline',
  1028. 'type' => 'data__accession_formatter',
  1029. 'settings' => array(),
  1030. ),
  1031. ),
  1032. );
  1033. }
  1034. // FEATURE MD5CHECKSUM
  1035. if ($table_name == 'feature') {
  1036. $field_name = 'data__sequence_checksum';
  1037. $info[$field_name] = array(
  1038. 'field_name' => $field_name,
  1039. 'entity_type' => $entity_type,
  1040. 'bundle' => $bundle->name,
  1041. 'label' => 'Sequence Checksum',
  1042. 'description' => 'The MD5 checksum for the sequence. The checksum here
  1043. will always be unique for the raw unformatted sequence. To verify that the
  1044. sequence has not been corrupted, download the raw sequence and use an MD5 tool
  1045. to calculate the value. If the value calculated is identical the one shown
  1046. here, then the downloaded sequence is uncorrupted.',
  1047. 'required' => FALSE,
  1048. 'settings' => array(
  1049. 'auto_attach' => TRUE,
  1050. 'chado_table' => $table_name,
  1051. 'chado_column' => 'md5checksum',
  1052. 'base_table' => $table_name,
  1053. ),
  1054. 'widget' => array(
  1055. 'type' => 'data__sequence_checksum_widget',
  1056. 'settings' => array(
  1057. 'display_label' => 1,
  1058. 'md5_fieldname' => 'feature__md5checksum',
  1059. ),
  1060. ),
  1061. 'display' => array(
  1062. 'default' => array(
  1063. 'label' => 'inline',
  1064. 'type' => 'data__sequence_checksum_formatter',
  1065. 'settings' => array(),
  1066. ),
  1067. ),
  1068. );
  1069. }
  1070. // FEATURE RESIDUES
  1071. if ($table_name == 'feature') {
  1072. $field_name = 'data__sequence';
  1073. $info[$field_name] = array(
  1074. 'field_name' => $field_name,
  1075. 'entity_type' => $entity_type,
  1076. 'bundle' => $bundle->name,
  1077. 'label' => 'Sequence',
  1078. 'description' => 'All available sequences for this record.',
  1079. 'required' => FALSE,
  1080. 'settings' => array(
  1081. 'auto_attach' => FALSE,
  1082. 'chado_table' => $table_name,
  1083. 'chado_column' => 'residues',
  1084. 'base_table' => $table_name,
  1085. ),
  1086. 'widget' => array(
  1087. 'type' => 'data__sequence_widget',
  1088. 'settings' => array(
  1089. 'display_label' => 1,
  1090. ),
  1091. ),
  1092. 'display' => array(
  1093. 'default' => array(
  1094. 'label' => 'above',
  1095. 'type' => 'data__sequence_formatter',
  1096. 'settings' => array(),
  1097. ),
  1098. ),
  1099. );
  1100. }
  1101. // FEATURE SEQLEN
  1102. if ($table_name == 'feature') {
  1103. $field_name = 'data__sequence_length';
  1104. $info[$field_name] = array(
  1105. 'field_name' => $field_name,
  1106. 'entity_type' => $entity_type,
  1107. 'bundle' => $bundle->name,
  1108. 'label' => 'Sequence Length',
  1109. 'description' => 'The number of residues in the raw sequence. This length
  1110. is only for the assigned raw sequence and does not represent the length of any
  1111. sequences derived from alignments. If this value is zero but aligned sequences
  1112. are present then this record has no official assigned sequence.',
  1113. 'required' => FALSE,
  1114. 'settings' => array(
  1115. 'auto_attach' => TRUE,
  1116. 'chado_table' => $table_name,
  1117. 'chado_column' => 'seqlen',
  1118. 'base_table' => $table_name,
  1119. ),
  1120. 'widget' => array(
  1121. 'type' => 'data__sequence_length_widget',
  1122. 'settings' => array(
  1123. 'display_label' => 1,
  1124. ),
  1125. ),
  1126. 'display' => array(
  1127. 'default' => array(
  1128. 'label' => 'inline',
  1129. 'type' => 'data__sequence_length_formatter',
  1130. 'settings' => array(),
  1131. ),
  1132. ),
  1133. );
  1134. }
  1135. // PROTEIN & CDS SEQUENCES.
  1136. if ($table_name == 'feature' and
  1137. ($bundle->label == 'mRNA' or $bundle->label == 'transcript')) {
  1138. $field_name = 'data__protein_sequence';
  1139. $info[$field_name] = array(
  1140. 'field_name' => $field_name,
  1141. 'entity_type' => $entity_type,
  1142. 'bundle' => $bundle->name,
  1143. 'label' => 'Protein Sequence',
  1144. 'description' => 'Protein sequences.',
  1145. 'required' => FALSE,
  1146. 'settings' => array(
  1147. 'auto_attach' => FALSE,
  1148. 'chado_table' => 'feature',
  1149. 'chado_column' => 'residues',
  1150. 'base_table' => 'feature',
  1151. ),
  1152. 'widget' => array(
  1153. 'type' => 'data__protein_sequence_widget',
  1154. 'settings' => array(
  1155. 'display_label' => 1,
  1156. ),
  1157. ),
  1158. 'display' => array(
  1159. 'default' => array(
  1160. 'label' => 'above',
  1161. 'type' => 'data__protein_sequence_formatter',
  1162. 'settings' => array(),
  1163. ),
  1164. ),
  1165. );
  1166. // $field_name = 'so__cds';
  1167. // $info[$field_name] = array(
  1168. // 'field_name' => $field_name,
  1169. // 'entity_type' => $entity_type,
  1170. // 'bundle' => $bundle->name,
  1171. // 'label' => 'Coding Sequence',
  1172. // 'description' => 'Coding sequences.',
  1173. // 'required' => FALSE,
  1174. // 'settings' => array(
  1175. // 'auto_attach' => FALSE,
  1176. // 'chado_table' => 'featureloc',
  1177. // 'chado_column' => '',
  1178. // 'base_table' => 'featureloc',
  1179. // ),
  1180. // 'widget' => array(
  1181. // 'type' => 'so__cds_widget',
  1182. // 'settings' => array(
  1183. // 'display_label' => 1,
  1184. // ),
  1185. // ),
  1186. // 'display' => array(
  1187. // 'default' => array(
  1188. // 'label' => 'above',
  1189. // 'type' => 'so__cds_formatter',
  1190. // 'settings' => array(),
  1191. // ),
  1192. // ),
  1193. // );
  1194. }
  1195. // // GENE TRANSCRIPTS
  1196. // $rel_table = $table_name . '_relationship';
  1197. // if (chado_table_exists($rel_table) and $bundle->label == 'gene') {
  1198. // $field_name = 'so__transcript';
  1199. // $info[$field_name] = array(
  1200. // 'field_name' => $field_name,
  1201. // 'entity_type' => $entity_type,
  1202. // 'bundle' => $bundle->name,
  1203. // 'label' => 'Transcripts',
  1204. // 'description' => 'Transcripts that are part of this gene.',
  1205. // 'required' => FALSE,
  1206. // 'settings' => array(
  1207. // 'auto_attach' => FALSE,
  1208. // 'chado_table' => $rel_table,
  1209. // 'chado_column' => '',
  1210. // 'base_table' => $table_name,
  1211. // ),
  1212. // 'widget' => array(
  1213. // 'type' => 'so__transcript_widget',
  1214. // 'settings' => array(
  1215. // 'display_label' => 1,
  1216. // ),
  1217. // ),
  1218. // 'display' => array(
  1219. // 'default' => array(
  1220. // 'label' => 'above',
  1221. // 'type' => 'so__transcript_formatter',
  1222. // 'settings' => array(),
  1223. // ),
  1224. // ),
  1225. // );
  1226. // }
  1227. // ORGANISM TYPE_ID
  1228. if ($table_name == 'organism' and array_key_exists('type_id', $schema['fields'])) {
  1229. $field_name = 'taxrank__infraspecific_taxon';
  1230. $info[$field_name] = array(
  1231. 'field_name' => $field_name,
  1232. 'entity_type' => $entity_type,
  1233. 'bundle' => $bundle->name,
  1234. 'label' => 'Infraspecific Taxon',
  1235. 'description' => 'The Infraspecific Taxon.',
  1236. 'required' => FALSE,
  1237. 'settings' => array(
  1238. 'auto_attach' => TRUE,
  1239. 'chado_table' => 'organism',
  1240. 'chado_column' => 'type_id',
  1241. 'base_table' => 'organism',
  1242. ),
  1243. 'widget' => array(
  1244. 'type' => 'taxrank__infraspecific_taxon_widget',
  1245. 'settings' => array(
  1246. 'display_label' => 1,
  1247. ),
  1248. ),
  1249. 'display' => array(
  1250. 'default' => array(
  1251. 'label' => 'inline',
  1252. 'type' => 'taxrank__infraspecific_taxon_formatter',
  1253. 'settings' => array(),
  1254. ),
  1255. ),
  1256. );
  1257. }
  1258. // FEATURE MAP UNITS
  1259. if ($table_name == 'featuremap') {
  1260. $field_name = 'uo__unit';
  1261. $info[$field_name] = array(
  1262. 'field_name' => $field_name,
  1263. 'entity_type' => $entity_type,
  1264. 'bundle' => $bundle->name,
  1265. 'label' => 'Units',
  1266. 'description' => 'The map\'s unit type.',
  1267. 'required' => TRUE,
  1268. 'settings' => array(
  1269. 'auto_attach' => TRUE,
  1270. 'chado_table' => $table_name,
  1271. 'chado_column' => 'unittype_id',
  1272. 'base_table' => $table_name,
  1273. ),
  1274. 'widget' => array(
  1275. 'type' => 'uo__unit_widget',
  1276. 'settings' => array(
  1277. 'display_label' => 1,
  1278. ),
  1279. ),
  1280. 'display' => array(
  1281. 'default' => array(
  1282. 'label' => 'inline',
  1283. 'type' => 'uo__unit_formatter',
  1284. 'settings' => array(),
  1285. ),
  1286. ),
  1287. );
  1288. }
  1289. // the analysis source.
  1290. if ($table_name == 'analysis') {
  1291. $field_name = 'local__source_data';
  1292. $info[$field_name] = array(
  1293. 'field_name' => $field_name,
  1294. 'entity_type' => $entity_type,
  1295. 'bundle' => $bundle->name,
  1296. 'label' => 'Data Source',
  1297. 'description' => 'The source where data was obtained for this analysis.',
  1298. 'required' => FALSE,
  1299. 'settings' => array(
  1300. 'auto_attach' => TRUE,
  1301. 'chado_table' => $table_name,
  1302. 'chado_column' => 'analysis_id',
  1303. 'base_table' => $table_name,
  1304. ),
  1305. 'widget' => array(
  1306. 'type' => 'local__source_data_widget',
  1307. 'settings' => array(
  1308. 'display_label' => 1,
  1309. ),
  1310. ),
  1311. 'display' => array(
  1312. 'default' => array(
  1313. 'label' => 'inline',
  1314. 'type' => 'local__source_data_formatter',
  1315. 'settings' => array(),
  1316. ),
  1317. ),
  1318. );
  1319. }
  1320. // Add an image field to the Organism type. This is a Drupal field and
  1321. // not stored in Chado, but is used for backwards compatibility.
  1322. if ($table_name == 'organism') {
  1323. $field_name = 'data__image';
  1324. $info[$field_name] = array(
  1325. 'field_name' => $field_name,
  1326. 'entity_type' => $entity_type,
  1327. 'bundle' => $bundle->name,
  1328. 'label' => 'Organism Image',
  1329. 'description' => 'An image for the organism',
  1330. 'required' => FALSE,
  1331. 'settings' => array(
  1332. 'term_vocabulary' => 'data',
  1333. 'term_name' => 'Image',
  1334. 'term_accession' => '2968',
  1335. ),
  1336. 'display' => array(
  1337. 'default' => array(
  1338. 'label' => 'hidden',
  1339. ),
  1340. ),
  1341. );
  1342. }
  1343. }
  1344. /**
  1345. *
  1346. * @param unknown $entity_type
  1347. * @param unknown $bundle
  1348. * @param unknown $details
  1349. */
  1350. function tripal_chado_bundle_instances_info_linker(&$info, $entity_type, $bundle, $details) {
  1351. $table_name = $details['chado_table'];
  1352. $type_table = $details['chado_type_table'];
  1353. $type_column = $details['chado_type_column'];
  1354. $cvterm_id = $details['chado_cvterm_id'];
  1355. $type_value = $details['chado_type_value'];
  1356. // CONTACTS
  1357. $contact_table = $table_name . '_contact';
  1358. if (chado_table_exists($contact_table)) {
  1359. $field_name = $table_name . '_contact';
  1360. $info[$field_name] = $info[$field_name] = array(
  1361. 'field_name' => $field_name,
  1362. 'entity_type' => $entity_type,
  1363. 'bundle' => $bundle->name,
  1364. 'label' => 'Contact',
  1365. 'description' => 'Associates an indviddual or organization with this record',
  1366. 'required' => FALSE,
  1367. 'settings' => array(
  1368. 'auto_attach' => FALSE,
  1369. 'chado_table' => $contact_table,
  1370. 'base_table' => $table_name,
  1371. 'chado_column' => 'contact_id',
  1372. ),
  1373. 'widget' => array(
  1374. 'type' => 'local__contact_widget',
  1375. 'settings' => array(
  1376. 'display_label' => 1,
  1377. ),
  1378. ),
  1379. 'display' => array(
  1380. 'default' => array(
  1381. 'label' => 'hidden',
  1382. 'type' => 'local__contact_formatter',
  1383. 'settings' => array(),
  1384. ),
  1385. ),
  1386. );
  1387. }
  1388. // DBXREF
  1389. $dbxref_table = $table_name . '_dbxref';
  1390. if (chado_table_exists($dbxref_table)) {
  1391. $field_name = 'sbo__database_cross_reference';
  1392. $schema = chado_get_schema($dbxref_table);
  1393. $pkey = $schema['primary key'][0];
  1394. $info[$field_name] = array(
  1395. 'field_name' => $field_name,
  1396. 'entity_type' => $entity_type,
  1397. 'bundle' => $bundle->name,
  1398. 'label' => 'Cross Reference',
  1399. 'description' => 'The IDs where this record may be available in other external online databases.',
  1400. 'required' => FALSE,
  1401. 'settings' => array(
  1402. 'auto_attach' => FALSE,
  1403. 'chado_table' => $dbxref_table,
  1404. 'chado_column' => $pkey,
  1405. 'base_table' => $table_name,
  1406. ),
  1407. 'widget' => array(
  1408. 'type' => 'sbo__database_cross_reference_widget',
  1409. 'settings' => array(
  1410. 'display_label' => 1,
  1411. ),
  1412. ),
  1413. 'display' => array(
  1414. 'default' => array(
  1415. 'label' => 'hidden',
  1416. 'type' => 'sbo__database_cross_reference_formatter',
  1417. 'settings' => array(),
  1418. ),
  1419. ),
  1420. );
  1421. }
  1422. // EXPRESSION
  1423. // TODO: this should only show up on gene or mRNA and the GO must be
  1424. // laoded or this field will crash things.
  1425. // $expression_table = $table_name . '_expression';
  1426. // if (chado_table_exists($expression_table)) {
  1427. // $field_name = 'go__gene_expression';
  1428. // $schema = chado_get_schema($expression_table);
  1429. // $pkey = $schema['primary key'][0];
  1430. // $info[$field_name] = array(
  1431. // 'field_name' => $field_name,
  1432. // 'entity_type' => $entity_type,
  1433. // 'bundle' => $bundle->name,
  1434. // 'label' => 'Gene expression',
  1435. // 'description' => 'Information about the expression of this record.',
  1436. // 'required' => FALSE,
  1437. // 'settings' => array(
  1438. // 'auto_attach' => FALSE,
  1439. // 'chado_table' => $expression_table,
  1440. // 'chado_column' => $pkey,
  1441. // 'base_table' => $table_name,
  1442. // ),
  1443. // 'widget' => array(
  1444. // 'type' => 'go__gene_expression_widget',
  1445. // 'settings' => array(
  1446. // 'display_label' => 1,
  1447. // ),
  1448. // ),
  1449. // 'display' => array(
  1450. // 'default' => array(
  1451. // 'label' => 'above',
  1452. // 'type' => 'go__gene_expression_formatter',
  1453. // 'settings' => array(),
  1454. // ),
  1455. // ),
  1456. // );
  1457. // }
  1458. // FEATURELOC
  1459. if ($table_name == 'feature') {
  1460. $field_name = 'data__sequence_coordinates';
  1461. $schema = chado_get_schema('featureloc');
  1462. $pkey = $schema['primary key'][0];
  1463. $info[$field_name] = array(
  1464. 'field_name' => $field_name,
  1465. 'entity_type' => $entity_type,
  1466. 'bundle' => $bundle->name,
  1467. 'label' => 'Sequence Coordinates',
  1468. 'description' => 'The locations on other genomic sequences where this
  1469. record has been aligned.',
  1470. 'required' => FALSE,
  1471. 'settings' => array(
  1472. 'auto_attach' => FALSE,
  1473. 'chado_table' => 'featureloc',
  1474. 'chado_column' => $pkey,
  1475. 'base_table' => 'feature',
  1476. ),
  1477. 'widget' => array(
  1478. 'type' => 'data__sequence_coordinates_widget',
  1479. 'settings' => array(
  1480. 'display_label' => 1,
  1481. ),
  1482. ),
  1483. 'display' => array(
  1484. 'default' => array(
  1485. 'label' => 'hidden',
  1486. 'type' => 'data__sequence_coordinates_formatter',
  1487. 'settings' => array(),
  1488. ),
  1489. ),
  1490. );
  1491. }
  1492. // FEATUREPOS
  1493. if ($table_name == 'feature') {
  1494. $field_name = 'ogi__location_on_map';
  1495. $schema = chado_get_schema('featurepos');
  1496. $pkey = $schema['primary key'][0];
  1497. $info[$field_name] = array(
  1498. 'field_name' => $field_name,
  1499. 'entity_type' => $entity_type,
  1500. 'bundle' => $bundle->name,
  1501. 'label' => 'Location on Map',
  1502. 'description' => 'The positions on a genetic map.',
  1503. 'required' => FALSE,
  1504. 'settings' => array(
  1505. 'auto_attach' => FALSE,
  1506. 'chado_table' => 'featurepos',
  1507. 'chado_column' => $pkey,
  1508. 'base_table' => 'feature',
  1509. ),
  1510. 'widget' => array(
  1511. 'type' => 'ogi__location_on_map_widget',
  1512. 'settings' => array(
  1513. 'display_label' => 1,
  1514. ),
  1515. ),
  1516. 'display' => array(
  1517. 'default' => array(
  1518. 'label' => 'hidden',
  1519. 'type' => 'ogi__location_on_map_formatter',
  1520. 'settings' => array(),
  1521. ),
  1522. ),
  1523. );
  1524. }
  1525. // // GENOTYPE
  1526. // $genotype_table = $table_name . '_genotype';
  1527. // if (chado_table_exists($genotype_table)) {
  1528. // $field_name = 'so__genotype';
  1529. // $schema = chado_get_schema($genotype_table);
  1530. // $pkey = $schema['primary key'][0];
  1531. // $info[$field_name] = array(
  1532. // 'field_name' => $field_name,
  1533. // 'entity_type' => $entity_type,
  1534. // 'bundle' => $bundle->name,
  1535. // 'label' => 'Genotype',
  1536. // 'description' => 'The genotypes associated with this record.',
  1537. // 'required' => FALSE,
  1538. // 'settings' => array(
  1539. // 'auto_attach' => FALSE,
  1540. // 'chado_table' => $genotype_table,
  1541. // 'chado_column' => $pkey,
  1542. // 'base_table' => $table_name,
  1543. // ),
  1544. // 'widget' => array(
  1545. // 'type' => 'so__genotype_widget',
  1546. // 'settings' => array(
  1547. // 'display_label' => 1,
  1548. // ),
  1549. // ),
  1550. // 'display' => array(
  1551. // 'default' => array(
  1552. // 'label' => 'hidden',
  1553. // 'type' => 'so__genotype_formatter',
  1554. // 'settings' => array(),
  1555. // ),
  1556. // ),
  1557. // );
  1558. // }
  1559. // // PHENOTYPE
  1560. // $phenotype_table = $table_name . '_phenotype';
  1561. // if (chado_table_exists($phenotype_table)) {
  1562. // $field_name = 'sbo__phenotype';
  1563. // $schema = chado_get_schema($phenotype_table);
  1564. // $pkey = $schema['primary key'][0];
  1565. // $info[$field_name] = array(
  1566. // 'field_name' => $field_name,
  1567. // 'entity_type' => $entity_type,
  1568. // 'bundle' => $bundle->name,
  1569. // 'label' => 'Phenotype',
  1570. // 'description' => 'The phenotypes associated with this record.',
  1571. // 'required' => FALSE,
  1572. // 'settings' => array(
  1573. // 'auto_attach' => FALSE,
  1574. // 'chado_table' => $phenotype_table,
  1575. // 'chado_column' => $pkey,
  1576. // 'base_table' => $table_name,
  1577. // ),
  1578. // 'widget' => array(
  1579. // 'type' => 'sbo__phenotype_widget',
  1580. // 'settings' => array(
  1581. // 'display_label' => 1,
  1582. // ),
  1583. // ),
  1584. // 'display' => array(
  1585. // 'default' => array(
  1586. // 'label' => 'hidden',
  1587. // 'type' => 'sbo__phenotype_formatter',
  1588. // 'settings' => array(),
  1589. // ),
  1590. // ),
  1591. // );
  1592. // }
  1593. // PROPERTIES
  1594. $prop_table = $table_name . 'prop';
  1595. if (chado_table_exists($prop_table)) {
  1596. $tschema = chado_get_schema($table_name);
  1597. $schema = chado_get_schema($prop_table);
  1598. $tpkey = $tschema['primary key'][0];
  1599. $pkey = $schema['primary key'][0];
  1600. // Property tables can be a bit tricky because not all property types
  1601. // in the prop table are appropriate for each type of data. Also som
  1602. // bundle types are resolved via a property. So, we have to distinguish
  1603. // between these two cases.
  1604. $sql = '';
  1605. $args = array();
  1606. // First, is this the case where all of the records in the table are
  1607. // of this type? If so, then all properties apply
  1608. if (!$type_column) {
  1609. $sql = 'SELECT DISTINCT type_id FROM {' . $prop_table . '}';
  1610. $props = chado_query($sql, $args);
  1611. }
  1612. // Second, if this is the case where a content type is uniquely identified
  1613. // by a type_id value in the base table, then only properties associated
  1614. // with that type ID should be used.
  1615. else if ($type_column and !$type_table) {
  1616. $sql = "
  1617. SELECT DISTINCT P.type_id
  1618. FROM {" . $prop_table . "} P
  1619. INNER JOIN {" . $table_name . "} T on T.$tpkey = P.$tpkey
  1620. WHERE T.$type_column = :cvterm_id
  1621. ";
  1622. $args[':cvterm_id'] = $cvterm_id;
  1623. $props = chado_query($sql, $args);
  1624. }
  1625. // Third, if this is the case where a content type is uniquely identified
  1626. // via a term/value pair in the prop table.
  1627. else if ($type_column and $type_table == $prop_table and !empty($type_value)) {
  1628. $sql = "
  1629. SELECT DISTINCT P2.type_id
  1630. FROM {" . $prop_table . "} P1
  1631. INNER JOIN {" . $table_name . "} T on T.$tpkey = P1.$tpkey
  1632. INNER JOIN {" . $prop_table . "} P2 on T.$tpkey = P2.$tpkey
  1633. WHERE P1.$type_column = :cvterm_id AND P1.value = :prop_value AND
  1634. P2.type_id != P1.type_id
  1635. ";
  1636. $args[':cvterm_id'] = $cvterm_id;
  1637. $args[':prop_value'] = $type_value;
  1638. $props = chado_query($sql, $args);
  1639. }
  1640. // Fourth, if this is the case where the content type is uinquely identifed
  1641. // via another table (e.g. cvterm linking table) and not this prop table.
  1642. else if ($type_column and $type_table != $prop_table and empty($type_value)) {
  1643. $sql = "
  1644. SELECT DISTINCT P.type_id
  1645. FROM {" . $prop_table . "} P
  1646. INNER JOIN {" . $table_name . "} T on T.$tpkey = P.$tpkey
  1647. INNER JOIN {" . $type_table . "} TT on TT.$tpkey = T.$tpkey
  1648. WHERE TT.$type_column = :cvterm_id
  1649. ";
  1650. $args[':cvterm_id'] = $cvterm_id;
  1651. $props = chado_query($sql, $args);
  1652. }
  1653. else {
  1654. // Do nothing;
  1655. }
  1656. if ($props) {
  1657. while ($prop = $props->fetchObject()) {
  1658. $term = chado_generate_var('cvterm', array('cvterm_id' => $prop->type_id));
  1659. $term = chado_expand_var($term, 'field', 'cvterm.definition');
  1660. // Skip the Publiation Type property for pubs as this is
  1661. // already handled by the pub.type_id field.
  1662. if ($term->name == 'Publication Type' and $term->cv_id->name == 'tripal_pub') {
  1663. continue;
  1664. }
  1665. // The tripal_analysis_KEGG, tripal_analysis_blast, and
  1666. // tripal_analysis_interpro modules store results in the analysisprop
  1667. // table which is probably not the best place, but we don't want to
  1668. // create a ton of fields for this.
  1669. if ($prop_table == 'analysisprop' and
  1670. ($term->dbxref_id->db_id->name == 'KEGG_BRITE' or
  1671. $term->dbxref_id->db_id->name == 'tripal')) {
  1672. continue;
  1673. }
  1674. $field_name = strtolower(preg_replace('/[^\w]/','_', $term->dbxref_id->db_id->name . '__' . $term->name));
  1675. $field_name = substr($field_name, 0, 32);
  1676. $info[$field_name] = array(
  1677. 'field_name' => $field_name,
  1678. 'entity_type' => $entity_type,
  1679. 'bundle' => $bundle->name,
  1680. 'label' => ucwords(preg_replace('/_/', ' ', $term->name)),
  1681. 'description' => $term->definition,
  1682. 'required' => FALSE,
  1683. 'settings' => array(
  1684. 'auto_attach' => TRUE,
  1685. 'term_vocabulary' => $term->dbxref_id->db_id->name,
  1686. 'term_accession' => $term->dbxref_id->accession,
  1687. 'term_name' => $term->name,
  1688. 'base_table' => $table_name,
  1689. 'chado_table' => $prop_table,
  1690. 'chado_column' => $pkey,
  1691. ),
  1692. 'widget' => array(
  1693. 'type' => 'chado_linker__prop_widget',
  1694. 'settings' => array(
  1695. 'display_label' => 1,
  1696. ),
  1697. ),
  1698. 'display' => array(
  1699. 'default' => array(
  1700. 'label' => 'hidden',
  1701. 'type' => 'chado_linker__prop_formatter',
  1702. 'settings' => array(),
  1703. ),
  1704. ),
  1705. );
  1706. // Make some customizations to some fields
  1707. if ($term->name == 'Citation' and $term->cv_id->name == 'tripal_pub') {
  1708. $info[$field_name]['required'] = TRUE;
  1709. $info[$field_name]['description'] = t('All publications must have a unique citation.
  1710. Please enter the full citation for this publication. For PubMed style citations list
  1711. the last name of the author followed by initials. Each author should be separated by a comma. Next comes
  1712. 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.
  1713. 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
  1714. suffer taxonomic influence?</a> J Ethnopharmacol. 2013 Apr 19; 146(3):842-52.</pre>');
  1715. $info[$field_name]['settings']['rows'] = 3;
  1716. }
  1717. if ($term->name == 'Abstract' and $term->cv_id->name == 'tripal_pub') {
  1718. $info[$field_name]['settings']['rows'] = 5;
  1719. }
  1720. }
  1721. }
  1722. }
  1723. // CVTERMS
  1724. $term_table = $table_name . '_cvterm';
  1725. if (chado_table_exists($term_table)) {
  1726. $schema = chado_get_schema($term_table);
  1727. $pkey = $schema['primary key'][0];
  1728. $lkey = key($schema['foreign keys'][$table_name]['columns']);
  1729. $rkey = $schema['foreign keys'][$table_name]['columns'][$lkey];
  1730. $field_name = 'sio__annotation';
  1731. $info[$field_name] = array(
  1732. 'field_name' => $field_name,
  1733. 'entity_type' => $entity_type,
  1734. 'bundle' => $bundle->name,
  1735. 'label' => 'Annotations',
  1736. 'description' => 'Annotations that are associated with this record.',
  1737. 'required' => FALSE,
  1738. 'settings' => array(
  1739. 'auto_attach' => FALSE,
  1740. 'chado_table' => $term_table,
  1741. 'chado_column' => $pkey,
  1742. 'base_table' => $table_name,
  1743. ),
  1744. 'widget' => array(
  1745. 'type' => 'sio__annotation_widget',
  1746. 'settings' => array(
  1747. 'display_label' => 1,
  1748. ),
  1749. ),
  1750. 'display' => array(
  1751. 'default' => array(
  1752. 'label' => 'hidden',
  1753. 'type' => 'sio__annotation_formatter',
  1754. 'settings' => array(),
  1755. ),
  1756. ),
  1757. );
  1758. }
  1759. // PUBLICATIONS
  1760. $pub_table = $table_name . '_pub';
  1761. if (chado_table_exists($pub_table)) {
  1762. $field_name = 'schema__publication';
  1763. $schema = chado_get_schema($pub_table);
  1764. $pkey = $schema['primary key'][0];
  1765. $info[$field_name] = array(
  1766. 'field_name' => $field_name,
  1767. 'entity_type' => $entity_type,
  1768. 'bundle' => $bundle->name,
  1769. 'label' => 'Publication',
  1770. 'description' => 'This record has been referenced or is sourced from these publications.',
  1771. 'required' => FALSE,
  1772. 'settings' => array(
  1773. 'auto_attach' => FALSE,
  1774. 'chado_table' => $pub_table,
  1775. 'chado_column' => $pkey,
  1776. 'base_table' => $table_name,
  1777. ),
  1778. 'widget' => array(
  1779. 'type' => 'schema__publication_widget',
  1780. 'settings' => array(
  1781. 'display_label' => 1,
  1782. ),
  1783. ),
  1784. 'display' => array(
  1785. 'default' => array(
  1786. 'label' => 'hidden',
  1787. 'type' => 'schema__publication_formatter',
  1788. 'settings' => array(),
  1789. ),
  1790. ),
  1791. );
  1792. }
  1793. // PUBLICATIONS (in reverse)
  1794. // We want to be able to show all of the content that a publication links
  1795. // to. The sio__references field does that.
  1796. if ($table_name == 'pub') {
  1797. $field_name = 'sio__references';
  1798. $schema = chado_get_schema($table_name);
  1799. $pkey = $schema['primary key'][0];
  1800. $info[$field_name] = array(
  1801. 'field_name' => $field_name,
  1802. 'entity_type' => $entity_type,
  1803. 'bundle' => $bundle->name,
  1804. 'label' => 'References',
  1805. 'description' => 'Records that are referred to by the publication.',
  1806. 'required' => FALSE,
  1807. 'settings' => array(
  1808. 'auto_attach' => FALSE,
  1809. 'chado_table' => $table_name,
  1810. 'chado_column' => $pkey,
  1811. 'base_table' => $table_name,
  1812. ),
  1813. 'widget' => array(
  1814. 'type' => 'sio__references_widget',
  1815. 'settings' => array(
  1816. 'display_label' => 1,
  1817. ),
  1818. ),
  1819. 'display' => array(
  1820. 'default' => array(
  1821. 'label' => 'hidden',
  1822. 'type' => 'sio__references_formatter',
  1823. 'settings' => array(),
  1824. ),
  1825. ),
  1826. );
  1827. }
  1828. // RELATIONSHIPS
  1829. // If the linker table does not exists then we don't want to add attach.
  1830. $rel_table = $table_name . '_relationship';
  1831. if (chado_table_exists($rel_table)) {
  1832. $field_name = 'sbo__relationship';
  1833. $schema = chado_get_schema($rel_table);
  1834. $pkey = $schema['primary key'][0];
  1835. $info[$field_name] = array(
  1836. 'field_name' => $field_name,
  1837. 'entity_type' => $entity_type,
  1838. 'bundle' => $bundle->name,
  1839. 'label' => 'Relationship',
  1840. 'description' => 'Other records with relationships to this record.',
  1841. 'required' => FALSE,
  1842. 'settings' => array(
  1843. 'auto_attach' => FALSE,
  1844. 'chado_table' => $rel_table,
  1845. 'chado_column' => $pkey,
  1846. 'base_table' => $table_name,
  1847. ),
  1848. 'widget' => array(
  1849. 'type' => 'sbo__relationship_widget',
  1850. 'settings' => array(
  1851. 'display_label' => 1,
  1852. ),
  1853. ),
  1854. 'display' => array(
  1855. 'default' => array(
  1856. 'label' => 'hidden',
  1857. 'type' => 'sbo__relationship_formatter',
  1858. 'settings' => array(),
  1859. ),
  1860. ),
  1861. );
  1862. }
  1863. // SYNONYMS
  1864. $syn_table = $table_name . '_synonym';
  1865. if (chado_table_exists($syn_table)) {
  1866. $field_name = 'schema__alternate_name';
  1867. $schema = chado_get_schema($syn_table);
  1868. $pkey = $schema['primary key'][0];
  1869. $info[$field_name] = array(
  1870. 'field_name' => $field_name,
  1871. 'entity_type' => $entity_type,
  1872. 'bundle' => $bundle->name,
  1873. 'label' => 'Synonyms',
  1874. 'description' => 'Alternate names, aliases or synonyms for this record.',
  1875. 'required' => FALSE,
  1876. 'settings' => array(
  1877. 'auto_attach' => FALSE,
  1878. 'chado_table' => $syn_table,
  1879. 'chado_column' => $pkey,
  1880. 'base_table' => $table_name,
  1881. ),
  1882. 'widget' => array(
  1883. 'type' => 'schema__alternate_name_widget',
  1884. 'settings' => array(
  1885. 'display_label' => 1,
  1886. ),
  1887. ),
  1888. 'display' => array(
  1889. 'default' => array(
  1890. 'label' => 'hidden',
  1891. 'type' => 'schema__alternate_name_formatter',
  1892. 'settings' => array(),
  1893. ),
  1894. ),
  1895. );
  1896. }
  1897. }
  1898. /**
  1899. * Implements hook_bundle_create_user_field().
  1900. *
  1901. * A priviledged user has the ability to add new fields to the bundle. The
  1902. * chado_linker__prop and chado_linker__cvterm fields are allowed to be
  1903. * added dynamically by the user. But, Drupal doesn't know how to deal with
  1904. * it, so this function is called for any field attached to a TripalEntity
  1905. * bundle type. Any fields whose TripalField::$module argument is set to
  1906. * 'tripal_chado' and that can be added dynamically will result in a call
  1907. * to this function.
  1908. */
  1909. function tripal_chado_bundle_create_user_field($new_field, $bundle) {
  1910. // Get the table this bundle is mapped to.
  1911. $term = tripal_load_term_entity(array('term_id' => $bundle->term_id));
  1912. $vocab = $term->vocab;
  1913. $params = array(
  1914. 'vocabulary' => $vocab->vocabulary,
  1915. 'accession' => $term->accession,
  1916. );
  1917. $chado_table = $bundle->data_table;
  1918. $chado_type_table = $bundle->type_linker_table;
  1919. $chado_type_column = $bundle->type_column;
  1920. $chado_type_id = $bundle->type_id;
  1921. $chado_type_value = $bundle->type_value;
  1922. // We allow site admins to add new chado_linker__prop fields to an entity.
  1923. // This function will allow us to properly add them. But at this point we
  1924. // don't know the controlled vocabulary term. We'll have to use the
  1925. // defaults and let the user set it using the interface.
  1926. if ($new_field['type'] == 'chado_linker__prop') {
  1927. $table_name = $chado_table . 'prop';
  1928. if (chado_table_exists($table_name)) {
  1929. $schema = chado_get_schema($table_name);
  1930. $pkey = $schema['primary key'][0];
  1931. $field_name = $new_field['field_name'];
  1932. $field_type = 'chado_linker__prop';
  1933. // First add the field.
  1934. field_create_field(array(
  1935. 'field_name' => $field_name,
  1936. 'type' => $field_type,
  1937. 'cardinality' => FIELD_CARDINALITY_UNLIMITED,
  1938. 'locked' => FALSE,
  1939. 'storage' => array(
  1940. 'type' => 'field_chado_storage',
  1941. ),
  1942. ));
  1943. // Now add the instance
  1944. field_create_instance(array(
  1945. 'field_name' => $field_name,
  1946. 'entity_type' => 'TripalEntity',
  1947. 'bundle' => $bundle->name,
  1948. 'label' => $new_field['label'],
  1949. 'description' => '',
  1950. 'required' => FALSE,
  1951. 'settings' => array(
  1952. 'auto_attach' => TRUE,
  1953. 'base_table' => $chado_table,
  1954. 'chado_table' => $table_name,
  1955. 'chado_column' => $pkey,
  1956. 'term_vocabulary' => '',
  1957. 'term_accession' => '',
  1958. 'term_name' => ''
  1959. ),
  1960. 'widget' => array(
  1961. 'type' => 'chado_linker__prop_widget',
  1962. 'settings' => array(
  1963. 'display_label' => 1,
  1964. ),
  1965. ),
  1966. 'display' => array(
  1967. 'default' => array(
  1968. 'label' => 'inline',
  1969. 'type' => 'chado_linker__prop_formatter',
  1970. 'settings' => array(),
  1971. ),
  1972. ),
  1973. ));
  1974. }
  1975. else {
  1976. drupal_set_message('Cannot add a property field to this entity. Chado does not support properties for this data type.', 'error');
  1977. }
  1978. }
  1979. // We allow site admins to add new chado_linker__cvterm fields to an entity.
  1980. // This function will allow us to properly add them. But at this point we
  1981. // don't know the controlled vocabulary term. We'll have to use the
  1982. // defaults and let the user set it using the interface.
  1983. if ($new_field['type'] == 'chado_linker__cvterm') {
  1984. $table_name = $chado_table . '_cvterm';
  1985. if (chado_table_exists($table_name)) {
  1986. $schema = chado_get_schema($table_name);
  1987. $pkey = $schema['primary key'][0];
  1988. $field_name = $new_field['field_name'];
  1989. $field_type = 'chado_linker__cvterm';
  1990. // First add the field.
  1991. field_create_field(array(
  1992. 'field_name' => $field_name,
  1993. 'type' => $field_type,
  1994. 'cardinality' => FIELD_CARDINALITY_UNLIMITED,
  1995. 'locked' => FALSE,
  1996. 'storage' => array(
  1997. 'type' => 'field_chado_storage',
  1998. ),
  1999. 'settings' => array(
  2000. 'base_table' => $chado_table,
  2001. 'chado_table' => $table_name,
  2002. 'chado_column' => $pkey,
  2003. ),
  2004. ));
  2005. // Now add the instance
  2006. field_create_instance(array(
  2007. 'field_name' => $field_name,
  2008. 'entity_type' => 'TripalEntity',
  2009. 'bundle' => $bundle->name,
  2010. 'label' => $new_field['label'],
  2011. 'description' => '',
  2012. 'required' => FALSE,
  2013. 'settings' => array(
  2014. 'auto_attach' => TRUE,
  2015. ),
  2016. 'widget' => array(
  2017. 'type' => 'chado_linker__cvterm_widget',
  2018. 'settings' => array(
  2019. 'display_label' => 1,
  2020. ),
  2021. ),
  2022. 'display' => array(
  2023. 'default' => array(
  2024. 'label' => 'above',
  2025. 'type' => 'chado_linker__cvterm_formatter',
  2026. 'settings' => array(),
  2027. ),
  2028. ),
  2029. ));
  2030. }
  2031. else {
  2032. drupal_set_message('Cannot add a property field to this entity. Chado does not support annotations for this data type.', 'error');
  2033. }
  2034. }
  2035. }
  2036. /**
  2037. * Allows for altering of a field's instance setting form.
  2038. *
  2039. * This appears to be a Drupal hook but is actually a custom function created
  2040. * by this module. It is called by the tripal_form_alter() function of this
  2041. * module.
  2042. *
  2043. * Here we put additional form elements for any field, regardless if it is
  2044. * a tripalField or not.
  2045. *
  2046. * @param $form
  2047. * The form array. Alterations to the form can be made within this array.
  2048. * @param $form_state
  2049. * The form state array.
  2050. */
  2051. function tripal_chado_field_instance_settings_form_alter(&$form, $form_state) {
  2052. global $language;
  2053. $field = $form['#field'];
  2054. $instance = $form['#instance'];
  2055. $base_table = array_key_exists('base_table', $instance['settings']) ? $instance['settings']['base_table'] : '';
  2056. $chado_table = array_key_exists('chado_table', $instance['settings']) ? $instance['settings']['chado_table'] : '';
  2057. $chado_column = array_key_exists('chado_column', $instance['settings']) ? $instance['settings']['chado_column'] : '';
  2058. if ($chado_table) {
  2059. // Construct a table for the vocabulary information.
  2060. $headers = array();
  2061. $rows = array();
  2062. $rows[] = array(
  2063. array(
  2064. 'data' => 'Base Table',
  2065. 'header' => TRUE,
  2066. 'width' => '20%',
  2067. ),
  2068. $base_table
  2069. );
  2070. $rows[] = array(
  2071. array(
  2072. 'data' => 'Record Table',
  2073. 'header' => TRUE,
  2074. 'width' => '20%',
  2075. ),
  2076. $chado_table
  2077. );
  2078. $rows[] = array(
  2079. array(
  2080. 'data' => 'ID Column',
  2081. 'header' => TRUE,
  2082. 'width' => '20%',
  2083. ),
  2084. $chado_column
  2085. );
  2086. $table = array(
  2087. 'header' => $headers,
  2088. 'rows' => $rows,
  2089. 'attributes' => array(
  2090. ),
  2091. 'sticky' => FALSE,
  2092. 'caption' => '',
  2093. 'colgroups' => array(),
  2094. 'empty' => '',
  2095. );
  2096. $form['chado_mapping'] = array(
  2097. '#type' => 'fieldset',
  2098. '#title' => 'Chado Mapping',
  2099. '#description' => t('This field maps to data in Chado to the following table:'),
  2100. );
  2101. $form['chado_mapping']['details'] = array(
  2102. '#type' => 'item',
  2103. '#markup' => theme_table($table),
  2104. );
  2105. }
  2106. }
  2107. /**
  2108. * Implements hook_form_FROM_ID_alter()
  2109. */
  2110. function tripal_chado_form_tripalbundle_form_alter(&$form, $form_state) {
  2111. global $language;
  2112. $bundle = $form['#bundle'];
  2113. $term = entity_load('TripalTerm', array('id' => $bundle->term_id));
  2114. $term = reset($term);
  2115. $vocab = $term->vocab;
  2116. $params = array(
  2117. 'vocabulary' => $vocab->vocabulary,
  2118. 'accession' => $term->accession,
  2119. );
  2120. $chado_table = $bundle->data_table;
  2121. $chado_column = $bundle->type_column;
  2122. $chado_type_table = $bundle->type_linker_table;
  2123. $chado_type_id = $bundle->type_id;
  2124. $chado_type_value = $bundle->type_value;
  2125. // Construct a table for the vocabulary information.
  2126. $headers = array();
  2127. $rows = array();
  2128. $rows[] = array(
  2129. array(
  2130. 'data' => 'Chado Table',
  2131. 'header' => TRUE,
  2132. 'width' => '20%',
  2133. ),
  2134. $chado_table
  2135. );
  2136. if ($chado_column) {
  2137. $rows[] = array(
  2138. array(
  2139. 'data' => 'Type Column',
  2140. 'header' => TRUE,
  2141. 'width' => '20%',
  2142. ),
  2143. $chado_column
  2144. );
  2145. }
  2146. if ($chado_type_table) {
  2147. $rows[] = array(
  2148. array(
  2149. 'data' => 'Association Table',
  2150. 'header' => TRUE,
  2151. 'width' => '20%',
  2152. ),
  2153. $chado_type_table
  2154. );
  2155. }
  2156. if ($chado_type_table and $chado_type_id) {
  2157. $rows[] = array(
  2158. array(
  2159. 'data' => 'CVTerm Table ID',
  2160. 'header' => TRUE,
  2161. 'width' => '20%',
  2162. ),
  2163. $chado_type_id
  2164. );
  2165. }
  2166. if ($chado_type_value) {
  2167. $rows[] = array(
  2168. array(
  2169. 'data' => 'Property Value',
  2170. 'header' => TRUE,
  2171. 'width' => '20%',
  2172. ),
  2173. $chado_type_value
  2174. );
  2175. }
  2176. $table = array(
  2177. 'header' => $headers,
  2178. 'rows' => $rows,
  2179. 'attributes' => array(
  2180. ),
  2181. 'sticky' => FALSE,
  2182. 'caption' => '',
  2183. 'colgroups' => array(),
  2184. 'empty' => '',
  2185. );
  2186. $form['chado_mapping'] = array(
  2187. '#type' => 'item',
  2188. '#title' => 'Chado Mapping',
  2189. '#markup' => theme_table($table),
  2190. '#description' => t('This content type maps to the table in Chado
  2191. listed above. Chado allows multiple data types to be housed
  2192. in a single table. Therefore, the column that is used to
  2193. differentiate between data types is also listed above.'),
  2194. '#weight' => 0,
  2195. );
  2196. }
  2197. /**
  2198. * Implements hook_field_views_data_alter();
  2199. */
  2200. function tripal_chado_field_views_data_alter(&$result, $field, $module) {
  2201. // This module creates the data__image field for managing images on
  2202. // bio_data content types. But we want it to render correctly
  2203. // so we need to set some handlers.
  2204. if ($field['field_name'] == 'data__image') {
  2205. foreach ($result as $key => $fields) {
  2206. // It's not clear how to identify our bundle types, but they do have
  2207. // a double underscore in their name to separate the vocabulary from
  2208. // the accession, so we'll use that to find them.
  2209. if (preg_match('/__/', $key)) {
  2210. $result[$key]['data__image']['field']['handler'] = 'tripal_views_handler_field_image';
  2211. }
  2212. }
  2213. }
  2214. }