tripal_chado.fields.inc 105 KB

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