Tripal Plant PopGen Submit
details.inc File Reference

Go to the source code of this file.

Functions

 tpps_details ($accession=NULL)
 
 tpps_details_form_callback (array $form, array $form_state)
 
 tpps_details_genotype (array &$state)
 
 tpps_details_get_study_file_ids ($state)
 
 tpps_details_mass_spectrometry (array &$state)
 
 tpps_details_phenotype (array &$state)
 
 tpps_details_search (array $form, array $form_state)
 
 tpps_details_species (array &$state)
 
 tpps_details_study (array &$state)
 
 tpps_details_tab ($accession, $type)
 
 tpps_details_tabs (array &$state)
 
 tpps_details_tags_sort ()
 
 tpps_details_top ()
 
 tpps_details_top_callback ()
 
 tpps_details_trees (array &$state)
 

Detailed Description

Defines functions to be used in the TPPS Details pages.

Definition in file details.inc.

Function Documentation

◆ tpps_details()

tpps_details (   $accession = NULL)

Starting point for most TPPS Details pages.

Either returns the top details page, which allows users to select from completed studies, or returns the per-submission details page, which allows users to browse the details of a study.

Parameters
string$accessionThe accession to get details from. If NULL, show all submissions.
Returns
string The appropriate output.

Definition at line 21 of file details.inc.

21  {
22  global $base_url;
23  global $user;
24  $output = "";
25 
26  if (empty($accession)) {
27  $query = db_select('chado.plusgeno_view', 'pg');
28  $query->addExpression('count(distinct(accession))', 'count');
29  $query = $query->execute();
30  $num_studies = $query->fetchObject()->count;
31 
32  $query = db_select('chado.plusgeno_view', 'pg');
33  $query->addExpression('count(distinct(species))', 'count');
34  $query = $query->execute();
35  $num_species = $query->fetchObject()->count;
36 
37  $tpps_link = "<b><a target=\"blank\" href=\"/tpps\">submit your study</a></b>";
38  $output .= "This page reflects community submissions associated with published studies. Each submission is associated with a longterm identifier that connects the genotype, phenotype, and/or environmental metrics assessed. These studies represent diversity assessements, association mapping, and landscape genomics. We accept studies with a variety of marker types. We encourage you to $tpps_link to TreeGenes and utilize the provided accession in your publication. We currently have <b>$num_studies</b> studies representing <b>$num_species</b> species.";
39  if (module_exists('cartogratree')) {
40  $output .= " Studies that have georeferenced accessions associated with them can be queried on <b><a href=\"cartogratree\">CartograPlant.</a></b>";
41  }
42  $form = drupal_get_form('tpps_details_search');
43  $output .= render($form);
44  $output .= tpps_details_tags_sort();
45  $output .= "<div id='tpps-details-table'>" . tpps_details_top() . "</div>";
46  drupal_add_css(drupal_get_path('module', 'tpps') . TPPS_CSS_PATH);
47  drupal_add_js(drupal_get_path('module', 'tpps') . TPPS_JS_PATH);
48  return $output;
49  }
50 
51  $output = "<a href=\"$base_url/tpps/details\">Return to TPPS Details</a>$output";
52  $state = tpps_load_submission($accession);
53  if (!empty($state)) {
54  if ($state['status'] != 'Approved') {
55  drupal_set_message(t('This submission is still under construction. Some of the information may be available here, but please keep in mind that it may be incomplete or subject to change in the near future.'), 'warning');
56  if (function_exists('tpps_details_byaccession_page')) {
57  $output .= @tpps_details_byaccession_page()['raw_markup']['#markup'];
58  drupal_add_js(drupal_get_path('module', 'tpps') . TPPS_JS_PATH);
59  return $output;
60  }
61  }
62 
63  if (empty($state['saved_values'][TPPS_PAGE_3]['skip_validation'])) {
64  $map_api_key = variable_get('tpps_maps_api_key', NULL);
65  $map_api_tools = "<script src=\"https://developers.google.com/maps/documentation/javascript/examples/markerclusterer/markerclusterer.js\"></script><script src=\"https://maps.googleapis.com/maps/api/js?key=$map_api_key&callback=initMap\"
66  async defer></script>"
67  . "<div id=\"_map_wrapper\"></div>";
68  $tree_info = array();
69  if (!empty($state['tree_info'])) {
70  foreach ($state['tree_info'] as $name => $info) {
71  if (!empty($info['lat']) and !empty($info['lng'])) {
72  $tree_info[] = array(
73  $name,
74  $info['lat'],
75  $info['lng'],
76  );
77  }
78  }
79  drupal_add_js(array('tpps' => array('tree_info' => $tree_info)), 'setting');
80  }
81  $output .= $map_api_tools;
82  }
83  drupal_add_js(drupal_get_path('module', 'tpps') . TPPS_JS_PATH);
84  drupal_add_css(drupal_get_path('module', 'tpps') . TPPS_CSS_PATH);
85 
86  $pub_link = $state['title'];
87  $pub_id = db_select('chado.project_pub', 'p')
88  ->fields('p', array('pub_id'))
89  ->condition('project_id', $state['ids']['project_id'])
90  ->execute()->fetchObject()->pub_id;
91  if (!empty($pub_id)) {
92  $bundle = tripal_load_bundle_entity(array('label' => 'Publication'));
93  $pub_id = chado_get_record_entity_by_bundle($bundle, $pub_id);
94  $pub_link = "<a href='$base_url/Publication/$pub_id'>$pub_link</a>";
95  }
96 
97  if (!empty($state['saved_values'][TPPS_PAGE_3]['skip_validation'])) {
98  $image_path = drupal_get_path('module', 'tpps') . '/images/';
99  $pub_link .= "<img title=\"This submission contains no location information\" src=\"/{$image_path}no_location.png\">";
100  }
101 
102  $output .= "<h2>$pub_link</h2>";
103  $output .= tpps_show_tags(tpps_submission_get_tags($state['accession']));
104  $primary_author = $state['authors'][0];
105  if (preg_match('/,/', $primary_author)) {
106  $parts = explode(',', $primary_author);
107  $lastname = trim($parts[0]);
108  }
109  else {
110  $parts = explode(' ', $primary_author);
111  $lastname = $parts[count($parts) - 1];
112  }
113  $output .= "<h4>$lastname et al {$state['pyear']}";
114  if (!empty($state['journal'])) {
115  $output .= " published in {$state['journal']}";
116  }
117  $output .= "</h4>";
118  $output .= "<div id=\"abstract\"><a href=\"#abstract\">Click to show abstract</a></div>"
119  . "<script>jQuery(document).ready(jQuery('#abstract').on('click', function() {
120  jQuery('#abstract')[0].innerHTML = `{$state['abstract']}`;
121  }));</script>";
122  if (empty($state['saved_values'][TPPS_PAGE_3]['skip_validation']) and module_exists('cartogratree')) {
123  $output .= "<a href=\"$base_url/cartogratree?accession=$accession\" target=\"blank\">View in CartograPlant</a><br>";
124  }
125  $output .= "<a href=\"$base_url/tpps/api/files/$accession\">Download compressed raw files</a><br>";
126  if ($state['saved_values'][TPPS_PAGE_1]['publication']['status'] != 'Published' and $user->uid == tpps_load_submission($accession, FALSE)->uid) {
127  $output .= "<a href=\"$base_url/tpps/$accession/edit-publication\">Edit publication information</a>";
128  }
129 
130  $output .= tpps_details_tabs($state);
131  return $output;
132  }
133 
134  drupal_set_message(t('This submission is pending resubmission through the new TPPS pipeline. Some of the information may be available here, but please keep in mind that it may be incomplete or subject to change in the near future.'), 'warning');
135 
136  if (function_exists('tpps_details_byaccession_page')) {
137  $output .= @tpps_details_byaccession_page()['raw_markup']['#markup'];
138  drupal_add_js(drupal_get_path('module', 'tpps') . TPPS_JS_PATH);
139  }
140  return $output;
141 }
tpps_submission_get_tags($accession)
const TPPS_PAGE_1
Definition: tpps.module:12
tpps_details_tags_sort()
Definition: details.inc:534
const TPPS_CSS_PATH
Definition: tpps.module:11
const TPPS_JS_PATH
Definition: tpps.module:10
tpps_show_tags(array $tags)
Definition: display.inc:976
tpps_details_tabs(array &$state)
Definition: details.inc:152
tpps_load_submission($accession, $state=TRUE)
Definition: submissions.inc:27
tpps_details_top()
Definition: details.inc:209
const TPPS_PAGE_3
Definition: tpps.module:14

◆ tpps_details_form_callback()

tpps_details_form_callback ( array  $form,
array  $form_state 
)

AJAX callback for the search form details_op element.

Parameters
array$formThe form being updated.
array$form_stateThe state of the form being updated.
Returns
array The part of the form to be updated.

Definition at line 568 of file details.inc.

568  {
569  return array(
570  'details_type' => $form['details_type'],
571  'details_op' => $form['details_op'],
572  'details_value' => $form['details_value'],
573  );
574 }

◆ tpps_details_genotype()

tpps_details_genotype ( array &  $state)

Creates the table of individual plant genotype details for a submission.

Parameters
array$stateThe form state of the submission.
Returns
string The HTML table of plants and genotypes associated with the submission.

Definition at line 981 of file details.inc.

981  {
982  $params = drupal_get_query_parameters($_POST);
983  $page = 0;
984  if (!empty($params['page'])) {
985  $page = $params['page'];
986  }
987  $rows = array();
988  $per_page = 20;
989  $start = $page * $per_page;
990 
991  // Set total check = false to begin with
992  $total_check = false;
993 
994  // Check cache to see if a total is available
995  $total_array = variable_get('tpps_tab_genotype_' + $state['ids']['project_id'] + '_total');
996  if($total_array == NULL) {
997  $total_check = true;
998  }
999  else {
1000  // total array should have an expire_time
1001  if($total_array['expire_time'] < time()) {
1002  $total_check = true;
1003  }
1004  else {
1005  $total = $total_array['total'];
1006  }
1007 
1008  }
1009 
1010 
1011  $dev = FALSE;
1012  if($dev == TRUE) {
1013  $total_check = true;
1014  }
1015 
1016  if($total_check) {
1017  $query = db_select('chado.genotype', 'g');
1018  $query->join('chado.stock_genotype', 'sg', 'sg.genotype_id = g.genotype_id');
1019  $query->join('chado.project_stock', 'ps', 'ps.stock_id = sg.stock_id');
1020  $query->addExpression('count(g.genotype_id)', 'count');
1021  $query->condition('ps.project_id', $state['ids']['project_id']);
1022  $query = $query->execute();
1023  $total = $query->fetchObject()->count;
1024 
1025  $total_array = array(
1026  'expire_time' => time() + variable_get('tpps_tab_genotype_total_cache_time', 30*(24*60*60)),
1027  'total' => $total
1028  );
1029  variable_set('tpps_tab_genotype_' + $state['ids']['project_id'] + '_total', $total_array);
1030  }
1031 
1032  $_GET['page'] = $page;
1033  pager_default_initialize($total, $per_page);
1034 
1035  $query = db_select('chado.genotype', 'g');
1036  $query->join('chado.stock_genotype', 'sg', 'sg.genotype_id = g.genotype_id');
1037  $query->join('chado.project_stock', 'ps', 'ps.stock_id = sg.stock_id');
1038  $query->join('chado.stock', 's', 's.stock_id = sg.stock_id');
1039  $query->fields('g', array(
1040  'genotype_id',
1041  'name',
1042  'uniquename',
1043  'description',
1044  'type_id',
1045  ));
1046  $query->fields('s', array('uniquename', 'stock_id'));
1047  $query->condition('ps.project_id', $state['ids']['project_id']);
1048  $query->range($start, $per_page);
1049  $query = $query->execute();
1050 
1051  while (($result = $query->fetchObject())) {
1052  // preg_match('/^TGDR...-(.*)$/', $result->s_uniquename, $matches);
1053  preg_match('/^TGDR.{1,4}-(.*)$/', $result->s_uniquename, $matches);
1054  $tree = $matches[1];
1055  $type = chado_get_cvterm(array(
1056  'cvterm_id' => $result->type_id,
1057  ))->name ?? "";
1058  $rows[] = array(
1059  tpps_entity_link($result->stock_id, $tree, 'Stock'),
1060  tpps_entity_link($result->genotype_id, $result->uniquename, 'Genotype'),
1061  $result->description,
1062  $type,
1063  );
1064  }
1065 
1066  $vars = array(
1067  'header' => array(
1068  'Plant',
1069  'Name',
1070  'Description',
1071  'Marker Type',
1072  ),
1073  'rows' => $rows,
1074  'attributes' => array(
1075  'class' => array('view'),
1076  'id' => 'tpps_table_display',
1077  ),
1078  'caption' => '',
1079  'colgroups' => NULL,
1080  'sticky' => FALSE,
1081  'empty' => '',
1082  );
1083  $table = theme('table', $vars);
1084  $pager = theme('pager', array('quantity', $total));
1085  return $pager . $table;
1086 }
tpps_entity_link($id, $name, $label)
Definition: display.inc:954

◆ tpps_details_get_study_file_ids()

tpps_details_get_study_file_ids (   $state)

Definition at line 738 of file details.inc.

738  {
739  $saved_values = $state['saved_values'];
740  // print_r($saved_values);
741  $organism_count = $saved_values['1']['organism']['number'];
742  $file_ids = [];
743  for($i=1; $i<=4; $i++) {
744  if ($i == 3) {
745  for($j=1; $j<=$organism_count; $j++) {
746  if(isset($saved_values[$i]['tree-accession']['species-' . $j]['file'])) {
747  array_push($file_ids, $saved_values[$i]['tree-accession']['species-' . $j]['file']);
748  }
749  }
750  }
751  if ($i == 4) {
752  // Phenotype files
753  for($j=1; $j<=$organism_count; $j++) {
754  if(isset($saved_values[$i]['organism-' . $j]['phenotype']['file'])) {
755  array_push($file_ids, $saved_values[$i]['organism-' . $j]['phenotype']['file']);
756  }
757  if(isset($saved_values[$i]['organism-' . $j]['phenotype']['metadata'])) {
758  array_push($file_ids, $saved_values[$i]['organism-' . $j]['phenotype']['metadata']);
759  }
760  }
761  for($j=1; $j<=$organism_count; $j++) {
762  if(isset($saved_values[$i]['organism-' . $j]['genotype']['files']['snps-assay'])) {
763  array_push($file_ids, $saved_values[$i]['organism-' . $j]['genotype']['files']['snps-assay']);
764  }
765  if(isset($saved_values[$i]['organism-' . $j]['genotype']['files']['snps-association'])) {
766  array_push($file_ids, $saved_values[$i]['organism-' . $j]['genotype']['files']['snps-association']);
767  }
768  if(isset($saved_values[$i]['organism-' . $j]['genotype']['files']['vcf'])) {
769  array_push($file_ids, $saved_values[$i]['organism-' . $j]['genotype']['files']['vcf']);
770  }
771  if(isset($saved_values[$i]['organism-' . $j]['genotype']['files']['ssrs'])) {
772  array_push($file_ids, $saved_values[$i]['organism-' . $j]['genotype']['files']['ssrs']);
773  }
774  if(isset($saved_values[$i]['organism-' . $j]['genotype']['files']['ssrs_extra'])) {
775  array_push($file_ids, $saved_values[$i]['organism-' . $j]['genotype']['files']['ssrs_extra']);
776  }
777  }
778  }
779  }
780  // check summarypage for supplemental files
781  if(count($saved_values['summarypage']['files']) > 2) {
782  $files = $saved_values['summarypage']['files'];
783  foreach ($files as $file_index => $file_id) {
784  if(is_numeric($file_id) && $file_id > 0) {
785  // print_r($file_index);
786  // array_push($file_ids, $file_id);
787  }
788  }
789  }
790  return $file_ids;
791 }

◆ tpps_details_mass_spectrometry()

tpps_details_mass_spectrometry ( array &  $state)

Creates the table for mass spectrometry details for a submission.

Parameters
array$stateThe form state of the submission.
Returns
string The HTML table of plants and genotypes associated with the submission.

Definition at line 1098 of file details.inc.

1098  {
1099  $params = drupal_get_query_parameters($_POST);
1100  $page = 0;
1101  if (!empty($params['page'])) {
1102  $page = $params['page'];
1103  }
1104  $rows = array();
1105  $per_page = 20;
1106  $start = $page * $per_page;
1107 
1108  $query = db_select('chado.phenotype', 'p');
1109  $query->join('chado.stock_phenotype', 'sp', 'sp.phenotype_id = p.phenotype_id');
1110  $query->join('chado.project_stock', 'ps', 'ps.stock_id = sp.stock_id');
1111  $query->join('chado.stock', 's', 's.stock_id = sp.stock_id');
1112  $query->addExpression('count(p.phenotype_id)', 'count');
1113  $query->condition('ps.project_id', $state['ids']['project_id']);
1114  $query = $query->execute();
1115  $total = $query->fetchObject()->count;
1116 
1117  $_GET['page'] = $page;
1118  pager_default_initialize($total, $per_page);
1119 
1120  $query = db_select('chado.phenotype', 'p');
1121  $query->join('chado.stock_phenotype', 'sp', 'sp.phenotype_id = p.phenotype_id');
1122  $query->join('chado.project_stock', 'ps', 'ps.stock_id = sp.stock_id');
1123  $query->join('chado.stock', 's', 's.stock_id = sp.stock_id');
1124  $query->fields('p', array(
1125  'phenotype_id',
1126  'name',
1127  'attr_id',
1128  'observable_id',
1129  'value',
1130  ));
1131  $query->fields('s', array('uniquename', 'stock_id'));
1132  $query->condition('p.attr_id', tpps_load_cvterm('Intensity')->cvterm_id);
1133  //$query->condition('ps.project_id', $state['ids']['project_id']);
1134  $query->range($start, $per_page);
1135  $query = $query->execute();
1136 
1137  while (($result = $query->fetchObject())) {
1138  preg_match('/^TGDR...-(.*)$/', $result->uniquename, $matches);
1139  $tree = $matches[1];
1140  $obs = chado_get_cvterm(array(
1141  'cvterm_id' => $result->observable_id,
1142  ))->name ?? "";
1143  $attr = chado_get_cvterm(array(
1144  'cvterm_id' => $result->attr_id,
1145  ))->name ?? "";
1146 
1147  $rows[] = array(
1148  tpps_entity_link($result->stock_id, $tree, 'Stock'),
1149  tpps_entity_link($result->phenotype_id, $result->name, 'Phenotype'),
1150  $attr,
1151  $obs,
1152  $result->value,
1153  );
1154  }
1155 
1156  $vars = array(
1157  'header' => array(
1158  'Plant',
1159  'Name',
1160  'Attribute',
1161  'Entity',
1162  'Value',
1163  ),
1164  'rows' => $rows,
1165  'attributes' => array(
1166  'class' => array('view'),
1167  'id' => 'tpps_table_display',
1168  ),
1169  'caption' => '',
1170  'colgroups' => NULL,
1171  'sticky' => FALSE,
1172  'empty' => '',
1173  );
1174  $table = theme('table', $vars);
1175  $pager = theme('pager', array('quantity', $total));
1176  return $pager . $table;
1177 }
tpps_entity_link($id, $name, $label)
Definition: display.inc:954
tpps_load_cvterm($term, array $options=array(), $version=NULL, $refresh_cache=FALSE)

◆ tpps_details_phenotype()

tpps_details_phenotype ( array &  $state)

Creates the table of individual plant phenotype details for a submission.

Parameters
array$stateThe form state of the submission.
Returns
string The HTML table of plants and phenotypes associated with the submission.

Definition at line 879 of file details.inc.

879  {
880  $params = drupal_get_query_parameters($_POST);
881  $page = 0;
882  if (!empty($params['page'])) {
883  $page = $params['page'];
884  }
885  $rows = array();
886  $per_page = 20;
887  $start = $page * $per_page;
888 
889  $query = db_select('chado.phenotype', 'p');
890  $query->join('chado.stock_phenotype', 'sp', 'sp.phenotype_id = p.phenotype_id');
891  $query->join('chado.project_stock', 'ps', 'ps.stock_id = sp.stock_id');
892  $query->join('chado.stock', 's', 's.stock_id = sp.stock_id');
893  $query->addExpression('count(p.phenotype_id)', 'count');
894  $query->condition('ps.project_id', $state['ids']['project_id']);
895  $query = $query->execute();
896  $total = $query->fetchObject()->count;
897 
898  $_GET['page'] = $page;
899  pager_default_initialize($total, $per_page);
900 
901  $query = db_select('chado.phenotype', 'p');
902  $query->join('chado.stock_phenotype', 'sp', 'sp.phenotype_id = p.phenotype_id');
903  $query->join('chado.project_stock', 'ps', 'ps.stock_id = sp.stock_id');
904  $query->join('chado.stock', 's', 's.stock_id = sp.stock_id');
905  $query->fields('p', array(
906  'phenotype_id',
907  'name',
908  'attr_id',
909  'observable_id',
910  'value',
911  ));
912  $query->fields('s', array('uniquename', 'stock_id'));
913  $query->condition('ps.project_id', $state['ids']['project_id']);
914  $query->range($start, $per_page);
915  $query = $query->execute();
916 
917  // $query = db_select('chado.new_pheno_view_update', 'p');
918  // $query->addField('p', 'phenotype_id', 'phenotype_id');
919  // $query->addField('p', 'synonym', 'name');
920  // $query->addField('p', 'structure_id', 'attr_id');
921  // $query->addField('p', 'observable_id', 'observable_id');
922  // $query->addField('p', 'value', 'value');
923  // $query->addField('p', 'tree_acc', 'uniquename');
924  // $query->addField('p', 'stock_id', 'stock_id');
925  // $query->condition('p.project_id', $state['ids']['project_id']);
926  // $query->range($start, $per_page);
927  // $query = $query->execute();
928 
929  while (($result = $query->fetchObject())) {
930  // preg_match('/^TGDR...-(.*)$/', $result->uniquename, $matches);
931  preg_match('/^TGDR.{1,4}-(.*)$/', $result->uniquename, $matches);
932  $tree = $matches[1];
933  $obs = chado_get_cvterm(array(
934  'cvterm_id' => $result->observable_id,
935  ))->name ?? "";
936  $attr = chado_get_cvterm(array(
937  'cvterm_id' => $result->attr_id,
938  ))->name ?? "";
939 
940  $rows[] = array(
941  tpps_entity_link($result->stock_id, $tree, 'Stock'),
942  tpps_entity_link($result->phenotype_id, $result->name, 'Phenotype'),
943  $attr,
944  $obs,
945  $result->value,
946  );
947  }
948 
949  $vars = array(
950  'header' => array(
951  'Plant',
952  'Name',
953  'Attribute',
954  'Entity',
955  'Value',
956  ),
957  'rows' => $rows,
958  'attributes' => array(
959  'class' => array('view'),
960  'id' => 'tpps_table_display',
961  ),
962  'caption' => '',
963  'colgroups' => NULL,
964  'sticky' => FALSE,
965  'empty' => '',
966  );
967  $table = theme('table', $vars);
968  $pager = theme('pager', array('quantity', $total));
969  return $pager . $table;
970 }
tpps_entity_link($id, $name, $label)
Definition: display.inc:954

◆ tpps_details_search()

tpps_details_search ( array  $form,
array  $form_state 
)

Define a search form to search and filter through the TPPS Details page.

Parameters
array$formThe form array object.
array$form_stateThe form state array object.
Returns
array The populated search form.

Definition at line 424 of file details.inc.

424  {
425  $params = drupal_get_query_parameters();
426  $form['details_type'] = array(
427  '#type' => 'select',
428  '#options' => array(
429  'title' => t('Title'),
430  'species' => t('Species'),
431  'accession' => t('Accession'),
432  'author' => t('Primary Author'),
433  'year' => t('Publication Year'),
434  'phenotype_name' => t('Phenotype Name'),
435  'phenotype_ontology' => t('Phenotype Ontology Name'),
436  'genotype_name' => t('Genotype Name'),
437  'genotype_marker' => t('Genotype Marker Type'),
438  'tags' => t('Tags'),
439  ),
440  '#ajax' => array(
441  'wrapper' => 'tpps-details-form',
442  'callback' => 'tpps_details_form_callback',
443  ),
444  '#prefix' => '<div id="tpps-details-form">',
445  '#default_value' => $params['type'] ?? NULL,
446  );
447 
448  $ops = array(
449  '~*' => '~*',
450  'LIKE' => 'LIKE',
451  '=' => '=',
452  );
453 
454  $form['details_op'] = array(
455  '#type' => 'select',
456  '#options' => $ops,
457  '#default_value' => $params['op'] ?? NULL,
458  );
459 
460  $form['details_value'] = array(
461  '#type' => 'textfield',
462  '#suffix' => '</div>',
463  '#autocomplete_path' => 'tpps/autocomplete/project_title',
464  '#default_value' => $params['value'] ?? NULL,
465  );
466 
467  if (empty($form_state['values']['details_type'])) {
468  $form_state['values']['details_type'] = $params['type'] ?? NULL;
469  }
470 
471  if (!empty($form_state['values']['details_type'])) {
472  switch ($form_state['values']['details_type']) {
473  case 'title':
474  $form['details_value']['#autocomplete_path'] = 'tpps/autocomplete/project_title';
475  break;
476 
477  case 'species':
478  $form['details_value']['#autocomplete_path'] = 'tpps/autocomplete/species';
479  break;
480 
481  case 'accession':
482  $form['details_value']['#autocomplete_path'] = 'tpps/autocomplete/project_accession';
483  break;
484 
485  case 'author':
486  $form['details_value']['#autocomplete_path'] = 'tpps/autocomplete/author';
487  break;
488 
489  case 'phenotype_name':
490  $form['details_value']['#autocomplete_path'] = 'tpps/autocomplete/phenotype';
491  break;
492 
493  case 'phenotype_ontology':
494  $form['details_value']['#autocomplete_path'] = 'tpps/autocomplete/phenotype_ontology';
495  break;
496 
497  case 'genotype_name':
498  $form['details_value']['#autocomplete_path'] = 'tpps/autocomplete/genotype';
499  break;
500 
501  case 'genotype_marker':
502  $form['details_value']['#autocomplete_path'] = 'tpps/autocomplete/genotype_marker';
503  break;
504 
505  default:
506  $form['details_value']['#autocomplete_path'] = NULL;
507  break;
508  }
509  }
510 
511  $form['details_search'] = array(
512  '#type' => 'button',
513  '#button_type' => 'button',
514  '#value' => t('Search'),
515  );
516 
517  $form['reset_button'] = array(
518  '#markup' => '<button class="btn btn-primary form-button" type="reset"/>Reset</button>',
519  );
520 
521  $form['#attributes'] = array(
522  'style' => 'text-align:center',
523  );
524 
525  return $form;
526 }

◆ tpps_details_species()

tpps_details_species ( array &  $state)

Creates the table for species details for a submission.

Parameters
array$stateThe form state of the submission.
Returns
string The HTML table of species associated with the submission.

Definition at line 585 of file details.inc.

585  {
586  $query = db_select('chado.organism', 'o');
587  $query->join('chado.pub_organism', 'po', 'o.organism_id = po.organism_id');
588  $query->join('chado.project_pub', 'pp', 'pp.pub_id = po.pub_id');
589  $query->fields('o', array('organism_id', 'genus', 'species', 'common_name'));
590  $query->condition('pp.project_id', $state['ids']['project_id']);
591  $query = $query->execute();
592  $rows = array();
593 
594  while (($result = $query->fetchObject())) {
595  $id = $result->organism_id;
596  $common_name = $result->common_name;
597  $family = $order = "";
598 
599  if (tpps_chado_prop_exists('organism', $id, 'family')) {
600  $family = db_select('chado.organismprop', 'o')
601  ->fields('o', array('value'))
602  ->condition('organism_id', $id)
603  ->condition('type_id', tpps_load_cvterm('family')->cvterm_id)
604  ->execute()->fetchObject()->value;
605  }
606 
607  if (tpps_chado_prop_exists('organism', $id, 'order')) {
608  $order = db_select('chado.organismprop', 'o')
609  ->fields('o', array('value'))
610  ->condition('organism_id', $id)
611  ->condition('type_id', tpps_load_cvterm('order')->cvterm_id)
612  ->execute()->fetchObject()->value;
613  }
614 
615  if (empty($common_name) and tpps_chado_prop_exists('organism', $id, 'common name')) {
616  $common_name = db_select('chado.organismprop', 'o')
617  ->fields('o', array('value'))
618  ->condition('organism_id', $id)
619  ->condition('type_id', tpps_load_cvterm('common name')->cvterm_id)
620  ->execute()->fetchObject()->value;
621  }
622 
623  $name = "{$result->genus} {$result->species}";
624  $link = tpps_entity_link($id, $name, 'Organism');
625  $rows[$name] = array(
626  $order,
627  $family,
628  $link,
629  $common_name,
630  );
631  }
632 
633  $vars = array(
634  'header' => array(
635  'Order',
636  'Family',
637  'Species',
638  'Common Name',
639  ),
640  'rows' => $rows,
641  'attributes' => array(
642  'class' => array('view'),
643  'id' => 'tpps_table_display',
644  ),
645  'caption' => '',
646  'colgroups' => NULL,
647  'sticky' => FALSE,
648  'empty' => '',
649  );
650  return theme('table', $vars);
651 }
tpps_entity_link($id, $name, $label)
Definition: display.inc:954
tpps_chado_prop_exists($base_table, $id, $name, array $options=array())
tpps_load_cvterm($term, array $options=array(), $version=NULL, $refresh_cache=FALSE)

◆ tpps_details_study()

tpps_details_study ( array &  $state)

Creates the table for study information details for a submission.

Parameters
array$stateThe form state of the submission.
Returns
string The HTML table of study information of the submission.

Definition at line 662 of file details.inc.

662  {
663  $rows = array();
664 
665  $species = array();
666  for ($i = 1; $i <= $state['stats']['species_count']; $i++) {
667  $id = $state['ids']['organism_ids'][$i];
668  $species_name = $state['saved_values'][TPPS_PAGE_1]['organism'][$i]['name'];
669  $species[] = tpps_entity_link($id, $species_name, 'Organism');
670  }
671 
672  $study_types = array(
673  1 => 'Natural Population (Landscape)',
674  2 => 'Growth Chamber',
675  3 => 'Greenhouse',
676  4 => 'Experimental/Common Garden',
677  5 => 'Plantation',
678  );
679 
680  $files = array();
681  $study_file_ids = tpps_details_get_study_file_ids($state);
682  // foreach ($state['files'] as $fid) {
683  foreach ($study_file_ids as $fid) {
684  $file = file_load($fid);
685  if ($file) {
686  $file_url = check_plain(file_create_url($file->uri));
687  if(stripos($file_url, 'core/labs') === FALSE) {
688  $files[] = "<a href='$file_url' target='blank'>$file->filename</a>";
689  }
690 
691  }
692  }
693 
694  $pub_link = $state['title'];
695  $pub_id = db_select('chado.project_pub', 'p')
696  ->fields('p', array('pub_id'))
697  ->condition('project_id', $state['ids']['project_id'])
698  ->execute()->fetchObject()->pub_id;
699  if (!empty($pub_id)) {
700  $bundle = tripal_load_bundle_entity(array('label' => 'Publication'));
701  $pub_id = chado_get_record_entity_by_bundle($bundle, $pub_id);
702  $pub_link = "<a href='$base_url/Publication/$pub_id'>$pub_link</a>";
703  }
704  $rows[] = array('Accession', $state['accession']);
705  $rows[] = array('Title', $pub_link);
706  $rows[] = array('Authors', implode(', ', $state['authors']));
707  $rows[] = array('Species', implode('<br>', $species));
708  $rows[] = array('Data Type', $state['saved_values'][TPPS_PAGE_2]['data_type']);
709  $rows[] = array(
710  'Study Type',
711  $study_types[$state['saved_values'][TPPS_PAGE_2]['study_type']],
712  );
713  $rows[] = array('File Downloads', implode('<br>', $files));
714  $rows[] = array('Population Size', $state['stats']['tree_count']);
715  if (!empty($state['stats']['phenotype_count'])) {
716  $rows[] = array('Phenotype Count', $state['stats']['phenotype_count']);
717  }
718  if (!empty($state['stats']['unique_phenotypes'])) {
719  $rows[] = array('Unique Phenotypes', $state['stats']['unique_phenotypes']);
720  }
721  // @todo genotype counts.
722  // $rows[] = array('Genotype Count', $state['stats']['genotype_count']);
723  $vars = array(
724  'header' => array(),
725  'rows' => $rows,
726  'attributes' => array(
727  'class' => array('view'),
728  'id' => 'tpps_table_display',
729  ),
730  'caption' => '',
731  'colgroups' => NULL,
732  'sticky' => FALSE,
733  'empty' => '',
734  );
735  return theme('table', $vars);
736 }
const TPPS_PAGE_1
Definition: tpps.module:12
tpps_entity_link($id, $name, $label)
Definition: display.inc:954
const TPPS_PAGE_2
Definition: tpps.module:13
tpps_details_get_study_file_ids($state)
Definition: details.inc:738

◆ tpps_details_tab()

tpps_details_tab (   $accession,
  $type 
)

A callback to print a single detail tab.

Parameters
string$accessionThe accession number of the submission.
string$typeThe type of details we want to print.

Definition at line 197 of file details.inc.

197  {
198  $function = "tpps_details_$type";
199  $state = tpps_load_submission($accession);
200  print($function($state));
201 }
tpps_load_submission($accession, $state=TRUE)
Definition: submissions.inc:27

◆ tpps_details_tabs()

tpps_details_tabs ( array &  $state)

Returns a template for details tabs.

Parameters
array$stateThe form state of the submission.
Returns
string HTML for the details tabs.

Definition at line 152 of file details.inc.

152  {
153  $output = '<ul class="nav nav-tabs" role="tablist">
154  <li class="nav-item"><a class="nav-link active" role="tab" data-toggle="tab" href="#species">Species</a></li>
155  <li class="nav-item"><a class="nav-link" role="tab" data-toggle="tab" href="#study">Study Details</a></li>
156  <li class="nav-item"><a class="nav-link" role="tab" data-toggle="tab" href="#trees">Plants</a></li>';
157  $p_exist = FALSE;
158  $g_exist = FALSE;
159  $mass_spectro_exist = FALSE;
160  for ($i = 1; $i <= $state['stats']['species_count']; $i++) {
161  if (!empty($state['saved_values'][TPPS_PAGE_4]["organism-$i"]['phenotype'])) {
162  $p_exist = TRUE;
163  }
164  if (!empty($state['saved_values'][TPPS_PAGE_4]["organism-$i"]['genotype'])) {
165  $g_exist = TRUE;
166  }
167  if ($state['saved_values'][TPPS_PAGE_4]["organism-$i"]['phenotype']['iso-check'] == TRUE) {
168  $mass_spectro_exist = TRUE;
169  }
170  }
171 
172  $output .= $p_exist ? '<li class="nav-item"><a class="nav-link" role="tab" data-toggle="tab" href="#phenotype">Phenotypes / Environments</a></li>' : "";
173  $output .= $g_exist ? '<li class="nav-item"><a class="nav-link" role="tab" data-toggle="tab" href="#genotype">Genotypes</a></li>' : "";
174  $output .= $mass_spectro_exist ? '<li class="nav-item"><a class="nav-link" role="tab" data-toggle="tab" href="#mass_spectrometry">Mass Spectrometry</a></li>' : "";
175  $output .= '</ul><div id="tab-content" class="tab-content">';
176 
177  $output .= "<div id=\"species\" role=\"tabpanel\" class=\"tab-pane fade in active\"></div>";
178  $output .= "<div id=\"study\" role=\"tabpanel\" class=\"tab-pane fade\"></div>";
179  $output .= "<div id=\"trees\" role=\"tabpanel\" class=\"tab-pane fade\"></div>";
180 
181  $output .= $p_exist ? "<div id=\"phenotype\" role=\"tabpanel\" class=\"tab-pane fade\"></div>" : "";
182  $output .= $g_exist ? "<div id=\"genotype\" role=\"tabpanel\" class=\"tab-pane fade\"></div>" : "";
183  $output .= $mass_spectro_exist ? "<div id=\"mass_spectrometry\" role=\"tabpanel\" class=\"tab-pane fade\"></div>" : "";
184 
185  $output .= '</div>';
186  return $output;
187 }
const TPPS_PAGE_4
Definition: tpps.module:15

◆ tpps_details_tags_sort()

tpps_details_tags_sort ( )

Display TPPS tags to sort Details page.

Returns
string Tag options as rendered HTML.

Definition at line 534 of file details.inc.

534  {
535  $output = "";
536 
537  $query = db_select('tpps_tag', 't')
538  ->fields('t')
539  ->orderBy('static', 'DESC')
540  ->orderBy('tpps_tag_id')
541  ->execute();
542  $tags = array();
543  while (($result = $query->fetchObject())) {
544  $tags[$result->tpps_tag_id] = array(
545  'id' => $result->tpps_tag_id,
546  'name' => $result->name,
547  'color' => $result->color,
548  'static' => $result->static,
549  );
550  }
551 
552  $output .= tpps_show_tags($tags);
553 
554  return "<label for=\"tpps-tags-filter\">Sort by tags:</label><div id=\"tpps-tags-filter\">" . $output . "</div>";
555 }
tpps_show_tags(array $tags)
Definition: display.inc:976

◆ tpps_details_top()

tpps_details_top ( )

Builds the TPPS Details page when no accession is provided.

Returns
string The HTML string for the TPPS Details page.

Definition at line 209 of file details.inc.

209  {
210  global $base_url;
211  $params = drupal_get_query_parameters($_POST);
212  $page = 0;
213  if (empty($params)) {
214  $params = drupal_get_query_parameters();
215  }
216  if (!empty($params['page'])) {
217  $page = $params['page'];
218  }
219  $per_page = 20;
220 
221  $query = db_select('chado.plusgeno_view', 'pg');
222  $query->addExpression('count(distinct(pg.accession))', 'count');
223  if (!empty($params['type']) and !empty($params['value']) and !empty($params['op'])) {
224  switch ($params['type']) {
225  case 'title':
226  case 'species':
227  case 'project_id':
228  case 'accession':
229  case 'author':
230  case 'year':
231  $query->condition($params['type'], $params['value'], $params['op']);
232  break;
233 
234  case 'phenotype_name':
235  $query->innerJoin('chado.project_stock', 'ps', 'ps.project_id = pg.project_id');
236  $query->innerJoin('chado.stock_phenotype', 'sp', 'sp.stock_id = ps.stock_id');
237  $query->innerJoin('chado.phenotype', 'ph', 'ph.phenotype_id = sp.phenotype_id');
238  $query->condition('ph.name', $params['value'], $params['op']);
239  break;
240 
241  case 'phenotype_ontology':
242  $query->innerJoin('chado.project_stock', 'ps', 'ps.project_id = pg.project_id');
243  $query->innerJoin('chado.stock_phenotype', 'sp', 'sp.stock_id = ps.stock_id');
244  $query->innerJoin('chado.phenotype', 'ph', 'ph.phenotype_id = sp.phenotype_id');
245  $query->innerJoin('chado.cvterm', 'cvt', 'cvt.cvterm_id = ph.attr_id');
246  $query->innerJoin('chado.cv', 'cv', 'cv.cv_id = cvt.cv_id');
247  $query->condition('cv.name', $params['value'], $params['op']);
248  break;
249 
250  case 'genotype_name':
251  $query->innerJoin('chado.tpps_search_genotype_name', 'g', 'g.project_id = pg.project_id');
252  $query->condition('g.name', $params['value'], $params['op']);
253  break;
254 
255  case 'genotype_marker':
256  $query->innerJoin('chado.tpps_search_genotype_marker', 'g', 'g.project_id = pg.project_id');
257  $query->condition('g.name', $params['value'], $params['op']);
258  break;
259 
260  case 'tags':
261  $query->innerJoin('public.tpps_submission', 'ts', 'ts.accession = pg.accession');
262  $query->innerJoin('public.tpps_submission_tag', 'st', 'st.tpps_submission_id = ts.tpps_submission_id');
263  $query->innerJoin('public.tpps_tag', 'tt', 'tt.tpps_tag_id = st.tpps_tag_id');
264  $query->condition('tt.name', $params['value'], $params['op']);
265  break;
266 
267  default:
268  break;
269  }
270  }
271  $query = $query->execute();
272  $total = $query->fetchObject()->count;
273 
274  $_GET['page'] = $page;
275  $page = pager_default_initialize($total, $per_page);
276  $start = $page * $per_page;
277 
278  $submissions = db_select('chado.plusgeno_view', 'pg');
279  $submissions->distinct();
280  $submissions->innerJoin('chado.project', 'p', 'p.project_id = pg.project_id');
281  if (!empty($params['type']) and !empty($params['value']) and !empty($params['op'])) {
282  switch ($params['type']) {
283  case 'title':
284  case 'species':
285  case 'project_id':
286  case 'accession':
287  case 'author':
288  case 'year':
289  $submissions->condition($params['type'], $params['value'], $params['op']);
290  break;
291 
292  case 'phenotype_name':
293  $submissions->innerJoin('chado.project_stock', 'ps', 'ps.project_id = pg.project_id');
294  $submissions->innerJoin('chado.stock_phenotype', 'sp', 'sp.stock_id = ps.stock_id');
295  $submissions->innerJoin('chado.phenotype', 'ph', 'ph.phenotype_id = sp.phenotype_id');
296  $submissions->condition('ph.name', $params['value'], $params['op']);
297  break;
298 
299  case 'phenotype_ontology':
300  $submissions->innerJoin('chado.project_stock', 'ps', 'ps.project_id = pg.project_id');
301  $submissions->innerJoin('chado.stock_phenotype', 'sp', 'sp.stock_id = ps.stock_id');
302  $submissions->innerJoin('chado.phenotype', 'ph', 'ph.phenotype_id = sp.phenotype_id');
303  $submissions->innerJoin('chado.cvterm', 'cvt', 'cvt.cvterm_id = ph.attr_id');
304  $submissions->innerJoin('chado.cv', 'cv', 'cv.cv_id = cvt.cv_id');
305  $submissions->condition('cv.name', $params['value'], $params['op']);
306  break;
307 
308  case 'genotype_name':
309  $submissions->innerJoin('chado.tpps_search_genotype_name', 'g', 'g.project_id = pg.project_id');
310  $submissions->condition('g.name', $params['value'], $params['op']);
311  break;
312 
313  case 'genotype_marker':
314  $submissions->innerJoin('chado.tpps_search_genotype_marker', 'g', 'g.project_id = pg.project_id');
315  $submissions->condition('g.name', $params['value'], $params['op']);
316  break;
317 
318  case 'tags':
319  $submissions->innerJoin('public.tpps_submission', 'ts', 'ts.accession = pg.accession');
320  $submissions->innerJoin('public.tpps_submission_tag', 'st', 'st.tpps_submission_id = ts.tpps_submission_id');
321  $submissions->innerJoin('public.tpps_tag', 'tt', 'tt.tpps_tag_id = st.tpps_tag_id');
322  $submissions->condition('tt.name', $params['value'], $params['op']);
323  break;
324 
325  default:
326  break;
327  }
328  }
329  $submissions->fields('pg', array(
330  'title',
331  'project_id',
332  'accession',
333  'tree_count',
334  'phenotypes_assessed',
335  'phen_count',
336  'gen_count',
337  ));
338  $submissions->range($start, $per_page);
339  $submissions->orderBy('pg.accession');
340  $submissions = $submissions->execute();
341 
342  $rows = array();
343  while (($sub = $submissions->fetchObject())) {
344  $proj_id = $sub->project_id;
345 
346  $query = db_select('chado.organism', 'o');
347  $query->join('chado.pub_organism', 'po', 'o.organism_id = po.organism_id');
348  $query->join('chado.project_pub', 'pp', 'pp.pub_id = po.pub_id');
349  $query->fields('o', array('organism_id', 'genus', 'species'));
350  $query->condition('pp.project_id', $proj_id);
351  $query->distinct();
352  $query = $query->execute();
353 
354  $species = array();
355  while (($result = $query->fetchObject())) {
356  $species[] = tpps_entity_link($result->organism_id, "{$result->genus} {$result->species}", 'Organism');
357  }
358 
359  $warning = "";
360  if (empty(tpps_load_submission($sub->accession))) {
361  $warning = "<img src='$base_url/misc/message-16-warning.png' title='This study has not yet been resubmitted through the new TPPS pipeline'> ";
362  }
363 
364  $row = array(
365  "<a href=\"$base_url/tpps/details/{$sub->accession}\">{$sub->accession}</a>",
366  "$warning<a href=\"$base_url/tpps/details/{$sub->accession}\">{$sub->title}</a>",
367  tpps_show_tags(tpps_submission_get_tags($sub->accession)),
368  implode('<br>', $species),
369  $sub->tree_count,
370  $sub->phenotypes_assessed,
371  $sub->phen_count,
372  $sub->gen_count,
373  );
374  $rows[$sub->accession] = $row;
375  }
376 
377  ksort($rows);
378 
379  $vars = array(
380  'header' => array(
381  'Accession',
382  'Title',
383  'Tags',
384  'Species',
385  'Plant Count',
386  'Phenotypes Assessed',
387  'Phenotypic Measures',
388  'Genotype Count',
389  ),
390  'rows' => $rows,
391  'attributes' => array(
392  'class' => array('view'),
393  'id' => 'tpps_table_display',
394  ),
395  'caption' => '',
396  'colgroups' => NULL,
397  'sticky' => FALSE,
398  'empty' => '',
399  );
400 
401  $output = theme('table', $vars);
402  $pager = theme('pager', array('quantity', $total));
403  return $pager . $output;
404 }
tpps_submission_get_tags($accession)
tpps_show_tags(array $tags)
Definition: display.inc:976
tpps_entity_link($id, $name, $label)
Definition: display.inc:954
tpps_load_submission($accession, $state=TRUE)
Definition: submissions.inc:27

◆ tpps_details_top_callback()

tpps_details_top_callback ( )

Serves as a direct callback to print the contents of tpps_details_top().

Definition at line 409 of file details.inc.

409  {
410  print(tpps_details_top());
411 }
tpps_details_top()
Definition: details.inc:209

◆ tpps_details_trees()

tpps_details_trees ( array &  $state)

Creates the table of individual plant details for a submission.

Parameters
array$stateThe form state of the submission.
Returns
string The HTML table of plants associated with the submission.

Definition at line 802 of file details.inc.

802  {
803  $path = current_path();
804  $args = explode('/', $path);
805  $params = drupal_get_query_parameters($_POST);
806  $page = 0;
807  if (!empty($params['page'])) {
808  $page = $params['page'];
809  }
810  $rows = array();
811  $per_page = 20;
812 
813  if (empty($state['tree_info'])) {
814  $output = t('The plant information for this study has not been properly updated. Please contact your site administrator.');
815  return $output;
816  }
817 
818  $skip = !empty($state['saved_values'][TPPS_PAGE_3]['skip_validation']);
819 
820  $_GET['page'] = $page;
821  pager_default_initialize(count($state['tree_info']), $per_page);
822  $chunks = array_chunk($state['tree_info'], $per_page, TRUE);
823 
824  foreach ($chunks[$page] as $name => $info) {
825  $id = $info['organism_id'];
826  $form_number = array_search($id, $state['ids']['organism_ids']);
827  $species_name = $state['saved_values'][TPPS_PAGE_1]['organism'][$form_number]['name'];
828 
829  $tree_id = tpps_entity_link($info['stock_id'], $name, 'Stock');
830 
831  $row = array(
832  strtoupper($args[2]) . '-' . strip_tags($tree_id),
833  tpps_entity_link($info['stock_id'], $name, 'Stock'),
834  tpps_entity_link($id, $species_name, 'Organism'),
835  );
836  if (!$skip) {
837  $row[] = $info['lat'];
838  $row[] = $info['lng'];
839  }
840  $rows[] = $row;
841  }
842 
843  $header = array(
844  'TreeGenes Identifier',
845  'Identifier',
846  'Species',
847  );
848  if (!$skip) {
849  $header[] = 'Latitude';
850  $header[] = 'Longitude';
851  }
852 
853  $vars = array(
854  'header' => $header,
855  'rows' => $rows,
856  'attributes' => array(
857  'class' => array('view'),
858  'id' => 'tpps_table_display',
859  ),
860  'caption' => '',
861  'colgroups' => NULL,
862  'sticky' => FALSE,
863  'empty' => '',
864  );
865  $table = theme('table', $vars);
866  $pager = theme('pager', array('quantity', count($state['tree_info'])));
867  return $pager . $table;
868 }
const TPPS_PAGE_1
Definition: tpps.module:12
tpps_entity_link($id, $name, $label)
Definition: display.inc:954
const TPPS_PAGE_3
Definition: tpps.module:14