Tripal Plant PopGen Submit
page_4_helper.php
Go to the documentation of this file.
1 <?php
2 
23 function tpps_phenotype(array &$form, array &$form_state, array $values, $id) {
24  $phenotype_upload_location = 'public://' . variable_get('tpps_phenotype_files_dir', 'tpps_phenotype');
25 
26  $form[$id]['phenotype'] = array(
27  '#type' => 'fieldset',
28  '#title' => t('<div class="fieldset-title">Phenotype Information:</div>'),
29  '#tree' => TRUE,
30  '#prefix' => "<div id=\"phenotype-main-$id\">",
31  '#suffix' => '</div>',
32  '#description' => t('Upload a file and/or fill in form fields below to provide us with metadata about your phenotypes.'),
33  '#collapsible' => TRUE,
34  );
35 
36  $form[$id]['phenotype']['normal-check'] = array(
37  '#type' => 'checkbox',
38  '#title' => t('My phenotypes include traits and/or environmental information other than mass spectrometry or isotope analysis'),
39  '#ajax' => array(
40  'callback' => 'tpps_update_phenotype',
41  'wrapper' => "phenotype-main-$id",
42  ),
43  '#default_value' => tpps_get_ajax_value($form_state, array(
44  $id,
45  'phenotype',
46  'normal-check',
47  ), TRUE),
48  );
49 
50  $form[$id]['phenotype']['iso-check'] = array(
51  '#type' => 'checkbox',
52  '#title' => t('My phenotypes include results from a mass spectrometry or isotope analysis'),
53  '#ajax' => array(
54  'callback' => 'tpps_update_phenotype',
55  'wrapper' => "phenotype-main-$id",
56  ),
57  );
58 
59  $normal_check = tpps_get_ajax_value($form_state, array(
60  $id,
61  'phenotype',
62  'normal-check',
63  ), NULL);
64 
65  $iso_check = tpps_get_ajax_value($form_state, array(
66  $id,
67  'phenotype',
68  'iso-check',
69  ), NULL);
70 
71  if (!empty($iso_check)) {
72  $form[$id]['phenotype']['iso'] = array(
73  '#type' => 'managed_file',
74  '#title' => t('Phenotype Isotope/Mass Spectrometry file: *'),
75  '#upload_location' => $phenotype_upload_location,
76  '#upload_validators' => array(
77  'file_validate_extensions' => array('csv tsv xlsx'),
78  ),
79  '#description' => t('Please upload a file containing all of your isotope/mass spectrometry data. The format of this file is very important! The first column of your file should contain plant identifiers which match the plant identifiers you provided in your plant accession file, and all of the remaining columns should contain isotope or mass spectrometry data.'),
80  );
81  }
82 
83  if (!empty($normal_check)) {
84  $attr_options = array(0 => '- Select -');
85  $terms = array(
86  'absorbance' => t('Absorbance'),
87  'age' => t('Age'),
88  'alive' => t('Alive'),
89  'amount' => t('Amount'),
90  'angle' => t('Angle'),
91  'area' => t('Area'),
92  'bent' => t('Bent'),
93  'carbon-13 atom' => t('Carbon-13 Atom'),
94  'chlorophyll' => t('Chlorophyll'),
95  'circumference' => t('Circumerence'),
96  'color' => t('Color'),
97  'composition' => t('Composition'),
98  'concentration_of' => t('Concentration of'),
99  'damage' => t('Damage'),
100  'delta' => t('Delta'),
101  'description' => t('Description'),
102  'diameter' => t('Diameter'),
103  'distance' => t('Distance'),
104  'gravity' => t('Gravity'),
105  'growth_quality_of_occurrent' => t('Growth Quality of Occurrent'),
106  'growth_rate' => t('Growth Rate'),
107  'has_number_of' => t('Has number of'),
108  'height' => t('Height'),
109  'humidity_level' => t('Humidity Level'),
110  'intensity' => t('Intensity'),
111  'length' => t('Length'),
112  'lesioned' => t('Lesioned'),
113  'maturity' => t('Maturity'),
114  'photosynthesis' => t('Photosynthesis'),
115  'position' => t('Position'),
116  'precipitation' => t('Precipitation'),
117  'pressure' => t('Pressure'),
118  'proportionality_to' => t('Proportionality to'),
119  'rate' => t('Rate'),
120  'rough' => t('Rough'),
121  'sex' => t('Sex'),
122  'shape' => t('Shape'),
123  'size' => t('Size'),
124  'temperature' => t('Temperature'),
125  'texture' => t('Texture'),
126  'thickness' => t('Thickness'),
127  'time' => t('Time'),
128  'transpiration' => t('Transpiration'),
129  'volume' => t('Volume'),
130  'water use efficiency' => t('Water use efficiency'),
131  'weight' => t('Weight'),
132  'width' => t('Width'),
133  );
134  foreach ($terms as $term => $label) {
135  $attr_id = tpps_load_cvterm($term)->cvterm_id;
136  $attr_options[$attr_id] = $label;
137  // drupal_set_message($term . "," . $label . "," . $attr_id);
138  }
139  $attr_options['other'] = 'My attribute term is not in this list';
140 
141  $unit_options = array();
142  $terms = array(
143  'absorbance unit' => t('Absorbance Unit'),
144  'boolean' => t('Boolean (Binary)'),
145  'centimeter' => t('Centimeter'),
146  'centimeters per day' => t('Centimeters per Day'),
147  'cubic_centimeter' => t('Cubic Centimeter'),
148  'cubic_meter' => t('Cubic Meter'),
149  'day' => t('Day'),
150  'degrees_celsius' => t('Degrees Celsius'),
151  'degrees celsius per millimeter' => t('Degrees Celsius per Millimeter'),
152  'degrees_fahrenheit' => t('Degrees Fahrenheit'),
153  'grams_per_square_meter' => t('Grams per Square Meter'),
154  'gram' => t('Gram'),
155  'kilogram' => t('Kilogram'),
156  'kilogram_per_cubic_meter' => t('Kilogram per Cubic Meter'),
157  'kilograms per meter cubed' => t('Kilograms per Meter Cubed'),
158  'liter' => t('Liter'),
159  'log(centimeters per day)' => t('Log (Centimeters per day)'),
160  'log(centimeters cubed per day)' => t('Log (Centimeters cubed per day)'),
161  'luminous_intensity_unit' => t('Luminous Intensity Unit'),
162  'meter' => t('Meter'),
163  'milligram' => t('Milligram'),
164  'milligrams per millimeter' => t('Milligrams per Millimeter'),
165  'milligrams per millimeter squared' => t('Milligrams per Millimeter Squared'),
166  'milligrams per milligram' => t('Milligrams per Milligram'),
167  'milliliter' => t('Milliliter'),
168  'millimeter' => t('Millimeter'),
169  'micrometer' => t('Micrometer'),
170  'micromoles carbon dioxide per meter squared per second' => t('Micromoles Carbon Dioxide per Meter Squared per Second'),
171  'micromoles carbon dioxide per gram per second' => t('Micromoles Carbon Dioxide per Gram per Second'),
172  'micromoles carbon dioxide per gram Nitrogen per second' => t('Micromoles Carbon Dioxide per Gram Nitrogen per Second'),
173  'micromoles carbon dioxide per millimole water' => t('Micromoles Carbon Dioxide per Millimole Water'),
174  'moles water per meter squared per second' => t('Moles Water per Meter Squared per Second'),
175  'no unit' => t('No Unit'),
176  'number' => t('Number'),
177  'pascal' => t('Pascal'),
178  'percent' => t('Percent'),
179  'qualitative' => t('Qualitative'),
180  'square_micrometer' => t('Square Micrometer'),
181  'square_millimeter' => t('Square Millimeter'),
182  'watt_per_square_meter' => t('Watt per Square Meter'),
183  'year' => t('Year'),
184  );
185  foreach ($terms as $term => $label) {
186  $unit_id = tpps_load_cvterm($term)->cvterm_id;
187  $unit_options[$unit_id] = $label;
188  // drupal_set_message($term . "," . $label . "," . $unit_id);
189  }
190  $unit_options['other'] = 'My unit is not in this list';
191 
192  $struct_options = array();
193  $terms = array(
194  'whole plant' => t('Whole Plant'),
195  'bark' => t('Bark'),
196  'branch' => t('Branch'),
197  'bud' => t('Bud'),
198  'catkin_inflorescence' => t('Catkin Inflorescence'),
199  'endocarp' => t('Endocarp'),
200  'floral_organ' => t('Floral Organ'),
201  'flower' => t('Flower'),
202  'flower_bud' => t('Flower Bud'),
203  'flower_fascicle' => t('Flower Fascicle'),
204  'fruit' => t('Fruit'),
205  'leaf' => t('Leaf'),
206  'leaf_rachis' => t('Leaf Rachis'),
207  'leaflet' => t('Leaflet'),
208  'nut_fruit' => t('Nut Fruit (Acorn)'),
209  'petal' => t('Petal'),
210  'petiole' => t('Petiole'),
211  'phloem' => t('Phloem'),
212  'plant_callus' => t('Plant Callus (Callus)'),
213  'primary_thickening_meristem' => t('Primary Thickening Meristem'),
214  'root' => t('Root'),
215  'secondary_xylem' => t('Secondary Xylem (Wood)'),
216  'seed' => t('Seed'),
217  'shoot_system' => t('Shoot System (Crown)'),
218  'stem' => t('Stem (Trunk, Primary Stem)'),
219  'stomatal_complex' => t('Stomatal Complex (Stomata)'),
220  'strobilus' => t('Strobilus'),
221  'terminal_bud' => t('Terminal Bud'),
222  'vascular_leaf' => t('Vascular Leaf (Needle)'),
223  );
224  foreach ($terms as $term => $label) {
225  $struct_id = tpps_load_cvterm($term)->cvterm_id;
226  $struct_options[$struct_id] = $label;
227  // drupal_set_message($term . "," . $label . "," . $struct_id);
228  }
229  $struct_options['other'] = 'My structure term is not in this list';
230 
231  $field = array(
232  '#type' => 'fieldset',
233  '#tree' => TRUE,
234  '#prefix' => "<div id=\"org_{$id}_phenotype_!num_meta\">",
235  '#suffix' => "</div>",
236  'name' => array(
237  '#type' => 'textfield',
238  '#title' => 'Phenotype !num Name: *',
239  // '#autocomplete_path' => 'tpps/autocomplete/phenotype',
240  '#prefix' => "<label><b>Phenotype !num:</b></label>",
241  '#attributes' => array(
242  'data-toggle' => array('tooltip'),
243  'data-placement' => array('right'),
244  // 'title' => array('If your phenotype name is not in the autocomplete list, don\'t worry about it! We will create new phenotype metadata in the database for you.'),
245  'title' => array('If your phenotype name does not exist in our database, don\'t worry about it! We will create new phenotype metadata in the database for you.'),
246  ),
247  '#description' => t('Phenotype "name" is the human-readable name of the phenotype, where "attribute" is the thing that the phenotype is describing. Phenotype "name" should match the data in the "Phenotype Name/Identifier" column that you select in your <a href="@url">Phenotype file</a> below.', array('@url' => url('/tpps', array('fragment' => "edit-$id-phenotype-file-ajax-wrapper")))),
248  ),
249  'env-check' => array(
250  '#type' => 'checkbox',
251  '#title' => 'Phenotype !num is an environmental phenotype',
252  '#ajax' => array(
253  'callback' => 'tpps_update_phenotype_meta',
254  'wrapper' => "org_{$id}_phenotype_!num_meta",
255  ),
256  ),
257  'attribute' => array(
258  '#type' => 'select',
259  '#title' => 'Phenotype !num Attribute: *',
260  '#options' => $attr_options,
261  '#ajax' => array(
262  'callback' => 'tpps_update_phenotype_meta',
263  'wrapper' => "org_{$id}_phenotype_!num_meta",
264  ),
265  ),
266  'attr-other' => array(
267  '#type' => 'textfield',
268  '#title' => 'Phenotype !num Custom Attribute: *',
269  '#autocomplete_path' => 'tpps/autocomplete/attribute',
270  '#attributes' => array(
271  'data-toggle' => array('tooltip'),
272  'data-placement' => array('right'),
273  'title' => array('If your attribute is not in the autocomplete list, don\'t worry about it! We will create new phenotype metadata in the database for you.'),
274  ),
275  '#description' => t('Some examples of attributes include: "amount", "width", "mass density", "area", "height", "age", "broken", "time", "color", "composition", etc.'),
276  '#states' => array(
277  'visible' => array(
278  ':input[name="' . $id . '[phenotype][phenotypes-meta][!num][attribute]"]' => array('value' => 'other'),
279  ),
280  ),
281  ),
282  'description' => array(
283  '#type' => 'textfield',
284  '#title' => 'Phenotype !num Description: *',
285  '#description' => t('Please provide a short description of Phenotype !num'),
286  ),
287  'units' => array(
288  '#type' => 'select',
289  '#title' => 'Phenotype !num Units: *',
290  '#options' => $unit_options,
291  ),
292  'unit-other' => array(
293  '#type' => 'textfield',
294  '#title' => 'Phenotype !num Custom Units: *',
295  '#autocomplete_path' => 'tpps/autocomplete/units',
296  '#attributes' => array(
297  'data-toggle' => array('tooltip'),
298  'data-placement' => array('right'),
299  'title' => array('If your unit is not in the autocomplete list, don\'t worry about it! We will create new phenotype metadata in the database for you.'),
300  ),
301  '#description' => t('Some examples of units include: "m", "meters", "in", "inches", "Degrees Celsius", "°C", etc.'),
302  '#states' => array(
303  'visible' => array(
304  ':input[name="' . $id . '[phenotype][phenotypes-meta][!num][units]"]' => array('value' => 'other'),
305  ),
306  ),
307  ),
308  'val-check' => array(
309  '#type' => 'checkbox',
310  '#title' => 'Phenotype !num has a value range',
311  '#states' => array(
312  'invisible' => array(
313  array(
314  array(
315  ':input[name="' . $id . '[phenotype][phenotypes-meta][!num][units]"]' => array('value' => tpps_load_cvterm('boolean')->cvterm_id),
316  ),
317  'or',
318  array(
319  ':input[name="' . $id . '[phenotype][phenotypes-meta][!num][bin-check]"]' => array('checked' => TRUE),
320  ),
321  ),
322  ),
323  ),
324  ),
325  'bin-check' => array(
326  '#type' => 'checkbox',
327  '#title' => 'Phenotype !num is a binary phenotype',
328  '#states' => array(
329  'invisible' => array(
330  array(
331  array(
332  ':input[name="' . $id . '[phenotype][phenotypes-meta][!num][units]"]' => array('value' => tpps_load_cvterm('boolean')->cvterm_id),
333  ),
334  'or',
335  array(
336  ':input[name="' . $id . '[phenotype][phenotypes-meta][!num][val-check]"]' => array('checked' => TRUE),
337  ),
338  ),
339  ),
340  ),
341  ),
342  'structure' => array(
343  '#type' => 'select',
344  '#title' => 'Phenotype !num Structure: *',
345  '#options' => $struct_options,
346  '#default_value' => tpps_load_cvterm('whole plant')->cvterm_id,
347  ),
348  'struct-other' => array(
349  '#type' => 'textfield',
350  '#title' => 'Phenotype !num Custom Structure: *',
351  '#autocomplete_path' => 'tpps/autocomplete/structure',
352  '#attributes' => array(
353  'data-toggle' => array('tooltip'),
354  'data-placement' => array('right'),
355  'title' => array('If your structure is not in the autocomplete list, don\'t worry about it! We will create new phenotype metadata in the database for you.'),
356  ),
357  '#description' => t('Some examples of structure descriptors include: "stem", "bud", "leaf", "xylem", "whole plant", "meristematic apical cell", etc.'),
358  '#states' => array(
359  'visible' => array(
360  ':input[name="' . $id . '[phenotype][phenotypes-meta][!num][structure]"]' => array('value' => 'other'),
361  ),
362  ),
363  ),
364  'min' => array(
365  '#type' => 'textfield',
366  '#title' => 'Phenotype !num Minimum Value (type 1 for binary): *',
367  '#states' => array(
368  'visible' => array(
369  array(
370  array(
371  ':input[name="' . $id . '[phenotype][phenotypes-meta][!num][units]"]' => array('value' => tpps_load_cvterm('boolean')->cvterm_id),
372  ),
373  'or',
374  array(
375  ':input[name="' . $id . '[phenotype][phenotypes-meta][!num][val-check]"]' => array('checked' => TRUE),
376  ),
377  'or',
378  array(
379  ':input[name="' . $id . '[phenotype][phenotypes-meta][!num][bin-check]"]' => array('checked' => TRUE),
380  ),
381  ),
382  ),
383  ),
384  ),
385  'max' => array(
386  '#type' => 'textfield',
387  '#title' => 'Phenotype !num Maximum Value (type 2 for binary): *',
388  '#states' => array(
389  'visible' => array(
390  array(
391  array(
392  ':input[name="' . $id . '[phenotype][phenotypes-meta][!num][units]"]' => array('value' => tpps_load_cvterm('boolean')->cvterm_id),
393  ),
394  'or',
395  array(
396  ':input[name="' . $id . '[phenotype][phenotypes-meta][!num][val-check]"]' => array('checked' => TRUE),
397  ),
398  'or',
399  array(
400  ':input[name="' . $id . '[phenotype][phenotypes-meta][!num][bin-check]"]' => array('checked' => TRUE),
401  ),
402  ),
403  ),
404  ),
405  ),
406  );
407 
408  tpps_dynamic_list($form, $form_state, 'phenotypes-meta', $field, array(
409  'label' => 'Phenotype',
410  'title' => "",
411  'callback' => 'tpps_update_phenotype',
412  'parents' => array($id, 'phenotype'),
413  'wrapper' => "phenotype-main-$id",
414  'name_suffix' => $id,
415  'alternative_buttons' => array(
416  "Add 5 Phenotypes" => 5,
417  "Add 10 Phenotypes" => 10,
418  "Clear All Phenotypes" => 'tpps_phenotype_number_clear',
419  ),
420  'button_weights' => array(
421  "Add Phenotype" => -5,
422  "Add 5 Phenotypes" => -4,
423  "Add 10 Phenotypes" => -3,
424  "Remove Phenotype" => -2,
425  "Clear All Phenotypes" => -1,
426  ),
427  'substitute_fields' => array(
428  array('#prefix'),
429  array('name', '#title'),
430  array('name', '#prefix'),
431  array('env-check', '#title'),
432  array('env-check', '#ajax', 'wrapper'),
433  array('attribute', '#title'),
434  array('attribute', '#ajax', 'wrapper'),
435  array('attr-other', '#title'),
436  array('description', '#title'),
437  array('description', '#description'),
438  array('units', '#title'),
439  array('unit-other', '#title'),
440  array('val-check', '#title'),
441  array('bin-check', '#title'),
442  array('structure', '#title'),
443  array('struct-other', '#title'),
444  array('min', '#title'),
445  array('max', '#title'),
446  ),
447  'substitute_keys' => array(
448  array(
449  'attr-other',
450  '#states',
451  'visible',
452  ':input[name="' . $id . '[phenotype][phenotypes-meta][!num][attribute]"]',
453  ),
454  array(
455  'unit-other',
456  '#states',
457  'visible',
458  ':input[name="' . $id . '[phenotype][phenotypes-meta][!num][units]"]',
459  ),
460  array(
461  'val-check',
462  '#states',
463  'invisible',
464  0,
465  0,
466  ':input[name="' . $id . '[phenotype][phenotypes-meta][!num][units]"]',
467  ),
468  array(
469  'val-check',
470  '#states',
471  'invisible',
472  0,
473  2,
474  ':input[name="' . $id . '[phenotype][phenotypes-meta][!num][bin-check]"]',
475  ),
476  array(
477  'bin-check',
478  '#states',
479  'invisible',
480  0,
481  0,
482  ':input[name="' . $id . '[phenotype][phenotypes-meta][!num][units]"]',
483  ),
484  array(
485  'bin-check',
486  '#states',
487  'invisible',
488  0,
489  2,
490  ':input[name="' . $id . '[phenotype][phenotypes-meta][!num][val-check]"]',
491  ),
492  array(
493  'struct-other',
494  '#states',
495  'visible',
496  ':input[name="' . $id . '[phenotype][phenotypes-meta][!num][structure]"]',
497  ),
498  array(
499  'min',
500  '#states',
501  'visible',
502  0,
503  0,
504  ':input[name="' . $id . '[phenotype][phenotypes-meta][!num][units]"]',
505  ),
506  array(
507  'min',
508  '#states',
509  'visible',
510  0,
511  2,
512  ':input[name="' . $id . '[phenotype][phenotypes-meta][!num][val-check]"]',
513  ),
514  array(
515  'min',
516  '#states',
517  'visible',
518  0,
519  4,
520  ':input[name="' . $id . '[phenotype][phenotypes-meta][!num][bin-check]"]',
521  ),
522  array(
523  'max',
524  '#states',
525  'visible',
526  0,
527  0,
528  ':input[name="' . $id . '[phenotype][phenotypes-meta][!num][units]"]',
529  ),
530  array(
531  'max',
532  '#states',
533  'visible',
534  0,
535  2,
536  ':input[name="' . $id . '[phenotype][phenotypes-meta][!num][val-check]"]',
537  ),
538  array(
539  'max',
540  '#states',
541  'visible',
542  0,
543  4,
544  ':input[name="' . $id . '[phenotype][phenotypes-meta][!num][bin-check]"]',
545  ),
546  ),
547  ));
548 
549  $phenotypes = tpps_get_ajax_value($form_state, array(
550  $id,
551  'phenotype',
552  'phenotypes-meta',
553  ), NULL);
554  $phenotype_number = tpps_get_ajax_value($form_state, array(
555  $id,
556  'phenotype',
557  'phenotypes-meta',
558  'number',
559  ), NULL);
560  for ($i = 1; $i <= $phenotype_number; $i++) {
561  if (empty($phenotypes[$i])) {
562  continue;
563  }
564  switch ($phenotypes[$i]['attribute']) {
565  case tpps_load_cvterm('alive')->cvterm_id:
566  case tpps_load_cvterm('bent')->cvterm_id:
567  case tpps_load_cvterm('lesioned')->cvterm_id:
568  case tpps_load_cvterm('rough')->cvterm_id:
569  $terms = array(
570  'boolean',
571  );
572  break;
573 
574  case tpps_load_cvterm('age')->cvterm_id:
575  case tpps_load_cvterm('time')->cvterm_id:
576  $terms = array(
577  'day',
578  'year',
579  );
580  break;
581 
582  case tpps_load_cvterm('area')->cvterm_id:
583  $terms = array(
584  'square_micrometer',
585  'square_millimeter',
586  );
587  break;
588 
589  case tpps_load_cvterm('circumference')->cvterm_id:
590  case tpps_load_cvterm('diameter')->cvterm_id:
591  case tpps_load_cvterm('distance')->cvterm_id:
592  case tpps_load_cvterm('height')->cvterm_id:
593  case tpps_load_cvterm('length')->cvterm_id:
594  case tpps_load_cvterm('thickness')->cvterm_id:
595  case tpps_load_cvterm('width')->cvterm_id:
596  $terms = array(
597  'centimeter',
598  'meter',
599  'millimeter',
600  'micrometer',
601  );
602  break;
603 
604  case tpps_load_cvterm('volume')->cvterm_id:
605  $terms = array(
606  'cubic_centimeter',
607  'cubic_meter',
608  'liter',
609  'milliliter',
610  );
611  break;
612 
613  case tpps_load_cvterm('weight')->cvterm_id:
614  $terms = array(
615  'gram',
616  'kilogram',
617  'milligram',
618  );
619  break;
620 
621  case tpps_load_cvterm('temperature')->cvterm_id:
622  $terms = array(
623  'degrees_celsius',
624  'degrees_fahrenheit',
625  );
626  break;
627 
628  case tpps_load_cvterm('pressure')->cvterm_id:
629  $terms = array(
630  'grams_per_square_meter',
631  'pascal',
632  );
633  break;
634 
635  default:
636  $terms = array();
637  break;
638  }
639 
640  $new_options = array();
641  foreach ($terms as $term) {
642  $new_options[tpps_load_cvterm($term)->cvterm_id] = $unit_options[tpps_load_cvterm($term)->cvterm_id];
643  }
644 
645  if (!empty($new_options)) {
646  $new_options['other'] = 'My unit is not in this list';
647  $form[$id]['phenotype']['phenotypes-meta'][$i]['units']['#options'] = $new_options;
648  }
649 
650  if ($phenotypes[$i]['env-check']) {
651  $terms = array(
652  'whole plant' => 'Whole Plant',
653  'soil_type' => 'Soil',
654  'atmosphere' => 'Atmosphere',
655  );
656 
657  $new_options = array();
658  foreach ($terms as $term => $label) {
659  $new_options[tpps_load_cvterm($term)->cvterm_id] = $label;
660  }
661 
662  $form[$id]['phenotype']['phenotypes-meta'][$i]['structure']['#options'] = $new_options;
663  }
664  }
665 
666  $form[$id]['phenotype']['check'] = array(
667  '#type' => 'checkbox',
668  '#title' => t('I would like to upload a phenotype metadata file'),
669  '#attributes' => array(
670  'data-toggle' => array('tooltip'),
671  'data-placement' => array('right'),
672  'title' => array('Upload a file'),
673  ),
674  '#description' => t('We encourage that you only upload a phenotype metadata file if you have > 20 phenotypes. Using the fields above instead of uploading a metadata file allows you to select from standardized controlled vocabulary terms, which makes your data more findable, interoperable, and reusable.'),
675  );
676 
677 
678  $form[$id]['phenotype']['metadata'] = array(
679  '#type' => 'managed_file',
680  '#title' => t('Phenotype Metadata File: Please upload a file containing columns with the name, attribute, structure, description, and units of each of your phenotypes: *'),
681  '#upload_location' => "$phenotype_upload_location",
682  '#upload_validators' => array(
683  'file_validate_extensions' => array('csv tsv xlsx'),
684  ),
685  '#states' => array(
686  'visible' => array(
687  ':input[name="' . $id . '[phenotype][check]"]' => array('checked' => TRUE),
688  ),
689  ),
690  '#tree' => TRUE,
691  );
692 
693  $form[$id]['phenotype']['metadata']['empty'] = array(
694  '#default_value' => isset($values["$id"]['phenotype']['metadata']['empty']) ? $values["$id"]['phenotype']['metadata']['empty'] : 'NA',
695  );
696 
697  $form[$id]['phenotype']['metadata']['columns'] = array(
698  '#description' => t('Please define which columns hold the required data: Phenotype name'),
699  );
700 
701  $column_options = array(
702  'N/A',
703  'Phenotype Name/Identifier',
704  'Attribute',
705  'Description',
706  'Units',
707  'Structure',
708  'Minimum Value',
709  'Maximum Value',
710  );
711 
712  $form[$id]['phenotype']['metadata']['columns-options'] = array(
713  '#type' => 'hidden',
714  '#value' => $column_options,
715  );
716 
717  $form[$id]['phenotype']['metadata']['no-header'] = array();
718 
719  // Get names of manual phenotypes.
720  $meta = tpps_get_ajax_value($form_state, array(
721  $id,
722  'phenotype',
723  'phenotypes-meta',
724  ));
725  $number = tpps_get_ajax_value($form_state, array(
726  $id,
727  'phenotype',
728  'phenotypes-meta',
729  'number',
730  ));
731  $phenotype_names = array();
732  for ($i = 1; $i <= $number; $i++) {
733  if (!empty($meta[$i]['name'])) {
734  $phenotype_names[] = is_array($meta[$i]['name']) ? $meta[$i]['name']['#value'] : $meta[$i]['name'];
735  }
736  }
737 
738  // Get names of phenotypes in metadata file.
739  $columns = tpps_get_ajax_value($form_state, array(
740  $id,
741  'phenotype',
742  'metadata',
743  'columns',
744  ), array(), 'metadata');
745  $meta_fid = tpps_get_ajax_value($form_state, array(
746  $id,
747  'phenotype',
748  'metadata',
749  ));
750  $name_col = NULL;
751  foreach ($columns as $key => $info) {
752  if (preg_match('/^[A-Z]+$/', $key)) {
753  $val = !empty($info['#value']) ? $info['#value'] : $info;
754  if (!empty($val) and $column_options[$val] == 'Phenotype Name/Identifier') {
755  $name_col = $key;
756  break;
757  }
758  }
759  }
760 
761  // Merge names.
762  if (!empty($name_col) and !is_array($meta_fid) and !empty(file_load($meta_fid))) {
763  $names = tpps_parse_file_column($meta_fid, $name_col);
764  $phenotype_names = array_merge($phenotype_names, $names);
765  }
766 
767  // If name ends in 4 digits (year), then time-check default = TRUE.
768  $time_default = NULL;
769  foreach ($phenotype_names as $name) {
770  if (preg_match('/[0-9]{4}$/', $name)) {
771  $time_default = TRUE;
772  }
773  }
774 
775  $form[$id]['phenotype']['time'] = array(
776  '#type' => 'fieldset',
777  '#title' => t('Time options'),
778  );
779 
780  if ($time_default) {
781  $message = t('It looks like some of your phenotypes might be time-based. If this is the case, please indicate which ones are time-based with the section below.');
782  $form[$id]['phenotype']['time']['#prefix'] = "<div class=\"alert alert-block alert-dismissible alert-warning messages warning\">
783  <a class=\"close\" data-dismiss=\"alert\" href=\"#\">×</a>
784  <h4 class=\"element-invisible\">Warning message</h4>
785  {$message}</div>";
786  }
787 
788  $form[$id]['phenotype']['time']['time-check'] = array(
789  '#type' => 'checkbox',
790  '#title' => t('Some of my phenotypes are time-based'),
791  '#default_value' => $time_default,
792  '#ajax' => array(
793  'callback' => 'tpps_update_phenotype',
794  'wrapper' => "phenotype-main-$id",
795  ),
796  );
797 
798  $time_check = tpps_get_ajax_value($form_state, array(
799  $id,
800  'phenotype',
801  'time',
802  'time-check',
803  ), $time_default);
804  if ($time_check) {
805  $time_options = array();
806  foreach ($phenotype_names as $name) {
807  $time_options[strtolower($name)] = $name;
808  }
809  $form[$id]['phenotype']['time']['time_phenotypes'] = array(
810  '#type' => 'checkboxes',
811  '#title' => t('Time-based Phenotypes: *'),
812  '#options' => $time_options,
813  '#description' => t('Please select the phenotypes which are time-based'),
814  );
815 
816  $form[$id]['phenotype']['time']['time_values'] = array(
817  '#type' => 'fieldset',
818  '#title' => t('Phenotype Time values:'),
819  );
820 
821  foreach ($time_options as $key => $name) {
822  $form[$id]['phenotype']['time']['time_values'][$key] = array(
823  '#type' => 'textfield',
824  '#title' => t('(Optional) @name time:', array('@name' => $name)),
825  '#states' => array(
826  'visible' => array(
827  ':input[name="' . $id . '[phenotype][time][time_phenotypes][' . $key . ']"]' => array('checked' => TRUE),
828  ),
829  ),
830  );
831  }
832  }
833  }
834 
835  return $form[$id]['phenotype'];
836 }
837 
849 function tpps_phenotype_number_clear($button_name, $value) {
850  return 0;
851 }
852 
868 function tpps_genotype(array &$form, array &$form_state, array $values, $id) {
869 
870  $genotype_upload_location = 'public://' . variable_get('tpps_genotype_files_dir', 'tpps_genotype');
871 
872  $fields = array(
873  '#type' => 'fieldset',
874  '#title' => t('<div class="fieldset-title">Genotype Information:</div>'),
875  '#collapsible' => TRUE,
876  );
877 
878  tpps_page_4_marker_info($fields, $id);
879 
880  tpps_page_4_ref($fields, $form_state, $id);
881 
882  $marker_parents = array(
883  $id,
884  'genotype',
885  'marker-type',
886  );
887  $parents = array_merge($marker_parents, array('SNPs'));
888  $snps_check = tpps_get_ajax_value($form_state, $parents);
889 
890  $parents = array_merge($marker_parents, array('SSRs/cpSSRs'));
891  $ssrs_check = tpps_get_ajax_value($form_state, $parents);
892 
893  $parents = array_merge($marker_parents, array('Indels'));
894  $indel_check = tpps_get_ajax_value($form_state, $parents);
895 
896  $parents = array_merge($marker_parents, array('Other'));
897  $other_marker_check = tpps_get_ajax_value($form_state, $parents);
898 
899  $fields['files'] = array(
900  '#type' => 'fieldset',
901  '#prefix' => "<div id='$id-genotype-files'>",
902  '#suffix' => '</div>',
903  );
904 
905  if (!empty($ssrs_check)) {
906  $fields['files']['ploidy'] = array(
907  '#type' => 'select',
908  '#title' => t('Ploidy'),
909  '#options' => array(
910  0 => t('- Select -'),
911  'Haploid' => t('Haploid'),
912  'Diploid' => t('Diploid'),
913  'Polyploid' => t('Polyploid'),
914  ),
915  '#ajax' => array(
916  'callback' => 'tpps_genotype_files_callback',
917  'wrapper' => "$id-genotype-files",
918  ),
919  );
920  }
921 
922  $file_type_parents = array(
923  $id,
924  'genotype',
925  'files',
926  'file-type',
927  );
928  $options = array();
929  if (!empty($snps_check)) {
930  $options['SNPs Genotype Assay'] = 'SNPs Genotype Assay';
931  $parents = array_merge($file_type_parents, array('SNPs Genotype Assay'));
932  $snps_assay_check = tpps_get_ajax_value($form_state, $parents);
933 
934  if (!empty($snps_assay_check)) {
935  $options['Assay Design'] = 'Assay Design';
936  }
937  $parents = array_merge($file_type_parents, array('Assay Design'));
938  $assay_design_check = tpps_get_ajax_value($form_state, $parents);
939 
940  if (!empty($snps_assay_check) and !empty($form[$id]['phenotype'])) {
941  $options['SNPs Associations'] = 'SNPs Associations';
942  }
943  $parents = array_merge($file_type_parents, array('SNPs Associations'));
944  $association_check = tpps_get_ajax_value($form_state, $parents);
945  }
946  if (!empty($ssrs_check)) {
947  $options['SSRs/cpSSRs Genotype Spreadsheet'] = 'SSRs/cpSSRs Genotype Spreadsheet';
948  $parents = array_merge($file_type_parents, array('SSRs/cpSSRs Genotype Spreadsheet'));
949  $ssrs_file_check = tpps_get_ajax_value($form_state, $parents);
950  }
951  if (!empty($indel_check)) {
952  $options['Indel Genotype Spreadsheet'] = 'Indel Genotype Spreadsheet';
953  $parents = array_merge($file_type_parents, array('Indel Genotype Spreadsheet'));
954  $indel_file_check = tpps_get_ajax_value($form_state, $parents);
955  }
956  if (!empty($other_marker_check)) {
957  $options['Other Marker Genotype Spreadsheet'] = 'Other Marker Genotype Spreadsheet';
958  $parents = array_merge($file_type_parents, array('Other Marker Genotype Spreadsheet'));
959  $other_file_check = tpps_get_ajax_value($form_state, $parents);
960  }
961  $options['VCF'] = 'VCF';
962 
963  $fields['files']['file-type'] = array(
964  '#type' => 'checkboxes',
965  '#title' => t('Genotype File Types (select all that apply): *'),
966  '#options' => $options,
967  '#ajax' => array(
968  'callback' => 'tpps_genotype_files_callback',
969  'wrapper' => "$id-genotype-files",
970  ),
971  );
972 
973  $parents = array_merge($file_type_parents, array('VCF'));
974  $vcf_file_check = tpps_get_ajax_value($form_state, $parents);
975 
976 
977  if (!empty($snps_assay_check)) {
978  $fields['files']['file-selector'] = array(
979  '#type' => 'checkbox',
980  '#title' => t('Reference Existing SNP File'),
981  '#ajax' => array(
982  'callback' => 'tpps_genotype_files_type_change_callback',
983  'wrapper' => "$id-genotype-files",
984  ),
985  );
986  $file_type_parents = array(
987  $id,
988  'genotype',
989  'files',
990  );
991 
992  $parents = array_merge($file_type_parents, array('file-selector'));
993  $file_selector_check = tpps_get_ajax_value($form_state, $parents);
994 
995  if (empty($file_selector_check)) {
996  $fields['files']['snps-assay'] = array(
997  '#type' => 'managed_file',
998  '#title' => t('SNPs Genotype Assay File: please provide a spreadsheet with columns for the Plant ID of genotypes used in this study: *'),
999  '#upload_location' => "$genotype_upload_location",
1000  '#upload_validators' => array(
1001  'file_validate_extensions' => array('csv tsv xlsx'),
1002  ),
1003  '#description' => t("Please upload a spreadsheet file containing SNP Genotype Assay data. The format of this file is very important! The first column of your file should contain plant identifiers which match the plant identifiers you provided in your plant accession file, and all of the remaining columns should contain SNP data."),
1004  '#tree' => TRUE,
1005  );
1006 
1007  if (isset($fields['files']['snps-assay']['#value']['fid'])) {
1008  $fields['files']['snps-assay']['#default_value'] = $fields['files']['snps-assay']['#value']['fid'];
1009  }
1010  if (!empty($fields['files']['snps-assay']['#default_value']) and ($file = file_load($fields['files']['snps-assay']['#default_value']))) {
1011  // Stop using the file so it can be deleted if the user clicks 'remove'.
1012  file_usage_delete($file, 'tpps', 'tpps_project', substr($form_state['accession'], 4));
1013  }
1014  }
1015  else {
1016  // // Add autocomplete field.
1017  $fields['files']['snps-assay'] = array(
1018  '#type' => 'textfield',
1019  '#title' => t('SNPs Genotype Assay File: please select an already existing spreadsheet with columns for the Plant ID of genotypes used in this study: *'),
1020  '#upload_location' => "$genotype_upload_location",
1021  '#autocomplete_path' => 'snp-assay-file/upload',
1022  '#description' => t("Please select an already existing spreadsheet file containing SNP Genotype Assay data. The format of this file is very important! The first column of your file should contain plant identifiers which match the plant identifiers you provided in your plant accession file, and all of the remaining columns should contain SNP data."),
1023  );
1024  }
1025  }
1026  else {
1027  $fields['files']['snps-assay'] = array(
1028  '#type' => 'managed_file',
1029  '#tree' => TRUE,
1030  '#access' => FALSE,
1031  );
1032  }
1033 
1034  if (!empty($assay_design_check)) {
1035  $design_options = array(0 => '- Select -');
1036  $firstpage = $form_state['saved_values'][TPPS_PAGE_1];
1037  for ($i = 1; $i <= $firstpage['organism']['number']; $i++) {
1038  $parts = explode(" ", $firstpage['organism'][$i]['name']);
1039  $genus = $parts[0];
1040  $query = db_select('chado.organism', 'o');
1041  $query->join('chado.project_organism', 'po', 'o.organism_id = po.organism_id');
1042  $query->join('public.tpps_project_file_managed', 'pf', 'pf.project_id = po.project_id');
1043  $query->join('public.file_managed', 'f', 'f.fid = pf.fid');
1044  $query->join('chado.project', 'p', 'p.project_id = po.project_id');
1045  $query->fields('f');
1046  $query->fields('p');
1047  $query->condition('o.genus', $genus);
1048  $query->condition('f.filename', '%assay_design%', 'ILIKE');
1049  $results = $query->execute();
1050  while (($record = $results->fetchObject())) {
1051  $design_options[$record->fid] = "{$record->filename} (from \"{$record->name}\")";
1052  }
1053  }
1054  $design_options['new'] = 'I would like to upload a new assay design file';
1055  $fields['files']['assay-load'] = array(
1056  '#type' => 'select',
1057  '#title' => 'Genotype Assay Design: *',
1058  '#options' => $design_options,
1059  '#description' => t('Please select an assay design. Some design files from the same genus as this species are available, or you can choose to upload your own assay design file.'),
1060  );
1061 
1062  $fields['files']['assay-design'] = array(
1063  '#type' => 'managed_file',
1064  '#title' => 'Genotype Assay Design File: *',
1065  '#upload_location' => "$genotype_upload_location",
1066  '#upload_validators' => array(
1067  'file_validate_extensions' => array('csv tsv xlsx'),
1068  ),
1069  '#tree' => TRUE,
1070  '#states' => array(
1071  'visible' => array(
1072  ':input[name="' . $id . '[genotype][files][assay-load]"]' => array('value' => 'new'),
1073  ),
1074  ),
1075  );
1076 
1077  if (isset($fields['files']['assay-design']['#value'])) {
1078  $fields['files']['assay-design']['#default_value'] = $fields['files']['assay-design']['#value'];
1079  }
1080  if (!empty($fields['files']['assay-design']['#default_value']) and ($file = file_load($fields['files']['assay-design']['#default_value']))) {
1081  // Stop using the file so it can be deleted if the user clicks 'remove'.
1082  file_usage_delete($file, 'tpps', 'tpps_project', substr($form_state['accession'], 4));
1083  }
1084 
1085  $fields['files']['assay-citation'] = array(
1086  '#type' => 'textfield',
1087  '#title' => t('Genotype Assay Design Citation (Optional):'),
1088  '#description' => t('If your assay design file is from a different paper, please include the citation for that paper here.'),
1089  '#states' => array(
1090  'visible' => array(
1091  ':input[name="' . $id . '[genotype][files][assay-load]"]' => array('value' => 'new'),
1092  ),
1093  ),
1094  );
1095  }
1096  else {
1097  $fields['files']['assay-design'] = array(
1098  '#type' => 'managed_file',
1099  '#tree' => TRUE,
1100  '#access' => FALSE,
1101  );
1102  }
1103 
1104  if (!empty($association_check)) {
1105  $fields['files']['snps-association'] = array(
1106  '#type' => 'managed_file',
1107  '#title' => t('SNPs Association File: *'),
1108  '#upload_location' => $genotype_upload_location,
1109  '#upload_validators' => array(
1110  'file_validate_extensions' => array('csv tsv xlsx'),
1111  ),
1112  '#description' => t('Please upload a spreadsheet file containing SNPs Association data. When your file is uploaded, you will be shown a table with your column header names, several drop-downs, and the first few rows of your file. You will be asked to define the data type for each column, using the drop-downs provided to you. If a column data type does not fit any of the options in the drop-down menu, you may set that drop-down menu to "N/A". Your file must contain columns with the SNP ID, Scaffold, Position (formatted like "start:stop"), Allele (formatted like "major:minor"), Associated Trait Name (must match a phenotype from the above section), and Confidence Value. Optionally, you can also specify a Gene ID (which should match the gene reference) and a SNP Annotation (non synonymous, coding, etc).'),
1113  '#tree' => TRUE,
1114  'empty' => array(
1115  '#default_value' => $values[$id]['genotype']['files']['snps-association']['empty'] ?? 'NA',
1116  ),
1117  'columns' => array(
1118  '#description' => t('Please define which columns hold the required data: SNP ID, Scaffold, Position, Allele, Associated Trait, Confidence Value.'),
1119  ),
1120  'columns-options' => array(
1121  '#type' => 'hidden',
1122  '#value' => array(
1123  'N/A',
1124  'SNP ID',
1125  'Scaffold',
1126  'Position',
1127  'Allele',
1128  'Associated Trait',
1129  'Confidence Value',
1130  'Gene ID',
1131  'Annotation',
1132  ),
1133  'no-header' => array(),
1134  ),
1135  );
1136 
1137  $fields['files']['snps-association-type'] = array(
1138  '#type' => 'select',
1139  '#title' => t('Confidence Value Type: *'),
1140  '#options' => array(
1141  0 => t('- Select -'),
1142  'P value' => t('P value'),
1143  'Genomic Inflation Factor (GIF)' => t('Genomic Inflation Factor (GIF)'),
1144  'P-adjusted (FDR) / Q value' => t('P-adjusted (FDR) / Q value'),
1145  'P-adjusted (FWE)' => t('P-adjusted (FWE)'),
1146  'P-adjusted (Bonferroni)' => t('P-adjusted (Bonferroni)'),
1147  ),
1148  );
1149 
1150  $fields['files']['snps-association-tool'] = array(
1151  '#type' => 'select',
1152  '#title' => t('Association Analysis Tool: *'),
1153  '#options' => array(
1154  0 => t('- Select -'),
1155  'GEMMA' => t('GEMMA'),
1156  'EMMAX' => t('EMMAX'),
1157  'Plink' => t('Plink'),
1158  'Tassel' => t('Tassel'),
1159  'Sambada' => t('Sambada'),
1160  'Bayenv' => t('Bayenv'),
1161  'BayeScan' => t('BayeScan'),
1162  'LFMM' => t('LFMM'),
1163  ),
1164  );
1165 
1166  $fields['files']['snps-pop-struct'] = array(
1167  '#type' => 'managed_file',
1168  '#title' => 'SNPs Population Structure File: ',
1169  '#upload_location' => "$genotype_upload_location",
1170  '#upload_validators' => array(
1171  'file_validate_extensions' => array('csv tsv xlsx'),
1172  ),
1173  '#tree' => TRUE,
1174  );
1175 
1176  if (isset($fields['files']['snps-pop-struct']['#value'])) {
1177  $fields['files']['snps-pop-struct']['#default_value'] = $fields['files']['snps-pop-struct']['#value'];
1178  }
1179  if (!empty($fields['files']['snps-pop-struct']['#default_value']) and ($file = file_load($fields['files']['snps-pop-struct']['#default_value']))) {
1180  // Stop using the file so it can be deleted if the user clicks 'remove'.
1181  file_usage_delete($file, 'tpps', 'tpps_project', substr($form_state['accession'], 4));
1182  }
1183 
1184  $fields['files']['snps-kinship'] = array(
1185  '#type' => 'managed_file',
1186  '#title' => 'SNPs Kinship File: ',
1187  '#upload_location' => "$genotype_upload_location",
1188  '#upload_validators' => array(
1189  'file_validate_extensions' => array('csv tsv xlsx'),
1190  ),
1191  '#tree' => TRUE,
1192  );
1193 
1194  if (isset($fields['files']['snps-kinship']['#value'])) {
1195  $fields['files']['snps-kinship']['#default_value'] = $fields['files']['snps-kinship']['#value'];
1196  }
1197  if (!empty($fields['files']['snps-kinship']['#default_value']) and ($file = file_load($fields['files']['snps-kinship']['#default_value']))) {
1198  // Stop using the file so it can be deleted if the user clicks 'remove'.
1199  file_usage_delete($file, 'tpps', 'tpps_project', substr($form_state['accession'], 4));
1200  }
1201  }
1202  else {
1203  $fields['files']['snps-association'] = array(
1204  '#type' => 'managed_file',
1205  '#tree' => TRUE,
1206  '#access' => FALSE,
1207  );
1208 
1209  $fields['files']['snps-pop-struct'] = array(
1210  '#type' => 'managed_file',
1211  '#tree' => TRUE,
1212  '#access' => FALSE,
1213  );
1214 
1215  $fields['files']['snps-kinship'] = array(
1216  '#type' => 'managed_file',
1217  '#tree' => TRUE,
1218  '#access' => FALSE,
1219  );
1220  }
1221 
1222  if (!empty($ssrs_file_check)) {
1223  $fields['files']['ssrs'] = array(
1224  '#type' => 'managed_file',
1225  '#title' => t('SSRs/cpSSRs Spreadsheet: *'),
1226  '#upload_location' => "$genotype_upload_location",
1227  '#upload_validators' => array(
1228  'file_validate_extensions' => array('csv tsv xlsx'),
1229  ),
1230  '#description' => t('Please upload a spreadsheet containing your SSRs/cpSSRs data. The format of this file is very important! TPPS will parse your file based on the ploidy you have selected above. For any ploidy, TPPS will assume that the first column of your file is the column that holds the Plant Identifier that matches your accession file.'),
1231  '#tree' => TRUE,
1232  'empty' => array(
1233  '#default_value' => isset($values["organism-$id"]['genotype']['files']['ssrs']) ? $values["organism-$id"]['genotype']['files']['ssrs'] : 'NA',
1234  ),
1235  );
1236 
1237  $ploidy = tpps_get_ajax_value($form_state, array(
1238  $id,
1239  'genotype',
1240  'files',
1241  'ploidy',
1242  ));
1243 
1244  switch ($ploidy) {
1245  case 'Haploid':
1246  $fields['files']['ssrs']['#description'] .= ' For haploid, TPPS assumes that each remaining column in the spreadsheet is a marker.';
1247  break;
1248 
1249  case 'Diploid':
1250  $fields['files']['ssrs']['#description'] .= ' For diploid, TPPS will assume that pairs of columns together are describing an individual marker, so the second and third columns would be the first marker, the fourth and fifth columns would be the second marker, etc.';
1251  break;
1252 
1253  case 'Polyploid':
1254  $fields['files']['ssrs']['#description'] .= ' For polyploid, TPPS will read columns until it arrives at a non-empty column with a different name from the last.';
1255  break;
1256 
1257  default:
1258  break;
1259  }
1260 
1261  if (isset($fields['files']['ssrs']['#value']['fid'])) {
1262  $fields['files']['ssrs']['#default_value'] = $fields['files']['ssrs']['#value']['fid'];
1263  }
1264  if (!empty($fields['files']['ssrs']['#default_value']) and ($file = file_load($fields['files']['ssrs']['#default_value']))) {
1265  // Stop using the file so it can be deleted if the user clicks 'remove'.
1266  file_usage_delete($file, 'tpps', 'tpps_project', substr($form_state['accession'], 4));
1267  }
1268 
1269  $fields['files']['ssr-extra-check'] = array(
1270  '#type' => 'checkbox',
1271  '#title' => t('I would like to include an additional SSRs/cpSSRs Spreadsheet (this is typically used when the study includes both SSR and cpSSR data)'),
1272  '#ajax' => array(
1273  'callback' => 'tpps_genotype_files_callback',
1274  'wrapper' => "$id-genotype-files",
1275  ),
1276  );
1277 
1278  $ssrs_extra_check = tpps_get_ajax_value($form_state, array(
1279  $id,
1280  'genotype',
1281  'files',
1282  'ssr-extra-check',
1283  ));
1284 
1285  if ($ssrs_extra_check) {
1286  $fields['files']['extra-ssr-type'] = array(
1287  '#type' => 'textfield',
1288  '#title' => t('Define Additional SSRs/cpSSRs Type: *'),
1289  );
1290 
1291  $fields['files']['extra-ploidy'] = array(
1292  '#type' => 'select',
1293  '#title' => t('Additional SSRs/cpSSRs Ploidy'),
1294  '#options' => array(
1295  0 => t('- Select -'),
1296  'Haploid' => t('Haploid'),
1297  'Diploid' => t('Diploid'),
1298  'Polyploid' => t('Polyploid'),
1299  ),
1300  '#ajax' => array(
1301  'callback' => 'tpps_genotype_files_callback',
1302  'wrapper' => "$id-genotype-files",
1303  ),
1304  );
1305 
1306  $fields['files']['ssrs_extra'] = array(
1307  '#type' => 'managed_file',
1308  '#title' => t('SSRs/cpSSRs Additional Spreadsheet: *'),
1309  '#upload_location' => "$genotype_upload_location",
1310  '#upload_validators' => array(
1311  'file_validate_extensions' => array('csv tsv xlsx'),
1312  ),
1313  '#description' => t('Please upload an additional spreadsheet containing your SSRs/cpSSRs data. The format of this file is very important! TPPS will parse your file based on the ploidy you have selected above. For any ploidy, TPPS will assume that the first column of your file is the column that holds the Plant Identifier that matches your accession file.'),
1314  '#tree' => TRUE,
1315  );
1316 
1317  $extra_ploidy = tpps_get_ajax_value($form_state, array(
1318  $id,
1319  'genotype',
1320  'files',
1321  'extra-ploidy',
1322  ));
1323 
1324  switch ($extra_ploidy) {
1325  case 'Haploid':
1326  $fields['files']['ssrs_extra']['#description'] .= ' For haploid, TPPS assumes that each remaining column in the spreadsheet is a marker.';
1327  break;
1328 
1329  case 'Diploid':
1330  $fields['files']['ssrs_extra']['#description'] .= ' For diploid, TPPS will assume that pairs of columns together are describing an individual marker, so the second and third columns would be the first marker, the fourth and fifth columns would be the second marker, etc.';
1331  break;
1332 
1333  case 'Polyploid':
1334  $fields['files']['ssrs_extra']['#description'] .= ' For polyploid, TPPS will read columns until it arrives at a non-empty column with a different name from the last.';
1335  break;
1336 
1337  default:
1338  break;
1339  }
1340 
1341  if (isset($fields['files']['ssrs_extra']['#value']['fid'])) {
1342  $fields['files']['ssrs_extra']['#default_value'] = $fields['files']['ssrs_extra']['#value']['fid'];
1343  }
1344  if (!empty($fields['files']['ssrs_extra']['#default_value']) and ($file = file_load($fields['files']['ssrs_extra']['#default_value']))) {
1345  // Stop using the file so it can be deleted if the user clicks 'remove'.
1346  file_usage_delete($file, 'tpps', 'tpps_project', substr($form_state['accession'], 4));
1347  }
1348  }
1349  else {
1350  $fields['files']['ssrs-extra'] = array(
1351  '#type' => 'managed_file',
1352  '#tree' => TRUE,
1353  '#access' => FALSE,
1354  );
1355  }
1356  }
1357  else {
1358  $fields['files']['ssrs'] = array(
1359  '#type' => 'managed_file',
1360  '#tree' => TRUE,
1361  '#access' => FALSE,
1362  );
1363 
1364  $fields['files']['ssrs-extra'] = array(
1365  '#type' => 'managed_file',
1366  '#tree' => TRUE,
1367  '#access' => FALSE,
1368  );
1369  }
1370 
1371  if (!empty($indel_file_check)) {
1372  $fields['files']['indels'] = array(
1373  '#type' => 'managed_file',
1374  '#title' => t('Indel Genotype Spreadsheet: *'),
1375  '#upload_location' => "$genotype_upload_location",
1376  '#upload_validators' => array(
1377  'file_validate_extensions' => array('csv tsv xlsx'),
1378  ),
1379  '#description' => t('Please upload a spreadsheet containing your Indels data. The first column of your file should contain plant identifiers which match the plant identifiers you provided in your plant accession file, and all of the remaining columns should contain Indel data.'),
1380  '#tree' => TRUE,
1381  );
1382 
1383  if (isset($fields['files']['indels']['#value']['fid'])) {
1384  $fields['files']['indels']['#default_value'] = $fields['files']['indels']['#value']['fid'];
1385  }
1386  if (!empty($fields['files']['indels']['#default_value']) and ($file = file_load($fields['files']['indels']['#default_value']))) {
1387  // Stop using the file so it can be deleted if the user clicks 'remove'.
1388  file_usage_delete($file, 'tpps', 'tpps_project', substr($form_state['accession'], 4));
1389  }
1390  }
1391  else {
1392  $fields['files']['indels'] = array(
1393  '#type' => 'managed_file',
1394  '#tree' => TRUE,
1395  '#access' => FALSE,
1396  );
1397  }
1398 
1399  if (!empty($other_file_check)) {
1400  $fields['files']['other'] = array(
1401  '#type' => 'managed_file',
1402  '#title' => t('Other Marker Genotype Spreadsheet: please provide a spreadsheet with columns for the Plant ID of genotypes used in this study: *'),
1403  '#upload_location' => "$genotype_upload_location",
1404  '#upload_validators' => array(
1405  'file_validate_extensions' => array('csv tsv xlsx'),
1406  ),
1407  '#description' => t('Please upload a spreadsheet file containing Genotype data. When your file is uploaded, you will be shown a table with your column header names, several drop-downs, and the first few rows of your file. You will be asked to define the data type for each column, using the drop-downs provided to you. If a column data type does not fit any of the options in the drop-down menu, you may set that drop-down menu to "N/A". Your file must contain one column with the Plant Identifier.'),
1408  '#tree' => TRUE,
1409  );
1410 
1411  $fields['files']['other']['empty'] = array(
1412  '#default_value' => $values[$id]['genotype']['files']['other']['empty'] ?? 'NA',
1413  );
1414 
1415  $default_dynamic = !empty($form_state['saved_values'][TPPS_PAGE_4][$id]['genotype']['files']['other-columns']);
1416  $fields['files']['other']['dynamic'] = array(
1417  '#type' => 'checkbox',
1418  '#title' => t('This file needs dynamic dropdown options for column data type specification'),
1419  '#ajax' => array(
1420  'wrapper' => "edit-$id-genotype-files-other-ajax-wrapper",
1421  'callback' => 'tpps_page_4_file_dynamic',
1422  ),
1423  '#default_value' => $default_dynamic,
1424  );
1425 
1426  $dynamic = tpps_get_ajax_value($form_state, array(
1427  $id,
1428  'genotype',
1429  'files',
1430  'other',
1431  'dynamic',
1432  ), $default_dynamic, 'other');
1433  if ($dynamic) {
1434  $fields['files']['other']['columns'] = array(
1435  '#description' => t('Please define which columns hold the required data: Plant Identifier, Genotype Data'),
1436  );
1437 
1438  $fields['files']['other']['columns-options'] = array(
1439  '#type' => 'hidden',
1440  '#value' => array(
1441  'Genotype Data',
1442  'Plant Identifier',
1443  'N/A',
1444  ),
1445  );
1446  }
1447 
1448  $fields['files']['other']['no-header'] = array();
1449  }
1450  else {
1451  $fields['files']['other'] = array(
1452  '#type' => 'managed_file',
1453  '#tree' => TRUE,
1454  '#access' => FALSE,
1455  );
1456  }
1457 
1458  if (!empty($vcf_file_check)) {
1459  $fields['files']['vcf'] = array(
1460  '#type' => 'managed_file',
1461  '#title' => t('Genotype VCF File: *'),
1462  '#upload_location' => "$genotype_upload_location",
1463  '#upload_validators' => array(
1464  'file_validate_extensions' => array('gz tar zip'),
1465  ),
1466  '#tree' => TRUE,
1467  '#states' => array(
1468  'visible' => array(
1469  ':input[name="' . $id . '[genotype][files][local_vcf_check]"]' => array('checked' => FALSE),
1470  ),
1471  ),
1472  );
1473 
1474  if (isset($fields['files']['vcf']['#value'])) {
1475  $fields['files']['vcf']['#default_value'] = $fields['files']['vcf']['#value'];
1476  }
1477  if (!empty($fields['files']['vcf']['#default_value']) and ($file = file_load($fields['files']['vcf']['#default_value']))) {
1478  // Stop using the file so it can be deleted if the user clicks 'remove'.
1479  file_usage_delete($file, 'tpps', 'tpps_project', substr($form_state['accession'], 4));
1480  }
1481 
1482  if (isset($form_state['tpps_type']) and $form_state['tpps_type'] == 'tppsc') {
1483  global $base_url;
1484  $parts = explode('://', $base_url);
1485  $hostname = $parts[1];
1486  $fields['files']['local_vcf_check'] = array(
1487  '#type' => 'checkbox',
1488  '#title' => t("My VCF file is stored locally on @hostname", array('@hostname' => $hostname)),
1489  );
1490 
1491  $fields['files']['local_vcf'] = array(
1492  '#type' => 'textfield',
1493  '#title' => t('Path to local VCF File: *'),
1494  '#states' => array(
1495  'visible' => array(
1496  ':input[name="' . $id . '[genotype][files][local_vcf_check]"]' => array('checked' => TRUE),
1497  ),
1498  ),
1499  '#description' => t("Please provide the full path to your vcf file stored locally on @hostname", array('@hostname' => $hostname)),
1500  );
1501  }
1502  }
1503  else {
1504  $fields['files']['vcf'] = array(
1505  '#type' => 'managed_file',
1506  '#tree' => TRUE,
1507  '#access' => FALSE,
1508  );
1509  }
1510 
1511  return $fields;
1512 }
1513 
1527 function tpps_environment(array &$form, array &$form_state, $id) {
1528  $cartogratree_env = variable_get('tpps_cartogratree_env', FALSE);
1529 
1530  $form[$id]['environment'] = array(
1531  '#type' => 'fieldset',
1532  '#title' => t('<div class="fieldset-title">Environmental Information:</div>'),
1533  '#collapsible' => TRUE,
1534  '#tree' => TRUE,
1535  );
1536 
1537  if ($cartogratree_env and db_table_exists('cartogratree_groups') and db_table_exists('cartogratree_layers') and db_table_exists('cartogratree_fields')) {
1538 
1539  $query = db_select('variable', 'v')
1540  ->fields('v')
1541  ->condition('name', db_like('tpps_layer_group_') . '%', 'LIKE');
1542 
1543  $results = $query->execute();
1544  $options = array();
1545 
1546  while (($result = $results->fetchObject())) {
1547  $group_id = substr($result->name, 17);
1548  $group = db_select('cartogratree_groups', 'g')
1549  ->fields('g', array('group_id', 'group_name'))
1550  ->condition('group_id', $group_id)
1551  ->execute()
1552  ->fetchObject();
1553  $group_is_enabled = variable_get("tpps_layer_group_$group_id", FALSE);
1554 
1555  if ($group_is_enabled) {
1556  if ($group->group_name == 'WorldClim v.2 (WorldClim)') {
1557  $subgroups_query = db_select('cartogratree_layers', 'c')
1558  ->distinct()
1559  ->fields('c', array('subgroup_id'))
1560  ->condition('c.group_id', $group_id)
1561  ->execute();
1562  while (($subgroup = $subgroups_query->fetchObject())) {
1563  $subgroup_title = db_select('cartogratree_subgroups', 's')
1564  ->fields('s', array('subgroup_name'))
1565  ->condition('subgroup_id', $subgroup->subgroup_id)
1566  ->execute()
1567  ->fetchObject()->subgroup_name;
1568  $options["worldclim_subgroup_{$subgroup->subgroup_id}"] = array(
1569  'group_id' => $group_id,
1570  'group' => $group->group_name,
1571  'title' => $subgroup_title,
1572  'params' => NULL,
1573  );
1574  }
1575  }
1576  else {
1577  $layers_query = db_select('cartogratree_layers', 'c')
1578  ->fields('c', array('title', 'group_id', 'layer_id'))
1579  ->condition('c.group_id', $group_id);
1580  $layers_results = $layers_query->execute();
1581  while (($layer = $layers_results->fetchObject())) {
1582  $params_query = db_select('cartogratree_fields', 'f')
1583  ->fields('f', array('display_name', 'field_id'))
1584  ->condition('f.layer_id', $layer->layer_id);
1585  $params_results = $params_query->execute();
1586  $params = array();
1587  while (($param = $params_results->fetchObject())) {
1588  $params[$param->field_id] = $param->display_name;
1589  }
1590  $options[$layer->layer_id] = array(
1591  'group_id' => $layer->group_id,
1592  'group' => $group->group_name,
1593  'title' => $layer->title,
1594  'params' => $params,
1595  );
1596  }
1597  }
1598  }
1599  }
1600 
1601  $form[$id]['environment']['env_layers_groups'] = array(
1602  '#type' => 'fieldset',
1603  '#title' => 'CartograPlant Environmental Layer Groups: *',
1604  '#collapsible' => TRUE,
1605  );
1606 
1607  $form[$id]['environment']['layer_search'] = array(
1608  '#type' => 'textfield',
1609  '#title' => t('Layers Search'),
1610  '#description' => t('You can use this field to filter the layers in the following section.'),
1611  );
1612 
1613  $form[$id]['environment']['env_layers'] = array(
1614  '#type' => 'fieldset',
1615  '#title' => 'CartograPlant Environmental Layers: *',
1616  '#collapsible' => TRUE,
1617  );
1618 
1619  $form[$id]['environment']['env_params'] = array(
1620  '#type' => 'fieldset',
1621  '#title' => 'CartograPlant Environmental Layer Parameters: *',
1622  '#collapsible' => TRUE,
1623  );
1624 
1625  foreach ($options as $layer_id => $layer_info) {
1626  $layer_title = $layer_info['title'];
1627  $layer_group = $layer_info['group'];
1628  $layer_params = $layer_info['params'];
1629 
1630  $form[$id]['environment']['env_layers_groups'][$layer_group] = array(
1631  '#type' => 'checkbox',
1632  '#title' => $layer_group,
1633  '#return_value' => $layer_info['group_id'],
1634  );
1635 
1636  $form[$id]['environment']['env_layers'][$layer_title] = array(
1637  '#type' => 'checkbox',
1638  '#title' => "<strong>$layer_title</strong> - $layer_group",
1639  '#states' => array(
1640  'visible' => array(
1641  ':input[name="' . $id . '[environment][env_layers_groups][' . $layer_group . ']"]' => array('checked' => TRUE),
1642  ),
1643  ),
1644  '#return_value' => $layer_id,
1645  );
1646 
1647  if (!empty($layer_params)) {
1648  $form[$id]['environment']['env_params']["$layer_title"] = array(
1649  '#type' => 'fieldset',
1650  '#title' => "$layer_title Parameters",
1651  '#description' => t('Please select the parameters you used from the @title layer.', array('@title' => $layer_title)),
1652  '#states' => array(
1653  'visible' => array(
1654  ':input[name="' . $id . '[environment][env_layers_groups][' . $layer_group . ']"]' => array('checked' => TRUE),
1655  ':input[name="' . $id . '[environment][env_layers][' . $layer_title . ']"]' => array('checked' => TRUE),
1656  ),
1657  ),
1658  );
1659 
1660  foreach ($layer_params as $param_id => $param) {
1661  $form[$id]['environment']['env_params']["$layer_title"][$param] = array(
1662  '#type' => 'checkbox',
1663  '#title' => $param,
1664  '#return_value' => $param_id,
1665  );
1666  }
1667  }
1668  }
1669 
1670  $form[$id]['environment']['env_layers']['other'] = array(
1671  '#type' => 'checkbox',
1672  '#title' => "<strong>Other custom layer</strong>",
1673  '#return_value' => 'other',
1674  );
1675 
1676  $form[$id]['environment']['env_layers']['other_db'] = array(
1677  '#type' => 'textfield',
1678  '#title' => t('Layer DB URL: *'),
1679  '#description' => t('The url of the DB providing this layer'),
1680  '#states' => array(
1681  'visible' => array(
1682  ':input[name="' . $id . '[environment][env_layers][other]"]' => array('checked' => TRUE),
1683  ),
1684  ),
1685  );
1686 
1687  $form[$id]['environment']['env_layers']['other_name'] = array(
1688  '#type' => 'textfield',
1689  '#title' => t('Layer Name: *'),
1690  '#description' => t('The name of the layer'),
1691  '#states' => array(
1692  'visible' => array(
1693  ':input[name="' . $id . '[environment][env_layers][other]"]' => array('checked' => TRUE),
1694  ),
1695  ),
1696  );
1697 
1698  $form[$id]['environment']['env_layers']['other_params'] = array(
1699  '#type' => 'textfield',
1700  '#title' => t('Parameters Used: *'),
1701  '#description' => t('Comma-delimited list of parameters from the layer used. For example, when using parameters "rainfall" and "humidity", this field should look something like "rainfall,humidity"'),
1702  '#states' => array(
1703  'visible' => array(
1704  ':input[name="' . $id . '[environment][env_layers][other]"]' => array('checked' => TRUE),
1705  ),
1706  ),
1707  );
1708  }
1709 
1710  return $form[$id]['environment'];
1711 }
1712 
1726 function tpps_page_4_ref(array &$fields, array &$form_state, $id) {
1727  global $user;
1728  $uid = $user->uid;
1729 
1730  $options = array(
1731  'key' => 'filename',
1732  'recurse' => FALSE,
1733  );
1734 
1735  $genome_dir = variable_get('tpps_local_genome_dir', NULL);
1736  $ref_genome_arr = array();
1737  $ref_genome_arr[0] = '- Select -';
1738 
1739  if ($genome_dir) {
1740  $existing_genomes = array();
1741  $results = file_scan_directory($genome_dir, '/^([A-Z][a-z]{3})$/', $options);
1742  $code_cvterm = tpps_load_cvterm('organism 4 letter code')->cvterm_id;
1743  foreach ($results as $key => $value) {
1744  $org_id_query = chado_select_record('organismprop', array('organism_id'), array(
1745  'value' => $key,
1746  'type_id' => $code_cvterm,
1747  ));
1748 
1749  if (!empty($org_id_query)) {
1750  $org_query = chado_select_record('organism', array('genus', 'species'), array(
1751  'organism_id' => current($org_id_query)->organism_id,
1752  ));
1753  $result = current($org_query);
1754 
1755  $versions = file_scan_directory("$genome_dir/$key", '/^v([0-9]|.)+$/', $options);
1756  foreach ($versions as $item) {
1757  $opt_string = $result->genus . " " . $result->species . " " . $item->filename;
1758  $existing_genomes[$opt_string] = $opt_string;
1759  }
1760  }
1761  }
1762  ksort($existing_genomes);
1763  $ref_genome_arr += $existing_genomes;
1764  }
1765 
1766  $ref_genome_arr["url"] = 'I can provide a URL to the website of my reference file(s)';
1767  $ref_genome_arr["bio"] = 'I can provide a GenBank accession number (BioProject, WGS, TSA) and select assembly file(s) from a list';
1768  $ref_genome_arr["manual"] = 'I can upload my own reference genome file';
1769  $ref_genome_arr["manual2"] = 'I can upload my own reference transcriptome file';
1770  $ref_genome_arr["none"] = 'I am unable to provide a reference assembly';
1771 
1772  $fields['ref-genome'] = array(
1773  '#type' => 'select',
1774  '#title' => t('Reference Assembly used: *'),
1775  '#options' => $ref_genome_arr,
1776  );
1777 
1778  require_once drupal_get_path('module', 'tripal') . '/includes/tripal.importer.inc';
1779  $class = 'EutilsImporter';
1780  tripal_load_include_importer_class($class);
1781  $eutils = tripal_get_importer_form(array(), $form_state, $class);
1782  $eutils['#type'] = 'fieldset';
1783  $eutils['#title'] = 'Tripal Eutils BioProject Loader';
1784  $eutils['#states'] = array(
1785  'visible' => array(
1786  ':input[name="' . $id . '[genotype][ref-genome]"]' => array('value' => 'bio'),
1787  ),
1788  );
1789  $eutils['accession']['#description'] = t('Valid examples: 12384, 394253, 66853, PRJNA185471');
1790  $eutils['db'] = array(
1791  '#type' => 'hidden',
1792  '#value' => 'bioproject',
1793  );
1794  unset($eutils['options']);
1795  $eutils['options']['linked_records'] = array(
1796  '#type' => 'hidden',
1797  '#value' => 1,
1798  );
1799  $eutils['callback']['#ajax'] = array(
1800  'callback' => 'tpps_ajax_bioproject_callback',
1801  'wrapper' => "$id-tripal-eutils",
1802  );
1803  $eutils['#prefix'] = "<div id=\"$id-tripal-eutils\">";
1804  $eutils['#suffix'] = '</div>';
1805 
1806  if (!empty($form_state['values'][$id]['genotype']['tripal_eutils'])) {
1807  $eutils_vals = $form_state['values'][$id]['genotype']['tripal_eutils'];
1808  if (!empty($eutils_vals['accession']) and !empty($eutils_vals['db'])) {
1809  $connection = new \EUtils();
1810  try {
1811  $connection->setPreview(TRUE);
1812  $eutils['data'] = $connection->get($eutils_vals['db'], $eutils_vals['accession']);
1813  foreach ($_SESSION['messages']['status'] as $key => $message) {
1814  if ($message == '<pre>biosample</pre>') {
1815  unset($_SESSION['messages']['status'][$key]);
1816  if (empty($_SESSION['messages']['status'])) {
1817  unset($_SESSION['messages']['status']);
1818  }
1819  break;
1820  }
1821  }
1822  }
1823  catch (\Exception $e) {
1824  tripal_set_message($e->getMessage(), TRIPAL_ERROR);
1825  }
1826  }
1827  }
1828  unset($eutils['button']);
1829  unset($eutils['instructions']);
1830  $fields['tripal_eutils'] = $eutils;
1831 
1832  $class = 'FASTAImporter';
1833  tripal_load_include_importer_class($class);
1834  $tripal_upload_location = "public://tripal/users/$uid";
1835 
1836  $fasta = tripal_get_importer_form(array(), $form_state, $class);
1837  $fasta['#type'] = 'fieldset';
1838  $fasta['#title'] = 'Tripal FASTA Loader';
1839  $fasta['#states'] = array(
1840  'visible' => array(
1841  array(
1842  array(':input[name="' . $id . '[genotype][ref-genome]"]' => array('value' => 'url')),
1843  'or',
1844  array(':input[name="' . $id . '[genotype][ref-genome]"]' => array('value' => 'manual')),
1845  'or',
1846  array(':input[name="' . $id . '[genotype][ref-genome]"]' => array('value' => 'manual2')),
1847  ),
1848  ),
1849  );
1850 
1851  unset($fasta['file']['file_local']);
1852  unset($fasta['organism_id']);
1853  unset($fasta['method']);
1854  unset($fasta['match_type']);
1855  $db = $fasta['additional']['db'];
1856  unset($fasta['additional']);
1857  $fasta['db'] = $db;
1858  $fasta['db']['#collapsible'] = TRUE;
1859  unset($fasta['button']);
1860 
1861  $upload = array(
1862  '#type' => 'managed_file',
1863  '#title' => '',
1864  '#description' => t('Remember to click the "Upload" button below to send your file to the server. This interface is capable of uploading very large files. If you are disconnected you can return, reload the file and it will resume where it left off. Once the file is uploaded the "Upload Progress" will indicate "Complete". If the file is already present on the server then the status will quickly update to "Complete".'),
1865  '#upload_validators' => array(
1866  'file_validate_extensions' => array(implode(' ', $class::$file_types)),
1867  ),
1868  '#upload_location' => $tripal_upload_location,
1869  );
1870 
1871  $fasta['file']['file_upload'] = $upload;
1872  $fasta['analysis_id']['#required'] = $fasta['seqtype']['#required'] = FALSE;
1873  $fasta['file']['file_upload']['#states'] = $fasta['file']['file_upload_existing']['#states'] = array(
1874  'visible' => array(
1875  array(
1876  array(':input[name="' . $id . '[genotype][ref-genome]"]' => array('value' => 'manual')),
1877  'or',
1878  array(':input[name="' . $id . '[genotype][ref-genome]"]' => array('value' => 'manual2')),
1879  ),
1880  ),
1881  );
1882  $fasta['file']['file_remote']['#states'] = array(
1883  'visible' => array(
1884  ':input[name="]' . $id . '[genotype][ref-genome]"]' => array('value' => 'url'),
1885  ),
1886  );
1887 
1888  $fields['tripal_fasta'] = $fasta;
1889 }
1890 
1899 function tpps_page_4_marker_info(array &$fields, $id) {
1900 
1901  $fields['marker-type'] = array(
1902  '#type' => 'checkboxes',
1903  '#title' => t('Marker Type (select all that apply): *'),
1904  '#options' => drupal_map_assoc(array(
1905  t('SNPs'),
1906  t('SSRs/cpSSRs'),
1907  t('Indels'),
1908  t('Other'),
1909  )),
1910  );
1911 
1912  $fields['marker-type']['#ajax'] = array(
1913  'callback' => 'tpps_genotype_files_callback',
1914  'wrapper' => "$id-genotype-files",
1915  );
1916 
1917  $fields['SNPs'] = array(
1918  '#type' => 'fieldset',
1919  '#title' => t('<div class="fieldset-title">SNPs Information:</div>'),
1920  '#states' => array(
1921  'visible' => array(
1922  ':input[name="' . $id . '[genotype][marker-type][SNPs]"]' => array('checked' => TRUE),
1923  ),
1924  ),
1925  '#collapsible' => TRUE,
1926  );
1927 
1928  $fields['SNPs']['genotyping-design'] = array(
1929  '#type' => 'select',
1930  '#title' => t('Define Experimental Design: *'),
1931  '#options' => array(
1932  0 => t('- Select -'),
1933  1 => t('GBS'),
1934  2 => t('Targeted Capture'),
1935  3 => t('Whole Genome Resequencing'),
1936  4 => t('RNA-Seq'),
1937  5 => t('Genotyping Array'),
1938  ),
1939  );
1940 
1941  $fields['SNPs']['GBS'] = array(
1942  '#type' => 'select',
1943  '#title' => t('GBS Type: *'),
1944  '#options' => array(
1945  0 => t('- Select -'),
1946  1 => t('RADSeq'),
1947  2 => t('ddRAD-Seq'),
1948  3 => t('NextRAD'),
1949  4 => t('RAPTURE'),
1950  5 => t('Other'),
1951  ),
1952  '#states' => array(
1953  'visible' => array(
1954  ':input[name="' . $id . '[genotype][SNPs][genotyping-design]"]' => array('value' => '1'),
1955  ),
1956  ),
1957  );
1958 
1959  $fields['SNPs']['GBS-other'] = array(
1960  '#type' => 'textfield',
1961  '#states' => array(
1962  'visible' => array(
1963  ':input[name="' . $id . '[genotype][SNPs][GBS]"]' => array('value' => '5'),
1964  ':input[name="' . $id . '[genotype][SNPs][genotyping-design]"]' => array('value' => '1'),
1965  ),
1966  ),
1967  );
1968 
1969  $fields['SNPs']['targeted-capture'] = array(
1970  '#type' => 'select',
1971  '#title' => t('Targeted Capture Type: *'),
1972  '#options' => array(
1973  0 => t('- Select -'),
1974  1 => t('Exome Capture'),
1975  2 => t('Other'),
1976  ),
1977  '#states' => array(
1978  'visible' => array(
1979  ':input[name="' . $id . '[genotype][SNPs][genotyping-design]"]' => array('value' => '2'),
1980  ),
1981  ),
1982  );
1983 
1984  $fields['SNPs']['targeted-capture-other'] = array(
1985  '#type' => 'textfield',
1986  '#states' => array(
1987  'visible' => array(
1988  ':input[name="' . $id . '[genotype][SNPs][targeted-capture]"]' => array('value' => '2'),
1989  ':input[name="' . $id . '[genotype][SNPs][genotyping-design]"]' => array('value' => '2'),
1990  ),
1991  ),
1992  );
1993 
1994  $fields['SSRs/cpSSRs'] = array(
1995  '#type' => 'textfield',
1996  '#title' => t('Define SSRs/cpSSRs Type: *'),
1997  '#states' => array(
1998  'visible' => array(
1999  ':input[name="' . $id . '[genotype][marker-type][SSRs/cpSSRs]"]' => array('checked' => TRUE),
2000  ),
2001  ),
2002  );
2003 
2004  $fields['other-marker'] = array(
2005  '#type' => 'textfield',
2006  '#title' => t('Define Other Marker Type: *'),
2007  '#states' => array(
2008  'visible' => array(
2009  ':input[name="' . $id . '[genotype][marker-type][Other]"]' => array('checked' => TRUE),
2010  ),
2011  ),
2012  );
2013 }
const TPPS_PAGE_1
Definition: tpps.module:12
tpps_genotype(array &$form, array &$form_state, array $values, $id)
tpps_get_ajax_value(array &$state, array $parents, $default=NULL, $file_name="")
Definition: form_utils.inc:236
tpps_dynamic_list(array &$form, array &$form_state, $id, array $repeat, array $options=array())
Definition: form_utils.inc:29
tpps_environment(array &$form, array &$form_state, $id)
tpps_phenotype(array &$form, array &$form_state, array $values, $id)
tpps_phenotype_number_clear($button_name, $value)
tpps_page_4_marker_info(array &$fields, $id)
tpps_parse_file_column($fid, $column, $no_header=FALSE)
Definition: file_utils.inc:334
const TPPS_PAGE_4
Definition: tpps.module:15
tpps_load_cvterm($term, array $options=array(), $version=NULL, $refresh_cache=FALSE)
tpps_page_4_ref(array &$fields, array &$form_state, $id)