tripal_chado.fields.inc 100 KB

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