tripal_chado.fields.inc 101 KB

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