tripal_chado.fields.inc 99 KB

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