24 chado_create_custom_table(
'genotype_call', array(
27 'genotype_call_id' => array(
34 'variant_id' => array(
46 'genotype_id' => array(
52 'project_id' => array(
69 'foreign keys' => array(
71 'table' =>
'genotype',
73 'genotype_id' =>
'genotype_id',
79 'variant_id' =>
'feature_id',
85 'marker_id' =>
'feature_id',
91 'project_id' =>
'project_id',
97 'stock_id' =>
'stock_id',
101 'primary key' => array(
104 'referring_tables' => array(
110 ), TRUE, NULL, FALSE);
114 chado_create_custom_table(
'stock_phenotype', array(
117 'phenotype_id' => array(
130 'unique keys' => array(
131 'stock_phenotype_c1' => array(
136 'foreign keys' => array(
137 'phenotype' => array(
138 'table' =>
'phenotype',
140 'phenotype_id' =>
'phenotype_id',
146 'stock_id' =>
'stock_id',
150 'primary key' => array(
154 'referring_tables' => array(
159 'stock_phenotype_idx1' => array(
162 'stock_phenotype_idx2' => array(
166 ), TRUE, NULL, FALSE);
168 chado_create_custom_table(
'project_organism', array(
171 'project_organism_id' => array(
178 'organism_id' => array(
184 'project_id' => array(
191 'foreign keys' => array(
193 'table' =>
'organism',
195 'organism_id' =>
'organism_id',
199 'table' =>
'project',
201 'project_id' =>
'project_id',
205 'unique keys' => array(
206 'project_organism_c1' => array(
211 'primary key' => array(
212 'project_organism_id',
214 ), TRUE, NULL, FALSE);
216 chado_create_custom_table(
'pub_organism', array(
219 'pub_organism_id' => array(
226 'organism_id' => array(
239 'foreign keys' => array(
241 'table' =>
'organism',
243 'organism_id' =>
'organism_id',
249 'pub_id' =>
'pub_id',
253 'unique keys' => array(
254 'pub_organism_c1' => array(
259 'primary key' => array(
262 ), TRUE, NULL, FALSE);
290 db_delete(
'public.variable')
291 ->condition(
'name', db_like(
'tpps_incomplete_') .
'%',
'LIKE')
295 db_delete(
'public.variable')
296 ->condition(
'name', db_like(
'tpps_complete_') .
'%',
'LIKE')
299 $tpps_usage = db_select(
'public.file_usage',
'f')
301 ->condition(
'module',
'tpps')
304 foreach ($tpps_usage as $row) {
305 file_usage_delete(file_load($row->fid), $row->module, $row->type, $row->id, $row->count);
318 if (!db_table_exists(
'tpps_submission')) {
319 $schema[
'tpps_submission'] = array(
320 'description' =>
'Contains TPPS Submissions',
322 'tpps_submission_id' => array(
323 'description' =>
'The id of the TPPS submission.',
330 'description' =>
'user id of the user who created the submission.',
336 'description' =>
'Status of the submission - Incomplete, Pending Approval, Submission Job Running or Approved.',
341 'accession' => array(
342 'description' =>
'The TGDR### accession number of the submission',
347 'dbxref_id' => array(
348 'description' =>
'The dbxref_id from chado.dbxref.',
353 'submission_state' => array(
354 'description' =>
'The form_state of the submission.',
360 'foreign keys' => array(
367 'dbxref_id' => array(
368 'table' =>
'chado.dbxref',
370 'dbxref_id' =>
'dbxref_id',
374 'primary key' => array(
375 'tpps_submission_id',
380 if (!db_table_exists(
'chado.genotype_call')) {
381 $schema[
'chado.genotype_call'] = array(
384 'genotype_call_id' => array(
391 'variant_id' => array(
397 'marker_id' => array(
403 'genotype_id' => array(
409 'project_id' => array(
421 'meta_data' => array(
429 'foreign keys' => array(
430 'genotype_id' => array(
431 'table' =>
'chado.genotype',
433 'genotype_id' =>
'genotype_id',
436 'variant_id' => array(
437 'table' =>
'chado.feature',
439 'variant_id' =>
'feature_id',
442 'marker_id' => array(
443 'table' =>
'chado.feature',
445 'marker_id' =>
'feature_id',
448 'project_id' => array(
449 'table' =>
'chado.project',
451 'project_id' =>
'project_id',
455 'table' =>
'chado.stock',
457 'stock_id' =>
'stock_id',
461 'primary key' => array(
467 $schema[
'tpps_submission_dbxref'] = array(
470 'tpps_submission_dbxref_id' => array(
477 'tpps_submission_id' => array(
483 'dbxref_id' => array(
490 'foreign keys' => array(
491 'tpps_submission_id' => array(
492 'table' =>
'tpps_submission',
494 'tpps_submission_id' =>
'tpps_submission_id',
497 'dbxref_id' => array(
498 'table' =>
'chado.dbxref',
500 'dbxref_id' =>
'dbxref_id',
504 'unique keys' => array(
505 'tpps_submission_dbxref_c1' => array(
506 'tpps_submission_id',
510 'primary key' => array(
511 'tpps_submission_dbxref_id',
515 $schema[
'tpps_project_file_managed'] = array(
518 'tpps_project_file_managed_id' => array(
525 'project_id' => array(
538 'foreign keys' => array(
539 'project_id' => array(
540 'table' =>
'chado.project',
542 'project_id' =>
'project_id',
546 'table' =>
'file_managed',
552 'unique keys' => array(
553 'tpps_project_file_managed_c1' => array(
558 'primary key' => array(
559 'tpps_project_file_managed_id',
563 $schema[
'tpps_tag'] = array(
566 'tpps_tag_id' => array(
592 'unique keys' => array(
593 'tpps_tag_c1' => array(
597 'primary key' => array(
602 $schema[
'tpps_submission_tag'] = array(
605 'tpps_submission_tag_id' => array(
612 'tpps_submission_id' => array(
618 'tpps_tag_id' => array(
625 'foreign keys' => array(
626 'tpps_submission_id' => array(
627 'table' =>
'tpps_submission',
629 'tpps_submission_id' =>
'tpps_submission_id',
632 'tpps_tag_id' => array(
633 'table' =>
'tpps_tag',
635 'tpps_tag_id' =>
'tpps_tag_id',
639 'unique keys' => array(
640 'tpps_submission_tag_c1' => array(
641 'tpps_submission_id',
645 'primary key' => array(
646 'tpps_submission_tag_id',
660 module_load_include(
'inc',
'tripal_chado',
'includes/tripal_chado.cv');
661 $transaction = db_transaction();
663 $file_path = DRUPAL_ROOT .
'/' . drupal_get_path(
'module',
'tpps') .
'/includes/lib/ppeo.obo';
666 $obo_id = db_insert(
'tripal_cv_obo')
669 'path' => $file_path,
672 tripal_cv_load_obo($obo_id);
674 catch (\Exception $e) {
675 $transaction->rollback();
685 $terms = $terms_function();
687 $transaction = db_transaction();
690 foreach ($terms as $key => $info) {
695 if ($key ==
'new_terms' and is_array($info)) {
696 foreach ($info as $term_info) {
703 if ($result ===
'local') {
709 catch (\Exception $e) {
710 $transaction->rollback();
719 $results = db_query(
"SELECT contype " 720 .
"FROM pg_catalog.pg_constraint con JOIN pg_catalog.pg_class rel ON rel.oid = con.conrelid " 721 .
"WHERE rel.relname = 'genotype_call' AND contype like 'f';");
722 if (!$results->rowCount()) {
723 db_query(
'ALTER TABLE chado.genotype_call ADD CONSTRAINT genotype_call_genotype_id_fkey FOREIGN KEY (genotype_id) REFERENCES chado.genotype(genotype_id) ON DELETE CASCADE;');
724 db_query(
'ALTER TABLE chado.genotype_call ADD CONSTRAINT genotype_call_marker_id_fkey FOREIGN KEY (marker_id) REFERENCES chado.feature(feature_id) ON DELETE CASCADE;');
725 db_query(
'ALTER TABLE chado.genotype_call ADD CONSTRAINT genotype_call_variant_id_fkey FOREIGN KEY (variant_id) REFERENCES chado.feature(feature_id) ON DELETE CASCADE;');
726 db_query(
'ALTER TABLE chado.genotype_call ADD CONSTRAINT genotype_call_project_id_fkey FOREIGN KEY (project_id) REFERENCES chado.project(project_id) ON DELETE CASCADE;');
727 db_query(
'ALTER TABLE chado.genotype_call ADD CONSTRAINT genotype_call_stock_id_fkey FOREIGN KEY (stock_id) REFERENCES chado.stock(stock_id) ON DELETE CASCADE;');
731 ->condition(
'column_name',
'meta_data')
732 ->condition(
'table_name',
'genotype_call');
733 $meta_type = db_select(
'information_schema.columns',
'c')
734 ->fields(
'c', array(
'data_type'))
736 ->execute()->fetchObject()->data_type;
738 if ($meta_type !=
'json') {
739 db_query(
'ALTER TABLE chado.genotype_call ALTER COLUMN meta_data TYPE json USING meta_data::json;');
747 $results = db_query(
"SELECT contype " 748 .
"FROM pg_catalog.pg_constraint con JOIN pg_catalog.pg_class rel ON rel.oid = con.conrelid " 749 .
"WHERE rel.relname = 'tpps_submission' AND contype like 'f';");
750 if (!$results->rowCount()) {
752 db_query(
'ALTER TABLE tpps_submission ADD CONSTRAINT tpps_submission_uid_fkey FOREIGN KEY (uid) REFERENCES users(uid) ON DELETE CASCADE;');
753 db_query(
'ALTER TABLE tpps_submission ADD CONSTRAINT tpps_submission_dbxref_id_fkey FOREIGN KEY (dbxref_id) REFERENCES chado.dbxref(dbxref_id) ON DELETE CASCADE;');
761 $results = db_query(
"SELECT contype " 762 .
"FROM pg_catalog.pg_constraint con JOIN pg_catalog.pg_class rel ON rel.oid = con.conrelid " 763 .
"WHERE rel.relname = 'tpps_submission_dbxref' AND contype like 'f';");
764 if (!$results->rowCount()) {
765 db_query(
'ALTER TABLE tpps_submission_dbxref ADD CONSTRAINT tpps_submission_dbxref_tpps_submission_id_fkey FOREIGN KEY (tpps_submission_id) REFERENCES tpps_submission(tpps_submission_id) ON DELETE CASCADE;');
766 db_query(
'ALTER TABLE tpps_submission_dbxref ADD CONSTRAINT tpps_submission_dbxref_dbxref_id_fkey FOREIGN KEY (dbxref_id) REFERENCES chado.dbxref(dbxref_id) ON DELETE CASCADE;');
774 $results = db_query(
"SELECT contype " 775 .
"FROM pg_catalog.pg_constraint con JOIN pg_catalog.pg_class rel ON rel.oid = con.conrelid " 776 .
"WHERE rel.relname = 'tpps_project_file_managed' AND contype like 'f';");
777 if (!$results->rowCount()) {
778 db_query(
'ALTER TABLE tpps_project_file_managed ADD CONSTRAINT tpps_project_file_managed_fid_fkey FOREIGN KEY (fid) REFERENCES file_managed(fid) ON DELETE CASCADE;');
779 db_query(
'ALTER TABLE tpps_project_file_managed ADD CONSTRAINT tpps_project_file_managed_project_id_fkey FOREIGN KEY (project_id) REFERENCES chado.project(project_id) ON DELETE CASCADE');
787 $results = db_query(
"SELECT contype " 788 .
"FROM pg_catalog.pg_constraint con JOIN pg_catalog.pg_class rel ON rel.oid = con.conrelid " 789 .
"WHERE rel.relname = 'tpps_submission_tag' AND contype like 'f';");
790 if (!$results->rowCount()) {
791 db_query(
'ALTER TABLE tpps_submission_tag ADD CONSTRAINT tpps_submission_tag_tpps_tag_id_fkey FOREIGN KEY (tpps_tag_id) REFERENCES tpps_tag(tpps_tag_id) ON DELETE CASCADE;');
792 db_query(
'ALTER TABLE tpps_submission_tag ADD CONSTRAINT tpps_submission_tag_tpps_submission_id_fkey FOREIGN KEY (tpps_submission_id) REFERENCES tpps_submission(tpps_submission_id) ON DELETE CASCADE;');
800 $local_db = chado_get_db(array(
'name' =>
'local'));
802 $query = db_select(
'pg_class',
'p')
804 ->condition(
'relname',
'plusgeno_view')
806 if (!($result = $query->fetchObject())) {
808 db_query(
'create materialized view chado.plusgeno_view as SELECT DISTINCT p.project_id, 812 count(o.stock_id) OVER (PARTITION BY p.project_id) AS tree_count, 813 sum(phen.count) OVER (PARTITION BY p.project_id) AS phen_count, 814 unique_phen.phenotypes_assessed, 816 FROM chado.project_dbxref p 817 JOIN chado.dbxref d ON p.dbxref_id = d.dbxref_id 818 JOIN ( SELECT pp.project_id, 820 FROM chado.project_pub pp 821 JOIN chado.pub ON pp.pub_id = pub.pub_id) ppub ON p.project_id = ppub.project_id 822 JOIN ( SELECT DISTINCT ps.project_id, 823 (org.genus::text || \' \'::text) || org.species::text AS species, 825 FROM chado.project_stock ps 826 JOIN chado.stock ON ps.stock_id = stock.stock_id 827 JOIN chado.organism org ON stock.organism_id = org.organism_id) o ON p.project_id = o.project_id 828 LEFT JOIN ( SELECT stock_phenotype.stock_id, 829 count(stock_phenotype.phenotype_id) OVER (PARTITION BY stock_phenotype.stock_id) AS count 830 FROM chado.stock_phenotype) phen ON o.stock_id = phen.stock_id 831 LEFT JOIN ( SELECT DISTINCT pc.project_id, 832 count(pc.name) OVER (PARTITION BY pc.project_id) AS phenotypes_assessed 833 FROM ( SELECT DISTINCT ps.project_id, 835 FROM chado.phenotype ph 836 JOIN chado.stock_phenotype sp ON ph.phenotype_id = sp.phenotype_id 837 JOIN chado.stock s ON sp.stock_id = s.stock_id 838 JOIN chado.project_stock ps ON s.stock_id = ps.stock_id) pc) unique_phen ON p.project_id = unique_phen.project_id 839 LEFT JOIN ( SELECT DISTINCT genotype_call.project_id, 840 count(genotype_call.genotype_call_id) OVER (PARTITION BY genotype_call.project_id) AS gen_count 841 FROM chado.genotype_call) g ON p.project_id = g.project_id 842 WHERE d.db_id = ' . $local_db->db_id .
';');
843 variable_set(
'tpps_local_db', $local_db);
847 $definition = db_select(
'pg_matviews',
'p')
848 ->fields(
'p', array(
'definition'))
849 ->condition(
'matviewname',
'plusgeno_view')
851 ->fetchObject()->definition;
852 preg_match(
'/d\.db_id ?= ?(\d+)\);/', $definition, $matches);
853 variable_set(
'tpps_local_db', chado_get_db(array(
'db_id' => (
int) $matches[1])));
861 $query = db_select(
'pg_class',
'p')
863 ->condition(
'relname',
'tpps_search_genotype_name')
865 if (!($result = $query->fetchObject())) {
866 db_query(
'create materialized view chado.tpps_search_genotype_name as 867 select distinct gc.project_id, g.name 868 from chado.genotype_call gc 869 inner join chado.genotype g 870 on (g.genotype_id = gc.genotype_id);');
873 $query = db_select(
'pg_class',
'p')
875 ->condition(
'relname',
'tpps_search_genotype_marker')
877 if (!($result = $query->fetchObject())) {
878 db_query(
'create materialized view chado.tpps_search_genotype_marker as 879 select distinct gc.project_id, cvt.name 880 from chado.genotype_call gc 881 inner join chado.genotype g 882 on (g.genotype_id = gc.genotype_id) 883 inner join chado.cvterm cvt 884 on (cvt.cvterm_id = g.type_id);');
892 $admin_query = db_select(
'role',
'r')
893 ->fields(
'r', array(
'rid'))
894 ->condition(
'name',
'administrator')
897 $auth_query = db_select(
'role',
'r')
898 ->fields(
'r', array(
'rid'))
899 ->condition(
'name',
'authenticated user')
902 $anon_query = db_select(
'role',
'r')
903 ->fields(
'r', array(
'rid'))
904 ->condition(
'name',
'anonymous user')
907 if (($admin = $admin_query->fetchObject()) and ($auth = $auth_query->fetchObject()) and ($anon = $anon_query->fetchObject())) {
909 foreach ($perms as $name => $info) {
910 db_insert(
'role_permission')
912 'rid' => $admin->rid,
913 'permission' => $name,
919 db_insert(
'role_permission')
922 'permission' =>
'access tpps form',
927 db_insert(
'role_permission')
930 'permission' =>
'user tpps submissions',
935 db_insert(
'role_permission')
938 'permission' =>
'tpps delete submission',
943 db_insert(
'role_permission')
946 'permission' =>
'view own tpps submission',
951 db_insert(
'role_permission')
954 'permission' =>
'access tpps details',
959 db_insert(
'role_permission')
962 'permission' =>
'access tpps details',
967 drupal_set_message(t(
'Attention: @t default permissions have been set. Go to @p to manage and customize @t permissions.', array(
969 '@p' =>
'admin/people/permissions',
980 'TPPSc' =>
'lightgray',
981 'Genotype' =>
'lightgreen',
982 'Phenotype' =>
'lightblue',
983 'Environment' =>
'lightsalmon',
984 'No Location Information' =>
'pink',
985 'Approximate Coordinates' =>
'gray',
988 foreach ($tags as $name => $color) {
989 db_insert(
'tpps_tag')
1003 $transaction = db_transaction();
1005 if (empty(tripal_load_bundle_entity(array(
'label' =>
'Genotype')))) {
1009 if (empty(tripal_load_bundle_entity(array(
'label' =>
'Stock')))) {
1013 catch (Exception $e) {
1014 watchdog_exception(
'tpps', $e);
1015 $transaction->rollback();
1025 $local_db = variable_get(
'tpps_local_db');
1026 $local_cv = chado_get_cv(array(
'name' =>
'local'));
1028 'include_fk' => array(
1034 'vocabulary' => $genotype_term->dbxref_id->db_id->name,
1035 'accession' => $genotype_term->dbxref_id->accession,
1036 'term_name' => $genotype_term->name,
1037 'storage_args' => array(
1038 'data_table' =>
'genotype',
1042 tripal_create_bundle($args);
1043 $bundle = tripal_load_bundle_entity(array(
'label' =>
'Genotype'));
1045 $prop_terms = array(
1047 'id' =>
'sep:00007',
1050 'field' =>
'sep__format',
1051 'label' =>
'Genotype Format',
1053 'def' =>
'A format is a quality that is a specificiation or arrangement of a specified form. The structure, layout, or the digital manifestation of an entity. [ PSI:GEL ]',
1056 'id' =>
'SO:0001686',
1057 'name' =>
'quality_value',
1058 'cvname' =>
'sequence',
1059 'field' =>
'so__quality_value',
1060 'label' =>
'Genotype Quality Score',
1062 'def' =>
'An experimental feature attribute that defines the quality of the feature in a quantitative way, such as a phred quality score. [ http://www.sequenceontology.org/browser/current_svn/term/SO:ke ]',
1065 'id' =>
'operation:3187',
1066 'name' =>
'Sequence contamination filtering',
1067 'cvname' =>
'operation',
1068 'field' =>
'edam__filter',
1069 'label' =>
'Genotype Contamination Filter',
1070 'dbname' =>
'EDAM_operation',
1071 'def' =>
'Identify and filter a (typically large) sequence data set to remove sequences from contaminants in the sample that was sequenced.',
1074 'id' =>
'SO:0002119',
1075 'name' =>
'allelic_frequency',
1076 'cvname' =>
'sequence',
1077 'field' =>
'so__allelic_frequency',
1078 'label' =>
'Genotype Allelic Frequency',
1080 'def' =>
'A physical quality which inheres to the allele by virtue of the number instances of the allele within a population. This is the relative frequency of the allele at a given locus in a population. [ http://www.sequenceontology.org/browser/current_svn/term/SO:ke ]',
1083 'id' =>
'NCIT:C155320',
1084 'name' =>
'Read Depth',
1086 'field' =>
'ncit__read_depth',
1087 'label' =>
'Genotype Read Depth',
1089 'def' =>
'The number of times a particular locus (site, nucleotide, amplicon, region) was sequenced. [ NCI ]',
1092 'id' =>
"{$local_db->name}:number_samples",
1093 'name' =>
'number_samples',
1094 'cvname' => $local_cv->name,
1095 'field' =>
"{$local_cv->name}__number_samples",
1096 'label' =>
'Genotype Number of Samples',
1097 'dbname' => $local_db->name,
1098 'def' =>
'Number of samples',
1102 foreach ($prop_terms as $prop_term) {
1103 $term = chado_insert_cvterm(array(
1104 'id' => $prop_term[
'id'],
1105 'name' => $prop_term[
'name'],
1106 'definition' => $prop_term[
'def'],
1107 'db_name' => $prop_term[
'dbname'],
1108 'cv_name' => $prop_term[
'cvname'],
1111 if ($prop_term[
'cvname'] != $term->cvname) {
1112 db_update(
'chado.cvterm')
1114 'cv_id' => chado_get_cv(array(
'name' => $prop_term[
'cvname']))->cv_id,
1116 ->condition(
'cvterm_id', $term->cvterm_id)
1119 $term->cvname = $prop_term[
'cvname'];
1121 $info = field_info_field($prop_term[
'field']);
1122 if (empty($info[
'bundles'][
'TripalEntity'])) {
1123 field_create_field(array(
1124 'field_name' => $prop_term[
'field'],
1125 'type' =>
'chado_linker__prop',
1126 'settings' => array(
1127 'storage' =>
'field_chado_storage',
1130 'type' =>
'field_chado_storage',
1131 'module' =>
'tripal_chado',
1136 elseif (array_search($bundle->name, $info[
'bundles'][
'TripalEntity']) !== FALSE) {
1140 field_create_instance(array(
1141 'field_name' => $prop_term[
'field'],
1142 'entity_type' =>
'TripalEntity',
1143 'label' => $prop_term[
'label'],
1144 'bundle' => $bundle->name,
1145 'required' => FALSE,
1146 'settings' => array(
1147 'user_register_form' => 0,
1148 'term_vocabulary' => $term->dbname,
1149 'term_name' => $term->name,
1150 'term_accession' => $term->accession,
1151 'base_table' =>
'genotype',
1152 'chado_table' =>
'genotypeprop',
1153 'chado_column' =>
'genotype_id',
1166 'include_fk' => array(
1171 chado_associate_semweb_term(
'stock',
'stock_id', $stock_term);
1172 chado_populate_mview(chado_get_mview_id(
'db2cv_mview'));
1175 'vocabulary' => $stock_term->dbxref_id->db_id->name,
1176 'accession' => $stock_term->dbxref_id->accession,
1177 'term_name' => $stock_term->name,
1178 'storage_args' => array(
1179 'data_table' =>
'stock',
1182 tripal_create_bundle($args);
1184 db_update(
'tripal_bundle')
1188 ->condition(
'label',
'Whole Plant')
1190 $bundle = tripal_load_bundle_entity(array(
'label' =>
'Stock'));
1191 tripal_save_title_format($bundle,
'[data__identifier]');
1194 'include_fk' => array(
1199 $info = field_info_field(
'sbo__phenotype');
1200 if (empty($info[
'bundles'][
'TripalEntity'])) {
1201 field_create_field(array(
1202 'field_name' =>
'sbo__phenotype',
1203 'type' =>
'sbo__phenotype',
1204 'settings' => array(
1205 'storage' =>
'field_chado_storage',
1208 'type' =>
'field_chado_storage',
1209 'module' =>
'tripal_chado',
1215 field_create_instance(array(
1216 'field_name' =>
'sbo__phenotype',
1217 'entity_type' =>
'TripalEntity',
1218 'label' =>
'Phenotype',
1219 'bundle' => $bundle->name,
1220 'required' => FALSE,
1221 'settings' => array(
1222 'user_register_form' => 0,
1223 'term_vocabulary' => $phenotype_term->dbxref_id->db_id->name,
1224 'term_name' => $phenotype_term->name,
1225 'term_accession' => $phenotype_term->dbxref_id->accession,
1226 'base_table' =>
'stock',
1227 'chado_table' =>
'stock_phenotype',
1228 'chado_column' =>
'phenotype_id',
1235 'include_fk' => array(
1240 $info = field_info_field(
'so__genotype');
1241 if (empty($info[
'bundles'][
'TripalEntity'])) {
1242 field_create_field(array(
1243 'field_name' =>
'so__genotype',
1244 'type' =>
'so__genotype',
1245 'settings' => array(
1246 'storage' =>
'field_chado_storage',
1249 'type' =>
'field_chado_storage',
1250 'module' =>
'tripal_chado',
1256 field_create_instance(array(
1257 'field_name' =>
'so__genotype',
1258 'entity_type' =>
'TripalEntity',
1259 'label' =>
'Genotype',
1260 'bundle' => $bundle->name,
1261 'required' => FALSE,
1262 'settings' => array(
1263 'user_register_form' => 0,
1264 'term_vocabulary' => $genotype_term->dbxref_id->db_id->name,
1265 'term_name' => $genotype_term->name,
1266 'term_accession' => $genotype_term->dbxref_id->accession,
1267 'base_table' =>
'stock',
1268 'chado_table' =>
'stock_genotype',
1269 'chado_column' =>
'genotype_id',
1280 chado_insert_db(array(
1282 'url' =>
'https://datadryad.org/',
1283 'urlprefix' =>
'https://datadryad.org/resource/doi:{doi}',
1294 $transaction = db_transaction();
1297 'status' =>
'Approved',
1300 foreach ($submissions as $state) {
1301 if (!empty($state[
'saved_values'][
TPPS_PAGE_3][
'tree-accession'][
'file']) and empty($state[
'saved_values'][TPPS_PAGE_3][
'tree-accession'][
'check'])) {
1302 $state[
'saved_values'][
TPPS_PAGE_3][
'tree-accession'][
'species-1'] = $state[
'saved_values'][
TPPS_PAGE_3][
'tree-accession'];
1303 unset($state[
'saved_values'][TPPS_PAGE_3][
'tree-accession'][
'species-1'][
'check']);
1307 catch (Exception $e) {
1308 if ($e->getMessage() ==
'Unrecognized file type') {
1317 catch (Exception $e) {
1318 $transaction->rollback();
1329 $transaction = db_transaction();
1332 'status' =>
'Approved',
1335 foreach ($submissions as $state) {
1336 $firstpage = $state[
'saved_values'][
TPPS_PAGE_1] ?? NULL;
1337 $seconds = $firstpage[
'publication'][
'secondaryAuthors'] ?? NULL;
1338 $state[
'title'] = $firstpage[
'publication'][
'title'] ??
"";
1339 $state[
'abstract'] = $firstpage[
'publication'][
'abstract'] ??
"";
1340 $state[
'pyear'] = $firstpage[
'publication'][
'year'] ??
"";
1341 $state[
'journal'] = $firstpage[
'publication'][
'journal'] ??
"";
1342 $state[
'authors'] = !empty($firstpage[
'primaryAuthor']) ? array($firstpage[
'primaryAuthor']) : array();
1343 $state[
'files'] = array();
1344 if (!empty($seconds[
'number'])) {
1345 for ($i = 1; $i <= $seconds[
'number']; $i++) {
1346 $state[
'authors'][] = $seconds[$i];
1350 if (empty($state[
'tree_info'])) {
1351 $state[
'tree_info'] = array();
1352 $query = db_select(
'chado.stock',
's');
1353 $query->join(
'chado.stockprop',
'lat',
'lat.stock_id = s.stock_id');
1354 $query->join(
'chado.stockprop',
'lng',
'lng.stock_id = s.stock_id');
1355 $query->fields(
's', array(
'stock_id',
'uniquename',
'organism_id'));
1356 $query->fields(
'lat', array(
'value'));
1357 $query->fields(
'lng', array(
'value'));
1358 $query->condition(
's.uniquename', db_like($state[
'accession']) .
'%',
'LIKE');
1359 $query->condition(
'lat.type_id',
tpps_load_cvterm(
'gps_latitude', array(),
'1_1')->cvterm_id);
1360 $query->condition(
'lng.type_id',
tpps_load_cvterm(
'gps_longitude', array(),
'1_1')->cvterm_id);
1362 $query = $query->execute();
1364 while (($tree = $query->fetchObject())) {
1365 preg_match(
'/^TGDR[0-9]+-(.*)$/', $tree->uniquename, $matches);
1366 $state[
'tree_info'][$matches[1]] = array(
1367 'stock_id' => $tree->stock_id,
1368 'lat' => $tree->value,
1369 'lng' => $tree->lng_value,
1370 'organism_id' => $tree->organism_id,
1375 $org_num = $state[
'stats'][
'species_count'] ?? 0;
1376 for ($i = 1; $i <= $org_num; $i++) {
1377 $state[
'files'][] = $state[
'saved_values'][
TPPS_PAGE_3][
'tree-accession'][
"species-$i"][
'file'] ?? NULL;
1378 $state[
'files'][] = $state[
'saved_values'][
TPPS_PAGE_4][
"organism-$i"][
'phenotype'][
'iso'] ?? NULL;
1379 $state[
'files'][] = $state[
'saved_values'][
TPPS_PAGE_4][
"organism-$i"][
'phenotype'][
'file'] ?? NULL;
1380 $state[
'files'][] = $state[
'saved_values'][
TPPS_PAGE_4][
"organism-$i"][
'phenotype'][
'metadata'] ?? NULL;
1381 $state[
'files'][] = $state[
'saved_values'][
TPPS_PAGE_4][
"organism-$i"][
'genotype'][
'files'][
'snps-assay'] ?? NULL;
1382 $state[
'files'][] = $state[
'saved_values'][
TPPS_PAGE_4][
"organism-$i"][
'genotype'][
'files'][
'assay-design'] ?? NULL;
1383 $state[
'files'][] = $state[
'saved_values'][
TPPS_PAGE_4][
"organism-$i"][
'genotype'][
'files'][
'ssrs'] ?? NULL;
1384 $state[
'files'][] = $state[
'saved_values'][
TPPS_PAGE_4][
"organism-$i"][
'genotype'][
'files'][
'other'] ?? NULL;
1385 $state[
'files'][] = $state[
'saved_values'][
TPPS_PAGE_4][
"organism-$i"][
'genotype'][
'files'][
'vcf'] ?? NULL;
1386 $state[
'files'][] = $state[
'saved_values'][
TPPS_PAGE_4][
"organism-$i"][
'genotype'][
'tripal_fasta'][
'file'][
'file_upload'] ?? NULL;
1389 foreach ($state[
'files'] as $key => $val) {
1391 unset($state[
'files'][$key]);
1398 catch (Exception $e) {
1399 $transaction->rollback();
1419 $transaction = db_transaction();
1422 'status' =>
'Approved',
1424 foreach ($submissions as $state) {
1425 if (!empty($state[
'saved_values'][
TPPS_PAGE_1][
'doi']) and !empty($state[
'ids'][
'project_id'])) {
1426 $dryad_db = chado_get_db(array(
'name' =>
'dryad'));
1427 $dryad_dbxref = chado_insert_dbxref(array(
1428 'db_id' => $dryad_db->db_id,
1429 'accession' => $state[
'saved_values'][TPPS_PAGE_1][
'doi'],
1432 'project_id' => $state[
'ids'][
'project_id'],
1433 'dbxref_id' => $dryad_dbxref,
1438 catch (Exception $e) {
1439 $transaction->rollback();
1450 $transaction = db_transaction();
1453 'status' =>
'Approved',
1455 foreach ($submissions as $state) {
1456 if (!empty($state[
'ids'][
'organism_ids']) and !empty($state[
'ids'][
'project_id'])) {
1457 $proj_id = $state[
'ids'][
'project_id'];
1458 $pub_id = db_select(
'chado.project_pub',
'p')
1459 ->fields(
'p', array(
'pub_id'))
1460 ->condition(
'project_id', $proj_id)
1462 ->execute()->fetchObject()->pub_id;
1463 foreach ($state[
'ids'][
'organism_ids'] as $org_id) {
1465 'organism_id' => $org_id,
1466 'pub_id' => $pub_id,
1472 catch (Exception $e) {
1473 $transaction->rollback();
1494 foreach ($submissions as $state) {
1495 if (empty($state[
'updated'])) {
1507 $cv = chado_get_cv(array(
'name' =>
'PPEO'));
1519 variable_set(
'tpps_cvterms_version',
'1_1');
1530 'status' =>
'Approved',
1534 ->condition(
'type_id',
tpps_load_cvterm(
'file_path', array(),
'1_1')->cvterm_id);
1535 foreach ($submissions as $state) {
1536 $files = $state[
'files'] ?? NULL;
1537 if (!empty($files) and !empty($state[
'file_info'])) {
1538 $transaction = db_transaction();
1541 $num_files = db_delete(
'chado.projectprop')
1542 ->condition(
'project_id', $state[
'ids'][
'project_id'])
1545 $state[
'file_rank'] = 0;
1546 $state_files = count($files);
1547 $state_files += count(($state[
'revised_files'] ?? array()));
1548 if ($num_files != $state_files) {
1549 throw new \Exception(
"Improper number of files in db vs files in state: $num_files in db and $state_files in state");
1551 if (!empty($state[
'revised_files'])) {
1552 foreach ($state[
'revised_files'] as $fid) {
1556 foreach ($files as $fid) {
1558 $file = file_load($fid);
1560 'project_id' => $state[
'ids'][
'project_id'],
1562 'value' => file_create_url($file->uri),
1563 'rank' => $state[
'file_rank']++,
1569 catch (\Exception $e) {
1570 drupal_set_message(
"skipping accession {$state['accession']}: " . $e->getMessage());
1571 $transaction->rollback();
1573 unset($transaction);
1584 $transaction = db_transaction();
1587 foreach ($submissions as $state) {
1588 $state[
'alternative_accessions'] = $state[
'alternative_accessions'] ??
'';
1592 if (!db_table_exists(
'tpps_submission_dbxref')) {
1594 db_create_table(
'tpps_submission_dbxref', $schema[
'tpps_submission_dbxref']);
1598 catch (\Exception $e) {
1599 $transaction->rollback();
1610 $transaction = db_transaction();
1612 db_delete(
'chado.project_pub')
1613 ->condition(
'pub_id', db_query(
'select distinct(pub_id) from chado.pub_organism'),
'NOT IN')
1616 catch (\Exception $e) {
1617 $transaction->rollback();
1628 $transaction = db_transaction();
1631 foreach ($submissions as $state) {
1632 $org_num = $state[
'saved_values'][
TPPS_PAGE_1][
'organism'][
'number'];
1634 for ($i = 1; $i <= $org_num; $i++) {
1635 if (gettype($state[
'saved_values'][
TPPS_PAGE_1][
'organism'][$i]) !=
'array') {
1637 $name = $state[
'saved_values'][
TPPS_PAGE_1][
'organism'][$i];
1638 $state[
'saved_values'][
TPPS_PAGE_1][
'organism'][$i] = array();
1639 $state[
'saved_values'][
TPPS_PAGE_1][
'organism'][$i][
'name'] = $name;
1640 $state[
'saved_values'][
TPPS_PAGE_1][
'organism'][$i][
'is_tree'] = TRUE;
1648 catch (\Exception $e) {
1649 $transaction->rollback();
1660 $transaction = db_transaction();
1662 'status' => array(
'Approved',
'Pending Approval',
'Incomplete'),
1665 foreach ($submissions as $state) {
1669 foreach ($state[
'file_info'][TPPS_PAGE_3] as $fid => $name) {
1670 if ($name ==
'Plant_Accession' or $name ==
'Tree_Accession') {
1671 $species = implode(
'_', explode(
' ', $state[
'saved_values'][
TPPS_PAGE_1][
'organism'][$org_num][
'name']));
1672 $state[
'file_info'][
TPPS_PAGE_3][$fid] =
"{$name}_{$species}";
1680 foreach ($state[
'file_info'][TPPS_PAGE_4] as $fid => $name) {
1681 if (preg_match(
'/^(.*_)([0-9]+)$/', $name, $matches)) {
1682 $prefix = $matches[1];
1683 $org_num = $matches[2];
1684 $species = implode(
'_', explode(
' ', $state[
'saved_values'][
TPPS_PAGE_1][
'organism'][$org_num][
'name']));
1685 $state[
'file_info'][
TPPS_PAGE_4][$fid] =
"{$prefix}{$species}";
1693 if ($state[
'status'] ==
'Approved') {
1699 catch (\Exception $e) {
1700 $transaction->rollback();
1711 $transaction = db_transaction();
1713 if (!db_table_exists(
'tpps_project_file_managed')) {
1715 db_create_table(
'tpps_project_file_managed', $schema[
'tpps_project_file_managed']);
1719 catch (\Exception $e) {
1720 $transaction->rollback();
1731 $transaction = db_transaction();
1733 'status' =>
'Approved',
1736 foreach ($submissions as $state) {
1737 if (empty($state[
'ids'][
'project_id'])) {
1742 $fourthpage = $state[
'saved_values'][
TPPS_PAGE_4];
1745 $firstpage[
'photo'] ?? NULL,
1748 for ($i = 1; $i <= $firstpage[
'organism'][
'number']; $i++) {
1749 $fids[] = $thirdpage[
'tree-accession'][
"species-$i"][
'file'] ?? NULL;
1750 $fids[] = $fourthpage[
"organism-$i"][
'phenotype'][
'file'] ?? NULL;
1751 $fids[] = $fourthpage[
"organism-$i"][
'phenotype'][
'metadata'] ?? NULL;
1752 $fids[] = $fourthpage[
"organism-$i"][
'phenotype'][
'iso'] ?? NULL;
1753 $fids[] = $fourthpage[
"organism-$i"][
'genotype'][
'tripal_fasta'][
'file_upload'] ?? NULL;
1754 $fids[] = $fourthpage[
"organism-$i"][
'genotype'][
'tripal_fasta'][
'file_upload_existing'] ?? NULL;
1755 $fids[] = $fourthpage[
"organism-$i"][
'genotype'][
'files'][
'snps-assay'] ?? NULL;
1756 $fids[] = $fourthpage[
"organism-$i"][
'genotype'][
'files'][
'snps-association'] ?? NULL;
1757 $fids[] = $fourthpage[
"organism-$i"][
'genotype'][
'files'][
'snps-pop-struct'] ?? NULL;
1758 $fids[] = $fourthpage[
"organism-$i"][
'genotype'][
'files'][
'snps-kinship'] ?? NULL;
1759 $fids[] = $fourthpage[
"organism-$i"][
'genotype'][
'files'][
'assay-design'] ?? NULL;
1760 $fids[] = $fourthpage[
"organism-$i"][
'genotype'][
'files'][
'ssrs'] ?? NULL;
1761 $fids[] = $fourthpage[
"organism-$i"][
'genotype'][
'files'][
'ssrs_extra'] ?? NULL;
1762 $fids[] = $fourthpage[
"organism-$i"][
'genotype'][
'files'][
'indels'] ?? NULL;
1763 $fids[] = $fourthpage[
"organism-$i"][
'genotype'][
'files'][
'other'] ?? NULL;
1764 $fids[] = $fourthpage[
"organism-$i"][
'genotype'][
'files'][
'vcf'] ?? NULL;
1767 foreach ($state[
'saved_values'][
'summarypage'][
'analysis'] as $key => $info) {
1768 if (substr($key, -5) ==
'_file' and file_load($info)) {
1773 foreach ($fids as $fid) {
1774 if (!empty($fid) and file_load($fid)) {
1775 $query = db_select(
'tpps_project_file_managed',
't')
1777 ->condition(
'fid', $fid)
1778 ->condition(
'project_id', $state[
'ids'][
'project_id'])
1780 $result = $query->fetchObject() ?? NULL;
1782 if (empty($result)) {
1783 db_insert(
'tpps_project_file_managed')
1785 'project_id' => $state[
'ids'][
'project_id'],
1791 if (!empty($state[
'revised_files'][$fid]) and ($file = file_load($state[
'revised_files'][$fid]))) {
1792 $query = db_select(
'tpps_project_file_managed',
't')
1794 ->condition(
'fid', $state[
'revised_files'][$fid])
1795 ->condition(
'project_id', $state[
'ids'][
'project_id'])
1797 $result = $query->fetchObject() ?? NULL;
1799 if (empty($result)) {
1800 db_insert(
'tpps_project_file_managed')
1802 'project_id' => $state[
'ids'][
'project_id'],
1803 'fid' => $state[
'revised_files'][$fid],
1812 catch (\Exception $e) {
1813 $transaction->rollback();
1824 $transaction = db_transaction();
1826 if (!db_table_exists(
'tpps_tag')) {
1828 db_create_table(
'tpps_tag', $schema[
'tpps_tag']);
1830 if (!db_table_exists(
'tpps_submission_tag')) {
1832 db_create_table(
'tpps_submission_tag', $schema[
'tpps_submission_tag']);
1839 foreach ($submissions as $record) {
1842 if (count($tags) == 0) {
1843 if ((!isset($state[
'tpps_type']) or $state[
'tpps_type'] !=
'tppsc')) {
1850 if ($state[
'status'] ==
'Approved') {
1851 $data_type = $state[
'saved_values'][
TPPS_PAGE_2][
'data_type'];
1852 $env_phenotypes = FALSE;
1853 if (preg_match(
'/G/', $data_type)) {
1856 if (preg_match(
'/P/', $data_type)) {
1858 $org_num = $state[
'saved_values'][
TPPS_PAGE_1][
'organism'][
'number'];
1859 for ($i = 1; $i <= $org_num; $i++) {
1860 $phenotype_num = $state[
'saved_values'][
TPPS_PAGE_4][
"organism-$i"][
'phenotype'][
'phenotypes-meta'][
'number'];
1861 for ($j = 1; $j <= $phenotype_num; $j++) {
1862 $info = $state[
'saved_values'][
TPPS_PAGE_4][
"organism-$i"][
'phenotype'][
'phenotypes-meta'][$j];
1863 if ($info[
'env-check']) {
1864 $env_phenotypes = TRUE;
1870 if (preg_match(
'/E/', $data_type) or $env_phenotypes) {
1877 catch (\Exception $e) {
1878 $transaction->rollback();
1889 $transaction = db_transaction();
1894 db_insert(
'tpps_tag')
1896 'name' =>
'No Location Information',
1905 db_insert(
'tpps_tag')
1907 'name' =>
'Approximate Coordinates',
1915 foreach ($submissions as $record) {
1918 if (!empty($state[
'saved_values'][
TPPS_PAGE_3][
'skip_validation'])) {
1922 $org_num = $state[
'saved_values'][
TPPS_PAGE_1][
'organism'][
'number'];
1923 for ($i = 1; $i <= $org_num; $i++) {
1924 $species_i = $state[
'saved_values'][
TPPS_PAGE_3][
'tree-accession'][
"species-$i"];
1925 if (isset($species_i[
'exact_coords']) and !$species_i[
'exact_coords']) {
1932 catch (\Exception $e) {
1933 $transaction->rollback();
1944 $transaction = db_transaction();
1948 foreach ($submissions as $record) {
1951 $org_num = $state[
'saved_values'][
TPPS_PAGE_1][
'organism'][
'number'];
1952 for ($i = 1; $i <= $org_num; $i++) {
1953 $phenotype = &$state[
'saved_values'][
TPPS_PAGE_4][
"organism-$i"][
'phenotype'] ?? NULL;
1954 if (!empty($phenotype)) {
1957 if (empty($phenotype[
'iso-check']) and !empty($phenotype[
'file'])) {
1958 $phenotype[
'normal-check'] = TRUE;
1963 if (!empty($phenotype[
'iso-check']) and !array_key_exists(
'normal-check', $phenotype)) {
1964 $phenotype[
'normal-check'] = FALSE;
1973 catch (\Exception $e) {
1974 $transaction->rollback();
tpps_submission_get_tags($accession)
tpps_create_stock_entity()
tpps_update_submission(array $state, array $options=array())
tpps_default_permissions()
tpps_alter_tpps_submission_dbxref()
tpps_alter_tpps_project_file_managed()
tpps_chado_insert_record($table, $records, array $options=array())
tpps_submission_add_tag($accession, $tag)
tpps_migrate_cvterms($old_major=NULL, $old_minor=NULL, $new_major=TPPS_MAJOR_VERSION, $new_minor=TPPS_MINOR_VERSION)
tpps_create_plusgeno_view()
tpps_local_install_term($key, $version=NULL)
tpps_submission_rename_files($accession)
tpps_create_genotype_entity()
tpps_alter_tpps_submission_tag()
tpps_load_submission($accession, $state=TRUE)
tpps_submission_update_all_stats(array &$form_state)
tpps_alter_tpps_submissions()
tpps_load_cvterm($term, array $options=array(), $version=NULL, $refresh_cache=FALSE)
tpps_load_submission_multiple(array $conditions=array(), $state=TRUE)
tpps_create_genotype_search_views()
tpps_install_miappe_ontology()
tpps_alter_genotype_call()
tpps_ols_install_term($info)