tripal_chado.fields.inc 100 KB

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