tripal_chado.fields.inc 93 KB

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