tripal_chado.fields.inc 101 KB

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