#!/usr/bin/perl

=head1
GenotypeStorageTest.pl - testing genotype storage

=head1 SYNOPSIS
    perl GenotypeStorageTest.pl -H localhost -D fixture -U postgres -c cache/ -s tmp/ -b Slurm -h localhost -w batch -p /home/production/cxgn/sgn -g /tmp/tmp_grm.txt
    perl GenotypeStorageTest.pl -H localhost -D genotype_test -U postgres -c /home/nmorales/Documents/work_scripts/temp_cache/ -s /home/nmorales/Documents/work_scripts/temp_dir/ -b Slurm -h localhost -w batch -p /home/nmorales/cxgn/sgn -g /home/nmorales/Documents/work_scripts/temp_dir/grm 2>&1 | tee GenotypeStorageTestOutput.txt
=head1 COMMAND-LINE OPTIONS
  ARGUMENTS
 -H host name (required) e.g. "localhost"
 -D database name (required) e.g. "cxgn_cassava"
 -U database username (required)
 -c cache root directory
 -s shared cluster temp directory
 -b backend: Slurm manager
 -h cluster host
 -w web cluster queue
 -p basepath where application runs from
 -g tempfile for genomic relationship matrix (GRM)

=head1 DESCRIPTION
This script tests the genotype storage

=head1 AUTHOR
 Nicolas Morales (nm529@cornell.edu)
=cut

use strict;

use Getopt::Std;
use Data::Dumper;
use JSON::Any;
use JSON::PP;
use Carp qw /croak/ ;
use Try::Tiny;
use Pod::Usage;

use Bio::Chado::Schema;
use CXGN::Metadata::Schema;
use CXGN::Phenome::Schema;
use CXGN::People::Schema;
use CXGN::People::Person;
use CXGN::DB::InsertDBH;
use SGN::Model::Cvterm;
use CXGN::Genotype::DownloadFactory;
use CXGN::Phenotypes::SearchFactory;
use CXGN::Genotype::GRM;
use CXGN::Genotype::GWAS;
use CXGN::Genotype::Protocol;
use Statistics::Basic qw(:all);
use List::Util qw(shuffle);
use Time::HiRes;
use CXGN::Dataset::Cache;

our ($opt_H, $opt_D, $opt_U, $opt_c, $opt_s, $opt_b, $opt_h, $opt_w, $opt_p, $opt_g);

getopts('H:U:D:c:s:b:h:w:p:g:');

print "Password for $opt_H / $opt_D: \n";
my $pw = <>;
chomp($pw);

print STDERR "Connecting to database schemas...\n";
my $dsn = 'dbi:Pg:database='.$opt_D.";host=".$opt_H.";port=5432";
my $schema = Bio::Chado::Schema->connect($dsn, $opt_U, $pw);
$schema->storage->dbh->do('SET search_path TO public,sgn');
my $dbh = $schema->storage->dbh;
my $metadata_schema = CXGN::Metadata::Schema->connect($dsn, $opt_U, $pw);
$metadata_schema->storage->dbh->do('SET search_path TO metadata');
my $phenome_schema = CXGN::Phenome::Schema->connect($dsn, $opt_U, $pw);
$phenome_schema->storage->dbh->do('SET search_path TO phenome');
my $people_schema = CXGN::People::Schema->connect($dsn, $opt_U, $pw);
$people_schema->storage->dbh->do('SET search_path TO sgn_people');

# Four datasets are used in this test:
# (1) Musa acuminata triploid accessions. 142,119 GBS markers for 314 accessions. 75 phenotypic traits across 3 field trial experiments.
# (2) Zea mays hybrid diploid accessions. These hybrids were from crosses of a parental population that was genotyped. The hybrids were evaluated in field experiments. This test will calculate the genotypes for the hybrids from the parents. 955,690 GBS markers for 1,325 parental accessions. 14 phenotypic traits across 3 field trial experiments.
# (3) Manihot esculenta diploid accessions. 287,952 GBS markers for 924 accessions. 18 phenotypic traits across 3 field trial experiments.
# (4) Zea mays diploid accessions. 955,690 GBS markers for 1,325 accessions. 14 phenotypic traits across 3 field trial experiments.

# Here the test datasets are defined with traits and accessions, and whether to compute genotypes from parents or not.
my $genotyping_protocol_names = [
    {
        name => "GenoProtMusa",
        compute_from_parents => 0,
        traits => ["Bunch position 1-5|cycle 1|COMP:0000014","Bunch position 1-5|cycle 2|COMP:0000016","Bunch position 1-5|cycle 3|COMP:0000017","Bunch weight in kg|cycle 1|COMP:0000018","Bunch weight in kg|cycle 2|COMP:0000020","Bunch weight in kg|cycle 3|COMP:0000021","Days from flowering to harvest|cycle 1|COMP:0000022","Days from flowering to harvest|cycle 2|COMP:0000024","Days from flowering to harvest|cycle 3|COMP:0000025","Days from planting to shooting in days|cycle 1|COMP:0000026","Days from planting to shooting in days|cycle 2|COMP:0000028","Days from planting to shooting in days|cycle 3|COMP:0000029","Finger circumference in cm|cycle 1|COMP:0000030","Finger circumference in cm|cycle 2|COMP:0000032","Finger circumference in cm|cycle 3|COMP:0000033","Finger external length in cm|cycle 1|COMP:0000034","Finger external length in cm|cycle 2|COMP:0000036","Finger external length in cm|cycle 3|COMP:0000037","Finger lateral diameter in cm|cycle 1|COMP:0000038","Finger lateral diameter in cm|cycle 2|COMP:0000040","Finger lateral diameter in cm|cycle 3|COMP:0000041","Fruit pulp lateral diameter in cm|cycle 1|COMP:0000042","Fruit pulp lateral diameter in cm|cycle 2|COMP:0000044","Fruit pulp lateral diameter in cm|cycle 3|COMP:0000045","Index of non-spotted leaves: calculation|cycle 1|COMP:0000046","Index of non-spotted leaves: calculation|cycle 2|COMP:0000048","Index of non-spotted leaves: calculation|cycle 3|COMP:0000049","Number of fingers in bunch: count|cycle 1|COMP:0000050","Number of fingers in bunch: count|cycle 2|COMP:0000052","Number of fingers in bunch: count|cycle 3|COMP:0000053","Number of functional leaves: count|cycle 1|harvesting|COMP:0000054","Number of functional leaves: count|cycle 1|shooting|COMP:0000056","Number of functional leaves: count|cycle 2|harvesting|COMP:0000057","Number of functional leaves: count|cycle 2|shooting|COMP:0000058","Number of functional leaves: count|cycle 3|harvesting|COMP:0000059","Number of functional leaves: count|cycle 3|shooting|COMP:0000062","Number of hands in bunch: count|cycle 1|COMP:0000060","Number of hands in bunch: count|cycle 2|COMP:0000063","Number of hands in bunch: count|cycle 3|COMP:0000064","Number of maiden suckers: count|cycle 1|COMP:0000065","Number of maiden suckers: count|cycle 2|COMP:0000067","Number of maiden suckers: count|cycle 3|COMP:0000068","Number of peeper suckers: count|cycle 1|COMP:0000069","Number of peeper suckers: count|cycle 2|COMP:0000071","Number of peeper suckers: count|cycle 3|COMP:0000072","Number of sword suckers: count|cycle 1|COMP:0000073","Number of sword suckers: count|cycle 2|COMP:0000075","Number of sword suckers: count|cycle 3|COMP:0000076","Plant circumference|cycle 1|COMP:0000103","Plant circumference|cycle 2|COMP:0000105","Plant circumference|cycle 3|COMP:0000106","Plant height in cm|cycle 1|COMP:0000107","Plant height in cm|cycle 2|COMP:0000109","Plant height in cm|cycle 3|COMP:0000110","Tallest sucker height in cm|cycle 1|harvesting|COMP:0000077","Tallest sucker height in cm|cycle 1|shooting|COMP:0000079","Tallest sucker height in cm|cycle 2|harvesting|COMP:0000080","Tallest sucker height in cm|cycle 2|shooting|COMP:0000081","Tallest sucker height in cm|cycle 3|harvesting|COMP:0000082","Tallest sucker height in cm|cycle 3|shooting|COMP:0000083","Weevil damage to corm of mother plant 1-3|cycle 1|COMP:0000084","Weevil damage to corm of mother plant 1-3|cycle 2|COMP:0000086","Weevil damage to corm of mother plant 1-3|cycle 3|COMP:0000087","Youngest leaf spotted rank|cycle 1|at flowering|COMP:0000088","Youngest leaf spotted rank|cycle 1|at harvesting|COMP:0000090","Youngest leaf spotted rank|cycle 2|at flowering|COMP:0000091","Youngest leaf spotted rank|cycle 2|at harvesting|COMP:0000092","Youngest leaf spotted rank|cycle 3|at flowering|COMP:0000093","Youngest leaf spotted rank|cycle 3|at harvesting|COMP:0000094","flowering of the plant|cycle 1|date of|COMP:0000095","flowering of the plant|cycle 2|date of|COMP:0000097","flowering of the plant|cycle 3|date of|COMP:0000098","fruit maturity of the plant|cycle 1|date of|COMP:0000099","fruit maturity of the plant|cycle 2|date of|COMP:0000101","fruit maturity of the plant|cycle 3|date of|COMP:0000102"],
        accessions => ["1201K-1","12419S-13","12468S-18","12468S-6","12477S-13","12479S-1","12479S-13","12618S-1","12949S-2","13284S-1","13522S-5","13573S-1","1438K-1","14539S-4","16191S-6","16242S-1","16285S-13","16285S-3","16285S-6","16285S-8","16457S-2","17503S-3","1968-2","19798S-2","21086S-1","2180K-6","222K-1","22598S-2","24410S-2","24434S-3","24583S-2","24797S-7","24928S_22","24948S-10","24948S-12","24948S-13","24948S-2","24948S-21","24948S-24","24948S-27","24948S-29","24948S-9","25031S-1","25031S-15","25031S-16","25031S-17","25031S-19","25031S-27","25031S-33","25031S-34","25031S-7","25066S-1","25066S-2","25089S-4","25102S-1","25117S-1","25117S-2","25117S-3","25328S-3","25356S-1","25371S-2","25435S-11","25435S-4","25457S-1","25474S-1","25474S-5","25499S-7","25508S-1","25583S-2","25623S-11","25628S-11","25653S-3","25680S-11","25680S-13","25737S-1","25909S-3","25974S-11","25974S-13","25974S-15","25974S-17","25974S-18","25974S-19","25974S-21","25974S-30","25974S-31","25974S-35","25974S-?","26039S-2","26060S-1","26075S-6","26075S-7","26075S-8","26224S-2","26224S-3","26260S-3","26288S-4","26315S-1","26315S-3","26316S-14","26316S-7","26317S-1","26337S-11A","26337S-11B","26337S-2","26337S-22A","26337S-22B","26337S-28","26337S-32","26337S-34","26337S-37","26337S-39","26337S-40","26337S-43","26363S-1","26369S-4","26369S-8","26466S-2","26466S-5","26530S-1","26540S-182","26660S-1","26666S-1","26709S-1","26725S-1","26815S-3","26815S-8","26815S-9","26820S-1","26840S-10","26840S-5","26840S-7","26840S-9","26874S-5","26975S-1","26975S-2","26990S-10","26990S-11","26990S-4","26998S-1","27073S-1","27074S-1","27184S-4","27184S-6","27184S-8","27261S-1","27261S-10","27261S-11","27262S-1","27262S-3","27264S-2","27334S-5","27346S-2","27346S-4","27401S-1","27437S-1","27494S-12","27494S-4","27494S-5","27524S-12A","27524S-12B","27524S-22","27524S-30","27528S-1","27579S-1","27579S-3","27684S-5","27713S-1","27744S-1","27770S-20","27770S-4","27825S-4","27833S-10","27833S-13","27873S-12","27873S-14","27873S-17","27873S-18","27873S-26","27873S-3","27873S-33","27873S-37","27873S-38","27873S-4","27873S-5","27873S-7","27885S-1","27885S-9","27886S-5","27914S-1","27914S-11","27914S-13","27914S-18","27914S-21","27914S-22","27914S-24","27914S-26","27914S-3","27914S-6","27914S-7","27914S-8","27915S-2","27915S-3","27935S-7","27960S-1","28030S-2","28030S-6","28033S-14","28033S-15","28033S-18","28033S-23","28033S-3","28033S-9","28036S-11","28036S-2","28060S-8","28068S-9","28071S-1","28073S-1","28077S-5","28095S-1","28164S-15","28164S-3","28165S-1","28188S-2","28200S-3","28246S-4","28246S-7","28256S-1","28257S-1","28257S-2","28257S-4","28260S-2","28263S-2","28432S-19","28432S-20","28432S-3","28434S-9","28452S-11","28465S-2","28465S-21","28476S-7","28476S-8","28479S-2","28481S-1","28492S-1","28506S-1","28528S-1","28561S-2","28561S-5","28780S-1","28974S-11","28974S-15","28974S-22","28974S-29","29114S-1","29114S-14","29114S-19","29114S-24","29165S-5","29275S-1","29275S-4","29275S-5","29285S-20","29364S-2","29586S-4","29636S-1","365K-1","376K-7","401K-1","5610S-1","660K-1","7197-2","7798S-2","8075-7","8386S-19","861S-1","9128-3","917K-2","9187S-8","9494S-10","9750S-13","ENYERU","Entukura","F1MK-106","F1MK-183","F1MK-24","F1MK-26","F1MK-37","F1MK-55","F1MK-96","HB","HJ","HX","ITC0249-Calcutta 4","ITC0250-Malaccensis","ITC0283-Long_Tavoy","ITC0425-SH-3142","ITC0712-Aacv_Rose","ITC1121-Pisang_Lilin","ITC1243-Kokopo_1","ITC1353-Nante","ITC1354-Enzirabahima","ITC1355-Kazirakwe","Kabucuragye","Kokopo2","Nakasabira","Nakawere","Nakayonga","Namwezi","Nfuuka","SH3217","SH3362","Tereza"]
    },
    {
        name => "GenoProtMaize",
        compute_from_parents => 1,
        traits => ["Anthesis [date]|G2F:0000001","Ear Height [cm]|G2F:0000003","Grain Moisture [percent]|G2F:0000005","Grain Yield [bu/acre]|G2F:0000007","Plant Height [cm]|G2F:0000009","Plot Weight [lbs]|G2F:0000011","Pollen DAP [days]|G2F:0000013","Root Lodging [plants]|G2F:0000015","Silk DAP [days]|G2F:0000017","Silking [date]|G2F:0000019","Stalk Lodging [plants]|G2F:0000021","Stand Count [plants]|G2F:0000023","dry yield|CO_334:0000014","fresh shoot weight measurement in kg|CO_334:0000016"],
        accessions => ["PHV63/LH195","CG106/PHZ51","LH145/LH82","PHN11_LH145_0002/PHB47","NYH-081/PHB47","W10005_0029/PHB47","B109/PHZ51","
        PH207_PHG47-13/PHB47","PH207_PHG47-19/PHB47","CG65/LH82","CG108/CGR03","LH57/LH195","BSSSC0_047/LH82","A635/LH82","LH195/PHZ51","LH38/LH195","CG121/PHZ51","CGR03/PHB47","CG123/PHB47","A679/LH82","LH61/PHB47","PH207_PHG47-6/PHB47","NYH-029/PHB47","W10004_0248/PHZ51","LH198/PHZ51","B106/PHZ51","CG60/CG110","CGX333/LH82","LH82_PHG47-20/PHB47","PH207_PHG47-1/PHB47","B14A/OH43","LH82/TX777","PHN11_PHW65_0065/LH195","B73/TX205","PHN11_LH145_0028/LH195","A680/LH82","LH82_PHG47-11/PHB47","CG121/LH82","CG60/CG102","W10004_0227/LH82","PB80/PHZ51","PHN11_PHG47_0287/PHB47","Z022E0009/LH195","DKC52-62","W10001_0012/PHB47","B73/MO17","MOG_MO45-078-1-1-1-1-B/LH185","CG122/PHB47","PH207_PHG47-23/PHB47","PHG83/PHB47","CG105/CG102","W10001_0022/PHB47","NYH-258/PHB47","PHB47/PHZ51","CG126/PHB47","M0058/LH185","CG60/LH162","PHG72/LH82","PHZ51/LH195","W10004_0127/LH82","PHG80/PHZ51","A634/PHZ51","SD101/PHB47","B119/PHZ51","PHW52/TX205","PHN11_OH43_0215/PHB47","PH207_PHG47-18/PHB47","W10004_0076/LH82","BSSSC0_048/LH82","M0033/LH82","B73/PHG35","CGR03/LH82","PHW52/PHN82","CGR03/CG44","WF9/H95","CGX333/PHZ51","PHM81/PHZ51","PH207_PHG47-25/PHB47","MO44_PHG47_0072/LH185","B97/LH82","M0326/LH185","PHN11_OH43_0001/PHB47","MOG_LH123HT-199-1-1-1-1-B/LH185","B111/LH82","LH82_PHG47-14/PHB47","M0041/LH185","A634/LH82","LH82_PHG47-12/PHB47","W10002_0001/PHB47","LH82_PHG47-9/PHB47","PHN11_OH43_0142/PHB47","PHN11_PHW65_0323/PHB47","PHRE1/LH82","LH51/PHB47","B103/PHZ51","LH198/CGR01","W10001_0013/PHB47","SD101/PHZ51","W10008_0063/PHB47","PH207_PHG47-15/PHB47","CG60/CG111","PHN11_OH43_0075/LH185","CG65/LH185","PHN11_LH145_0085/LH185","A672/LH82","PB80/LH82","TX303/LH82","B73/PHM49","CGR04/LH195","FS6296VT3","LH212HT/LH195","CG124/PHB47","M0015/LH82","W10008_0119/PHB47","PHN11_PHW65_0312/PHB47","CG110/LH82","Z022E0097/LH185","W10006_0004/PHB47","LH74/PHM49","LH185/LH198","F42/MO17","PHN11_PHG47_0251/LH185","PHN11_LH145_0003/PHB47","PHG72/PHB47","W10001_0007/PHB47","CG102/LH82","CG122/CG102","GEMN-0155/PHB47","CG108/CGR01","A641/PHZ51","EX4104","CG118/CGR03","NYH-245/PHB47","PHW52/PHG35","CG102/CG60","LH195/TX777","W10001_0018/PHB47","M0101/LH185","Z022E0121/PHZ51","TX303/PHB47","LH74/PHG35","M0077/LH82","EX3101","W10001_0006/PHB47","Z022E0023/LH82","CG44/CGR01","Z022E0114/PHZ51","CG104/LH82","LH61/LH195","LH38/PHB47","B73/PHN82","PH207_PHG47-14/PHB47","M0030/PHZ51","PHN11_PHW65_0015/PHB47","B14A/LH82","LH57/PHB47","CG118/CGR01","B37/C103","LH185/PHB47","W10008_0069/PHB47","PHG39/PHG35","CG123/CG102","CG108/LH162","PHJ40/LH82","B14A/MO17","PHN11_LH145_0085/PHB47","LH82_PHG47-7/PHB47","PHKE6/PHZ51","GEMS-0162/PHZ51","M0014/LH82","LH82/LH195","B37/H95","M0143/LH185","GEMS-0163/PHZ51","MO44_PHG47_0072/PHB47","CG105/PHB47","PHN11_PHW65_0015/LH198","PHN11_LH145_0005/CG102","W10004_0127/PHZ51","LH82_PHG47-5/PHB47","Z022E0053/CG102","PHN11_OH43_0075/PHB47","A680/PHZ51","M0008/LH82","LH132/LH51","PHN11_PHG47_0287/LH195","PHP02/PHB47","M0012/LH82","W10004_0204/PHZ51","W10008_0092/PHB47","W10008_0059/PHB47","B73_NC230-041-1-1-1-1/LH185","PHN11_LH145_0003/LH185","W10008_0017/PHB47","Z022E0123/LH185","PH207_PHG47-7/PHB47","A641/LH82","PH207_PHG47-8/PHB47","PHN11_PHW65_0065/PHB47","WF9/OH43","SD101/LH82","W10005_0147/PHB47","PHN11_LH145_0005/LH198","Z022E0077/LH82","M0052/LH82","W10008_0037/PHB47","CG111/PHB47","F42/OH43","2369/PHZ51","Z022E0003/LH82","W10004_0032/LH185","A679/PHZ51","M0001/LH82","CG44/CG110","M0024/LH82","B73/PHZ51","W10004_0248/LH82","Z022E0072/PHZ51","B103/LH82","PH207_PHG47-11/PHB47","MOG_PHG83-090-1-1-1-1-B/LH185","PHG39/PHM49","MO44_LH145_0127/PHB47","GEMS-0162/LH82","PHN11_PHW65_0275/LH185","CG118/LH82","B37/OH43","PHG39/PHN82","LH132/LH82","W10004_0204/LH198","CG65/CG102","W10004_0216/PHZ51","PH207_PHG47-22/PHB47","W10002_0002/PHB47","NYH-250/PHB47","PHG80/PHB47","CG110/PHB47","W10001_0019/PHB47","PHN11_PHW65_0275/PHB47","CG65/CG108","LH82_PHG47-24/PHB47","BSSSC0_038/PHZ51","FS5424XRR","M0151/LH185","B14A/C103","PHN11_OH43_0142/LH185","M0030/LH185","LH82_PHG47-19/PHB47","CG125/PHZ51","LH82_PHG47-21/PHB47","MO44_LH145_0138/PHB47","LH82_PHG47-17/PHB47","BSSSC0_044/LH82","M0163/LH82","Z022E0017/LH185","MO44_LH145_0138/LH185","PHW52/PHM49","M0022/LH185","A672/PHZ51","B97/PHB47","W10008_0065/PHB47","CG125/PHB47","LH82_PHG47-4/PHB47","CG120/LH82","MO44_LH145_0127/LH185","A635/PHZ51","LH82_PHG47-3/PHB47","M0101/LH82","NYH-167/PHB47","PHRE1/PHZ51","W10004_0076/LH185","M0083/PHZ51","WF9/MO17","MO44_PHW65_0193/LH185","B109/LH82","LH51/LH195","LH195/LH185","PHN11_PHG47_0385/PHB47","REDEAR2-2-2-1-1-2-B-B-1-B10/LH195","W10008_0099/PHB47","M0041/LH82","LH82_PHG47-15/PHB47","B111/PHZ51","NYH-128/PHB47","CG106/PHB47","CG118/CG44","BSSSC0_044/PHZ51","GEMN-0178/PHB47","CG119/LH82","LH82_PHG47-23/PHB47","NYH-269/PHB47","PHN11_LH145_0028/LH198","Z022E0046/PHZ51","LH82_PHG47-18/PHB47","PHN11_PHG47_0048/LH198","PHB47/LH195","NYH-229/PHB47","B14A/H95","PHN11_OH43_0215/LH195","Z022E0160/LH82","M0118/LH185","M0266/LH82","PHJ40/PHZ51","W10001_0047/PHB47","Z022E0073/LH82","PHB47/LH82","W10008_0001/PHB47","M0088/LH185","MOG_OH43_0170/LH185","LH82_PHG47-10/PHB47","Z022E0042/LH82","PHN11_PHG47_0388/LH195","BSSSC0_029/PHZ51","PHN11_OH43_0088/PHB47","CG127/PHB47","B106/LH82","BSSSC0_032/PHZ51","W10004_0227/PHZ51","GEMS-0146/PHZ51","M0028/LH185","NYH-244/PHB47","W37A/PHB47","PHN11_PHG47_0385/LH198","CG108/PHB47","BSSSC0_047/PHZ51","PHN11_OH43_0001/LH198","LH74/PHN82","CG127/PHZ51","W10006_0003/PHB47","PHG47/PHB47","M0154/LH82","PH207_PHG47-24/PHB47","OH43/PHB47","PHN11_PHG47_0172/LH198","PHN11_OH43_0088/LH198","M0003/LH185","PHN11_PHG47_0172/LH195","PHM81/PHB47","Z022E0110/PHZ51","M0039/LH82","PHN11_PHW65_0359/LH198","Z022E0025/PHZ51","(LAMA2002-35-2-B-B-B-B_CG44)-1-3-B-1-1-B24-B5-B16/LH195","NYH-055/PHB47","B119/LH82","NYH-240/PHB47","BSSSC0_038/LH82","TX714/PHZ51","Z022E0059/LH185","LH145/PHZ51","M0262/LH185","W10004_0216/LH82","PH207_PHG47-17/PHB47","CG108/CG102","PHN11_PHW65_0323/LH195","BSSSC0_032/LH82","Z022E0149/LH185","CG119/CG102","LH82_PHG47-1/PHB47","CG119/CG108","NYH-061/PHB47","PHKE6/LH82","Z022E0095/PHZ51","NYH-052/PHB47","NYH-251/PHB47","CG60/PHB47","W10005_0107/PHB47","W10008_0042/PHB47","CG120/PHZ51","CG104/PHB47","PHN11_PHG47_0251/PHB47","LH82_PH207-23/PHB47","NYH-211/PHB47","M0143/LH82","LH82_PH207-11/PHB47","PHN11_OH43_0036/LH185","CG118/LH198","B118/PHB47","W10001_0031/PHB47","W10004_0032/PHZ51","PHN11_PHW65_0015/LH195","LH82_PH207-20/PHB47","LH82_PH207-18/PHB47","PH207_PHG47-12/PHB47","CG108/CG111","LH82_PHG47-2/PHB47","CG102/PHZ51","BSSSC0_023/PHZ51","GEMN-0192/PHB47","CG108/LH195","LH82_PH207-25/PHB47","CG104/PHZ51","GEMS-0150/LH82","BSSSC0_048/PHZ51","CGX333/LH198","CG119/PHZ51","LH82_PH207-4/PHB47","LH82_PHG47-22/PHB47","M0028/LH82","PHN11_LH145_0036/LH198","PH207_PHG47-3/PHB47","LH82_PH207-16/PHB47","CG119/CG44","PHN11_PHG47_0048/PHB47","LH82_PHG47-16/PHB47","PHG80/LH82","GEMS-0148/PHZ51","PHN11_LH145_0028/PHB47","CG122/PHZ51","BSSSC0_019/PHZ51","M0052/LH185","CG105/PHZ51","PH207_PHG47-2/PHB47","CG121/LH198","GEMS-0150/PHZ51","M0083/LH82","CG119/LH198","CG108/CG110","PHN11_PHG47_0388/PHB47","LH82_PHG47-25/PHB47","W10004_0204/LH82","M0287/LH185","NYH-129/PHB47","PH207_PHG47-16/PHB47","LH82_PHG47-8/PHB47","LH82_PH207-17/PHB47","W10005_0220/PHB47","PHN11_LH145_0003/LH198","MO44_PHW65_0035/LH185","Q381/PHB47","M0323/LH185","W10005_0037/PHB47","CG118/PHZ51","BSSSC0_008/LH82","MO44_LH145_0138/LH198","CG108/PHZ51","LH82_PH207-10/PHB47","PHN11_OH43_0001/LH185","M0024/LH185","BSSSC0_023/LH82","LH162/CG102","PHN11_OH43_0036/PHB47","LH82_PH207-7/PHB47","LH82_PH207-14/PHB47","M0154/LH185","LH82_PH207-24/PHB47","BSSSC0_019/LH82","M0325/LH185","LH82_PH207-15/PHB47","LH82_PHG47-13/PHB47","W10005_0220/LH198","PHN11_OH43_0184/PHB47","CM105/PHZ51","W10004_0032/LH82","M0077/PHZ51","PH207_PHG47-10/PHB47","PH207_PHG47-20/PHB47","W10008_0009/PHB47","M0266/LH185","PHN11_PHG47_0390/LH198","BSSSC0_008/PHZ51","CG108/LH82","M0186/LH185","PHN11_PHG47_0390/PHB47","CG44/LH162","W10008_0018/PHB47","LH82_PH207-5/PHB47","CM105/LH82","PHKE6/PHB47","LH82_PH207-22/PHB47","M0116/LH82","CG120/LH198","LH82_PH207-19/PHB47","LH82_PH207-8/PHB47","LH82_PH207-13/PHB47","M0106/LH185","M0008/LH185","W10004_0076/PHZ51","M0116/LH185","CGR01/PHB47","LH82_PH207-2/PHB47","B73_NC230-059-1-1-1-1/LH185","LH82_PH207-12/PHB47","2369/3IIH6","2369/LH123HT","2369/PHN82","2FACC/3IIH6","4N506/3IIH6","6F629/3IIH6","78010/3IIH6","A3G-3-3-1-313/3IIH6","A632/3IIH6","A634/3IIH6","A635/3IIH6","A679/3IIH6","A680/3IIH6","B104/3IIH6","B105/3IIH6","B109/3IIH6","B110/3IIH6","B111/3IIH6","B119/3IIH6","B14A/3IIH6","B73/3IIH6","B84/3IIH6","BSSSC0_001/3IIH6","BSSSC0_002/3IIH6","BSSSC0_005/3IIH6","BSSSC0_008/3IIH6","BSSSC0_012/3IIH6","BSSSC0_015/3IIH6","BSSSC0_017/3IIH6","BSSSC0_020/3IIH6","BSSSC0_024/3IIH6","BSSSC0_026/3IIH6","BSSSC0_029/3IIH6","BSSSC0_038/3IIH6","BSSSC0_048/3IIH6","BSSSC0_054/3IIH6","BSSSC0_057/3IIH6","BSSSC0_060/3IIH6","CG102/3IIH6","CG106/3IIH6","CG120/3IIH6","CG120/CG123","CG120/LH162","CG120/LH185","CG120/PHR25","CG120/PHW03","CG123/S8324","CG124/CG120","CG124/LH145","CG124/PHHV4","CG124/PHRE1","CG124/S8324","CG60/LH185","CG60/LH82","CGR03/CG108","CI540/3IIH6","CO258/3IIH6","DKFBHJ/3IIH6","EX4101","EX5101","FBLA/3IIH6","FR19/3IIH6","GEMN-0260/3IIH6","GEMN-0268/3IIH6","H122W/3IIH6","H84/3IIH6","H91/3IIH6","I159/3IIH6","ILL.HY/3IIH6","LH145/3IIH6","LH145/CG123","LH145/LH162","LH145/PHK05","LH145/PHR25","LH149/3IIH6","LH185/LH145","LH185/PHRE1","LH185/S8324","LH195/3IIH6","LH195/CGR01","LH195/LH82","LH198/3IIH6","LH205/3IIH6","LH209/3IIH6","LH216/LH195","LH220HT/3IIH6","LH222/3IIH6","LH82/LH145","LH82/PHB47","LH82/PHRE1","LH82/S8324","N192/3IIH6","N209/3IIH6","N217/3IIH6","N218/3IIH6","N28HT/3IIH6","N501/3IIH6","NKH8431/3IIH6","OS420/3IIH6","PHB09/3IIH6","PHB47/3IIH6","PHB47/CG123","PHB47/LH162","PHB47/LH185","PHB47/PHK05","PHB47/PHK56","PHB47/PHR25","PHB47/PHW03","PHBB3/3IIH6","PHBW8/3IIH6","PHG29/CG120","PHG29/LH145","PHG29/PHB47","PHG29/PHG47","PHG29/PHHV4","PHG29/PHRE1","PHG29/S8324","PHG39/TX205","PHG47/CG120","PHG47/LH145","PHG47/PHHV4","PHG47/PHRE1","PHG47/S8324","PHG80/3IIH6","PHHV4/3IIH6","PHHV4/CG123","PHHV4/LH162","PHHV4/LH185","PHHV4/PHK05","PHHV4/PHK56","PHHV4/PHR25","PHHV4/PHW03","PHHV4/PHZ51","PHJ89/CG120","PHJ89/LH145","PHJ89/PHHV4","PHJ89/PHRE1","PHJ89/S8324","PHK05/PHRE1","PHK56/PHRE1","PHN82/LH145","PHN82/PHB47","PHN82/PHHV4","PHN82/PHRE1","PHN82/S8324","PHP02/PHG47","PHP85/3IIH6","PHRE1/CG123","PHRE1/PHR25","PHT69/3IIH6","PHV37/3IIH6","PHW03/LH145","PHW03/S8324","PHZ51/LH145","S8324/3IIH6","S8324/CG123","S8324/LH162","S8324/PHK05","S8324/PHK56","S8324/PHR25","S8324/PHZ51","S8326/CG120","S8326/LH145","S8326/PHB47","S8326/PHHV4","S8326/PHRE1","S8326/S8324","SD101/3IIH6","VA35/LH195","W10004_0007/3IIH6","W10004_0008/3IIH6","W10004_0011/3IIH6","W10004_0026/3IIH6","W10004_0045/3IIH6","W10004_0062/3IIH6","W10004_0072/3IIH6","W10004_0119/3IIH6","W10004_0121/3IIH6","W10004_0140/3IIH6","W10004_0148/3IIH6","W10004_0208/3IIH6","W10004_0212/3IIH6","W10004_0225/3IIH6","W10004_0258/3IIH6","W10004_0292/3IIH6"]
    },
    {
        name => "GenoProtCassava",
        compute_from_parents => 0,
        traits => ["cassava brown streak disease leaf incidence 3-month evaluation|CO_334:0000208","cassava brown streak disease leaf incidence 6-month evaluation|CO_334:0000209","cassava brown streak disease leaf incidence 9-month evaluation|CO_334:0000210","cassava brown streak disease leaf severity 3-month evaluation|CO_334:0000204","cassava brown streak disease leaf severity 6-month evaluation|CO_334:0000205","cassava brown streak disease leaf severity 9-month evaluation|CO_334:0000206","cassava brown streak disease root severity 12-month evaluation|CO_334:0000201","cassava mosaic disease incidence 3-month evaluation|CO_334:0000196","cassava mosaic disease incidence 6-month evaluation|CO_334:0000198","cassava mosaic disease incidence 9-month evaluation|CO_334:0000197","cassava mosaic disease severity 3-month evaluation|CO_334:0000192","cassava mosaic disease severity 6-month evaluation|CO_334:0000194","cassava mosaic disease severity 9-month evaluation|CO_334:0000193","dry matter content percentage|CO_334:0000092","fresh storage root weight per plot|COMP:0000111","harvest index variable|CO_334:0000015","plant stands harvested counting|CO_334:0000010","root number counting|CO_334:0000011"],
        accessions => ["TMEB14","UG110004_125","UG110004_137","UG110004_157","UG110004_191","UG110004_20","UG110004_224","UG110004_231","UG110004_269","UG110004_287","UG110004_304","UG110004_34","UG110004_344","UG110004_83","UG110014","UG110015_105","UG110015_148","UG110015_167","UG110015_184","UG110015_208","UG110015_24","UG110015_241","UG110015_259","UG110015_28","UG110015_293","UG110015_322","UG110015_57","UG110015_96","UG110017","UG110017_117","UG110017_145","UG110017_161","UG110017_180","UG110017_237","UG110017_252","UG110017_300","UG110017_316","UG110017_333","UG110017_47","UG110017_5","UG110017_62","UG110017_77","UG14_0003","UG14_0007","UG14_0014","UG14_0019","UG14_0023","UG14_0030","UG14_0033","UG14_0034","UG14_0037","UG14_0038","UG14_0045","UG14_0047","UG14_0048","UG14_0051","UG14_0063","UG14_0068","UG14_0072","UG14_0073","UG14_0074","UG14_0075","UG14_0084","UG14_0085","UG14_0093","UG14_0096","UG14_0104","UG14_0105","UG14_0111","UG14_0112","UG14_0123","UG14_0127","UG14_0128","UG14_0129","UG14_0141","UG14_0143","UG14_0144","UG14_0195","UG14_0201","UG14_0207","UG14_0212","UG14_0218","UG14_0223","UG14_0227","UG14_0233","UG14_0234","UG14_0237","UG14_0243","UG14_0250","UG14_0253","UG14_0255","UG14_0256","UG14_0261","UG14_0263","UG14_0265","UG14_0274","UG14_0294","UG14_0296","UG14_0298","UG14_0299","UG14_0301","UG14_0313","UG14_0318","UG14_0319","UG14_0328","UG14_0330","UG14_0332","UG14_0333","UG14_0335","UG14_0339","UG14_0411","UG14_0417","UG14_0421","UG14_0424","UG14_0426","UG14_0437","UG14_0441","UG14_0447","UG14_0732","UG14_0737","UG14_0741","UG14_0743","UG14_0754","UG14_0756","UG14_0762","UG14_0765","UG14_0769","UG14_0800","UG14_0802","UG14_0808","UG14_0818","UG14_0868","UG14_0871","UG14_0874","UG14_0892","UG14_0898","UG14_0916","UG14_0940","UG14_0942","UG14_0946","UG14_0951","UG14_0962","UG14_0963","UG14_0971","UG14_0979","UG14_0990","UG14_0993","UG14_1003","UG14_1026","UG14_1034","UG14_1043","UG14_1051","UG14_1058","UG14_1064","UG14_1103","UG14_1116","UG14_1146","UG14_1156","UG14_1169","UG14_1173","UG14_1198","UG14_1215","UG14_1219","UG14_1231","UG14_1233","UG14_1237","UG14_1239","UG14_1254","UG14_1257","UG14_1264","UG14_1265","UG14_1267","UG14_1269","UG14_1271","UG14_1283","UG14_1285","UG14_1288","UG14_1297","UG14_1310","UG14_1318","UG14_1334","UG14_1337","UG14_1341","UG14_1342","UG14_1345","UG14_1353","UG14_1355","UG14_1384","UG14_1389","UG14_1391","UG14_1410","UG14_1414","UG14_1422","UG14_1427","UG14_1442","UG14_1443","UG14_1449","UG14_1454","UG14_1462","UG14_1463","UG14_1476","UG14_1493","UG14_1495","UG14_1500","UG14_1504","UG14_1511","UG14_1513","UG14_1516","UG14_1523","UG14_1537","UG14_1539","UG14_1542","UG14_1546","UG14_1552","UG14_1555","UG14_1563","UG14_1567","UG14_1579","UG14_1582","UG14_1591","UG14_1597","UG14_1599","UG14_1609","UG14_1618","UG14_1625","UG14_1636","UG14_1644","UG14_1652","UG14_1658","UG14_1659","UG14_1686","UG14_1691","UG14_1693","UG14_1702","UG14_1706","UG14_1721","UG14_1724","UG14_1727","UG14_1728","UG14_1729","UG14_1734","UG14_1735","UG14_1746","UG14_1748","UG14_1751","UG14_1757","UG14_1763","UG14_1765","UG14_1778","UG14_1779","UG14_1791","UG14_1793","UG14_1796","UG14_1798","UG14_1799","UG14_1801","UG14_1804","UG14_1810","UG14_1815","UG14_1821","UG14_1829","UG14_1832","UG14_1834","UG14_1836","UG14_1837","UG14_1840","UG14_1844","UG14_1847","UG14_1848","UG14_1853","UG14_1854","UG14_1856","UG14_1857","UG14_1862","UG14_1863","UG14_1874","UG14_1875","UG14_1878","UG14_1881","UG14_1882","UG14_1884","UG14_1891","UG14_1893","UG14_1896","UG14_1898","UG14_1903","UG14_1905","UG14_1919","UG14_1922","UG14_1925","UG14_1933","UG14_1938","UG14_1939","UG14_1940","UG14_1941","UG14_1944","UG14_1947","UG14_1948","UG14_1954","UG14_1956","UG14_1961","UG14_1964","UG14_1967","UG14_1968","UG14_1969","UG14_1970","UG14_1973","UG14_1975","UG14_1981","UG14_1987","UG14_1988","UG14_1991","UG14_1999","UG14_2000","UG14_2001","UG14_2022","UG14_2023","UG14_2024","UG14_2026","UG14_2035","UG14_2041","UG14_2045","UG14_2050","UG14_2053","UG14_2056","UG14_2064","UG14_2065","UG14_2068","UG14_2071","UG14_2075","UG14_2080","UG14_2082","UG14_2083","UG14_2087","UG14_2088","UG14_2091","UG14_2092","UG14_2094","UG14_2098","UG14_2103","UG14_2107","UG14_2119","UG14_2123","UG14_2127","UG14_2132","UG14_2134","UG14_2142","UG14_2143","UG14_2144","UG14_2151","UG14_2154","UG14_2160","UG14_2166","UG14_2169","UG14_2174","UG14_2180","UG14_2184","UG14_2196","UG14_X004","UG14_X005","UG14_X006","UG14_X008","UG14_X009","UG14_X011","UG14_X013","UG14_X014","UG14_X018","UG14_X020","UG14_X022","UG14_X025","UG14_X027","UG14_X029","UG14_X030","UG14_X039","UG14_X041","UGL15228","UGL15232","UGL15233","UGL15234","UGL15235","UGL15236","UGL15237","UGL15238","UGL15239","UGL15240","UGL15241","UGL15242","UGL15243","UGL15244","UGL15245","UGL15246","UGL15247","UGL15248","UGL15249","UGL15250","UGL15251","UGL15252","UGL15253","UGL15254","UGL15255","UGL15256","UGL15257","UGL15258","UGL15259","UGL15260","UGL15261","UGL15262","UGL15263","UGL15264","UGL15265","UGL15266","UGL15267","UGL15268","UGL15269","UGL15270","UGL15271","UGL15272","UGL15273","UGL15274","UGL15275","UGL15276","UGL15277","UGL15278","UGL15279","UGL15280","UGL15281","UGL15282","UGL15283","UGL15284","UGL15285","UGL15286","UGL15287","UGL15288","UGL15289","UGL15290","UGL15291","UGL15292","UGL15293","UGL15294","UGL15295","UGL15296","UGL15297","UGL15298","UGL15299","UGL15300","UGL15301","UGL15302","UGL15303","UGL15304","UGL15305","UGL15306","UGL15307","UGL15308","UGL15309","UGL15310","UGL15311","UGL15312","UGL15313","UGL15314","UGL15315","UGL15316","UGL15318","UGL15319","UGL15320","UGL15321","UGL15322","UGL15323","UGL15324","UGL15325","UGL15326","UGL15327","UGL15328","UGL15329","UGL15330","UGL15331","UGL15332","UGL15333","UGL15334","UGL15335","UGL15337","UGL15338","UGL15339","UGL15340","UGL15341","UGL15342","UGL15343","UGL15344","UGL15345","UGL15346","UGL15347","UGL15348","UGL15349","UGL15350","UGL15351","UGL15352","UGL15353","UGL15354","UGL15355","UGL15356","UGL15357","UGL15358","UGL15359","UGL15360","UGL15361","UGL15362","UGL15363","UGL15364","UGL15365","UGL15366","UGL15367","UGL15368","UGL15369","UGL15370","UGL15371","UGL15372","UGL15373","UGL15374","UGL15375","UGL15376","UGL15377","UGL15378","UGL15379","UGL15380","UGL15381","UGL15382","UGL15383","UGL15384","UGL15385","UGL15386","UGL15387","UGL15388","UGL15389","UGL15390","UGL15391","UGL15392","UGL15393","UGL15394","UGL15395","UGL15396","UGL15397","UGL15398","UGL15399","UGL15400","UGL15401","UGL15402","UGL15403","UGL15404","UGL15405","UGL15406","UGL15407","UGL15408","UGL15409","UGL15410","UGL15411","UGL15412","UGL15413","UGL15414","UGL15415","UGL15416","UGL15417","UGL15418","UGL15419","UGL15420","UGL15421","UGL15422","UGL15423","UGL15424","UGL15425","UGL15426","UGL15427","UGL15428","UGL15429","UGL15430","UGL15431","UGL15432","UGL15433","UGL15434","UGL15435","UGL15436","UGL15437","UGL15438","UGL15439","UGL15440","UGL15441","UGL15442","UGL15443","UGL15444","UGL15445","UGL15446","UGL15447","UGL15448","UGL15449","UGL15450","UGL15451","UGL15452","UGL15453","UGL15454","UGL15455","UGL15456","UGL15457","UGL15458","UGL15459","UGL15460","UGL15461","UGL15462","UGL15463","UGL15464","UGL15465","UGL15466","UGL15467","UGL15468","UGL15469","UGL15470","UGL15471","UGL15472","UGL15473","UGL15474","UGL15475","UGL15476","UGL15477","UGL15478","UGL15479","UGL15480","UGL15481","UGL15482","UGL15483","UGL15484","UGL15485","UGL15486","UGL15487","UGL15488","UGL15489","UGL15490","UGL15491","UGL15492","UGL15493","UGL15494","UGL15495","UGL15496","UGL15497","UGL15498","UGL15499","UGL15500","UGL15501","UGL15502","UGL15503","UGL15504","UGL15505","UGL15506","UGL15507","UGL15508","UGL15509","UGL15510","UGL15511","UGL15512","UGL15513","UGL15514","UGL15515","UGL15516","UGL15517","UGL15518","UGL15519","UGL15520","UGL15521","UGL15522","UGL15523","UGL15524","UGL15525","UGL15526","UGL15527","UGL15528","UGL15529","UGL15530","UGL15531","UGL15532","UGL15533","UGL15534","UGL15535","UGL15536","UGL15537","UGL15538","UGL15539","UGL15540","UGL15541","UGL15542","UGL15543","UGL15544","UGL15545","UGL15546","UGL15547","UGL15548","UGL15549","UGL15550","UGL15551","UGL15552","UGL15553","UGL15554","UGL15555","UGL15556","UGL15557","UGL15558","UGL15559","UGL15560","UGL15561","UGL15562","UGL15563","UGL15564","UGL15565","UGL15566","UGL15567","UGL15568","UGL15569","UGL15570","UGL15571","UGL15572","UGL15573","UGL15574","UGL15575","UGL15576","UGL15577","UGL15578","UGL15579","UGL15580","UGL15582","UGL15583","UGL15584","UGL15585","UGL15586","UGL15587","UGL15588","UGL15589","UGL15590","UGL15591","UGL15592","UGL15593","UGL15594","UGL15595","UGL15596","UGL15597","UGL15598","UGL15599","UGL15600","UGL15601","UGL15602","UGL15603","UGL15604","UGL15605","UGL15606","UGL15607","UGL15608","UGL15609","UGL15610","UGL15611","UGL15612","UGL15613","UGL15614","UGL15615","UGL15616","UGL15617","UGL15618","UGL15619","UGL15620","UGL15621","UGL15622","UGL15623","UGL15624","UGL15625","UGL15626","UGL15627","UGL15628","UGL15629","UGL15630","UGL15631","UGL15632","UGL15633","UGL15634","UGL15635","UGL15636","UGL15637","UGL15638","UGL15639","UGL15640","UGL15641","UGL15642","UGL15643","UGL15644","UGL15645","UGL15646","UGL15647","UGL15649","UGL15650","UGL15651","UGL15653","UGL15654","UGL15655","UGL15656","UGL15657","UGL15658","UGL15659","UGL15660","UGL15661","UGL15662","UGL15663","UGL15664","UGL15665","UGL15666","UGL15667","UGL15668","UGL15669","UGL15670","UGL15671","UGL15672","UGL15673","UGL15674","UGL15675","UGL15676","UGL15677","UGL15678","UGL15679","UGL15680","UGL15681","UGL15682","UGL15683","UGL15684","UGL15686","UGL15687","UGL15689","UGL15690","UGL15691","UGL15692","UGL15693","UGL15695","UGL15696","UGL15697","UGL15698","UGL15699","UGL15700","UGL15701","UGL15702","UGL15703","UGL15704","UGL15705","UGL15706","UGL15707","UGL15708","UGL15709","UGL15710","UGL15711","UGL15712","UGL15713","UGL15714","UGL15715","UGL15716","UGL15717","UGL15718","UGL15719","UGL15720","UGL15721","UGL15722","UGL15723","UGL15724","UGL15725","UGL15726","UGL15727","UGL15728","UGL15729","UGL15730","UGL15731","UGL15732","UGL15733","UGL15734","UGL15735","UGL15736","UGL15737","UGL15738","UGL15739","UGL15740","UGL15741","UGL15742","UGL15743","UGL15745","UGL15746","UGL15747","UGL15748","UGL15749","UGL15750","UGL15751","UGL15752","UGL15753","UGL15754","UGL15755","UGL15756","UGL15757","UGL15758","UGL15759","UGL15760","UGL15761","UGL15762","UGL15763","UGL15764","UGL15765","UGL15766","UGL15767","UGL15768","UGL15769","UGL15770","UGL15771","UGL15772","UGL15773","UGL15774","UGL15775","UGL15776","UGL15777","UGL15778","UGL15779","UGL15780","UGL15781","UGL15782","UGL15783","UGL15784","UGL15785","UGL15786","UGL15787"]
    },
    {
        name => "GenoProtMaize",
        compute_from_parents => 0,
        traits => ["Anthesis [date]|G2F:0000001","Ear Height [cm]|G2F:0000003","Grain Moisture [percent]|G2F:0000005","Grain Yield [bu/acre]|G2F:0000007","Plant Height [cm]|G2F:0000009","Plot Weight [lbs]|G2F:0000011","Pollen DAP [days]|G2F:0000013","Root Lodging [plants]|G2F:0000015","Silk DAP [days]|G2F:0000017","Silking [date]|G2F:0000019","Stalk Lodging [plants]|G2F:0000021","Stand Count [plants]|G2F:0000023","dry yield|CO_334:0000014","fresh shoot weight measurement in kg|CO_334:0000016"],
        accessions => ["554353-1-1-B","554360-1-1-B","554363-1-1-B","554371-1-1-B","554372-1-1-B","6F629","8M129","907","A632","A634","A635","A680","AH83","Ames19311","Ames22751","Ames22759","Ames22761","Ames23496","Ames23923","Ames27138","Ames28939","Ames30793","Ames30797","Ames8399","ARGENTINE_FLINTY_COMPOSITE-C(1)-37-B-B-B2-1-B25","ArgentineFlintyComposite-C(1)-37-B-B-B2-1-B25-B2-B?-1-B","AS5707","AS6103","B103","B110","B2","B37","B73","B73_NC230-032-1-1-1-1","B73_NC230-040-1-1-1-1","B73_NC230-041-1-1-1-1","B73_NC230-049-1-1-1-1","B73_NC230-059-1-1-1-1","B73_NC230-126-1-1-1-1","B73_NC230-127-1-1-1-1","B73_NC230-128-1-1-1-1","B73_NC230-129-1-1-1-1","B73_NC230-147-1-1-1-1","B73_PHG39-1","B73_PHG39-12","B73_PHG39-15","B73xPHG39-10","B73xPHG39-11","B73xPHG39-13","B73xPHG39-14","B73xPHG39-15","B73xPHG39-16","B73xPHG39-17","B73xPHG39-18","B73xPHG39-19","B73xPHG39-2","B73xPHG39-20","B73xPHG39-21","B73xPHG39-22","B73xPHG39-23","B73xPHG39-24","B73xPHG39-25","B73xPHG39-3","B73xPHG39-4","B73xPHG39-5","B73xPHG39-6","B73xPHG39-7","B73xPHG39-8","B73xPHG39-9","B76","B79","B84","B97","BGEM-0001-N","BGEM-0005-N","BGEM-0039-N","BGEM-0040-N","BGEM-0046-N","BGEM-0063-N","BGEM-0066-N","BGEM-0089-N","BGEM-0102-N","BGEM-0107-N","BGEM-0121-N","BGEM-0124-N","BGEM-0125-N","BGEM-0129-N","BGEM-0130-N","BGEM-0140-N","BGEM-0143-N","BGEM-0151-N","BGEM-0157-N","BGEM-0182-N","BGEM-0184-N","BGEM-0193-N","BGEM-0202-N","BGEM-0203-N","BGEM-0204-N","BGEM-0205-N","BGEM-0206-N","BGEM-0207-N","BGEM-0209-N","BGEM-0210-N","BGEM-0211-N","BGEM-0215-N","BGEM-0227-N","BGEM-0228-N","BGEM-0235-N","BGEM-0239-N","BGEM-0240-N","BGEM-0246-N","BGEM-0248-N","BGEM-0253-N","BGEM-0256-N","BGEM-0259-N","BLANK","BSSSC0_001","BSSSC0_005","BSSSC0_009","BSSSC0_015","BSSSC0_026","BSSSC0_033","BSSSC0_044","BSSSC0_054","BSSSC0_057","BSSSC0_060","C103","CG102","CG104","CG105","CG106","CG108","CG110","CG111","CG118"]
    }
];

# Number of times to repeat each query
# my $query_repeat = 100;
my $query_repeat = 3;

# Number of queries to do
my $number_queries = 10;

# Number of random accessions to pick for querying phenotypes and genotypes
my $random_accessions = 25;

# Number of random markers to pick for querying genotypes
my $random_markers = 500;

# There are two possible formats for retrieving genotyping data currently implemented, so they will both be tested
my $download_formats = ['VCF', 'DosageMatrix'];

# For recording execution time results
my %execution_times;

my $accession_cvterm_id = SGN::Model::Cvterm->get_cvterm_row($schema, 'accession', 'stock_type')->cvterm_id();

my $shared_cluster_dir_config = $opt_s;
my $backend_config = $opt_b;
my $cluster_host_config = $opt_h;
my $web_cluster_queue_config = $opt_w;
my $basepath_config = $opt_p;

# Loop over the 4 species scenarios : Banana, Maize computed from parents, Cassava, Maize
foreach my $index (0..3) {

    # Getting genotyping protocol, accessions, and traits for the species
    my $genotyping_protocol_name = $genotyping_protocol_names->[$index]->{name};
    my $compute_from_parents = $genotyping_protocol_names->[$index]->{compute_from_parents};
    my @accession_names = @{$genotyping_protocol_names->[$index]->{accessions}};
    my $trait_names = $genotyping_protocol_names->[$index]->{traits};

    # Retriving the genotyping protocol database id from the name
    my $genotyping_protocol_id = $schema->resultset("NaturalDiversity::NdProtocol")->find({name => $genotyping_protocol_name})->nd_protocol_id();

    # Randomly picking a number of markers in the genotyping protocol
    my $protocol = CXGN::Genotype::Protocol->new({
        bcs_schema => $schema,
        nd_protocol_id => $genotyping_protocol_id
    });
    my @marker_names = @{$protocol->marker_names()};
    my @marker_names_subset = @marker_names[(shuffle(0..$#marker_names))[0..$random_markers-1]];

    # Retrieving the trait database ids from the trait names
    my @trait_ids = ();
    print STDERR Dumper $trait_names;
    foreach (@$trait_names) {
        my $trait_id = SGN::Model::Cvterm->get_cvterm_row_from_trait_name($schema, $_)->cvterm_id();
        push @trait_ids, $trait_id;
    }

    foreach my $query_num (1..$number_queries) {

        # Randomly picking a number of accessions from all the available accessions
        my @random_accession_names = @accession_names[(shuffle(0..$#accession_names))[0..$random_accessions-1]];
        print STDERR Dumper \@random_accession_names;

        # Retrieving the stock database ids from the accession names
        my @accession_stock_ids = ();
        my $accession_stock_rs = $schema->resultset("Stock::Stock")->search({type_id=>$accession_cvterm_id, uniquename => {-in => \@random_accession_names}});
        while (my $r = $accession_stock_rs->next()){
            push @accession_stock_ids, $r->stock_id();
        }

        # Repeating query a number of times
        foreach my $query_repeat_num (1..$query_repeat) {

            # For genotyping data there are two formats being tested: VCF and DosageMatrix
            foreach my $download_format (@$download_formats) {
                print STDERR "GenoDownload index $index format $download_format query $query_num queryrepeat $query_repeat_num computefromparents $compute_from_parents\n";

                # Start timer for retrieving genotype data
                my $geno_start = [ Time::HiRes::gettimeofday() ];

                # Search for genotyping data in given format and query parameters
                my $geno = CXGN::Genotype::DownloadFactory->instantiate(
                    $download_format,
                    {
                        bcs_schema=>$schema,
                        people_schema=>$people_schema,
                        cache_root_dir=>$opt_c,
                        accession_list=>\@accession_stock_ids,
                        protocol_id_list=>[$genotyping_protocol_id],
                        compute_from_parents=>$compute_from_parents,
                        marker_name_list=>\@marker_names_subset
                    }
                );
                my $file_handle = $geno->download(
                    $shared_cluster_dir_config,
                    $backend_config,
                    $cluster_host_config,
                    $web_cluster_queue_config,
                    $basepath_config
                );

                # Stop timer for retrieving genotype data and record time
                my $geno_end = Time::HiRes::tv_interval($geno_start);
                push @{$execution_times{$genotyping_protocol_name}->{genotyping_time}->{$download_format}->{$compute_from_parents}}, $geno_end;
                print STDERR Dumper $geno_end;

                # open my $fh_geno, "<&", $file_handle or die "Can't open output file: $!";
                # while (my $gt_line = <$fh_geno>) {
                #     print STDERR $gt_line;
                # }
            }

            # Start timer for retrieving genomic relationship matrix
            my $grm_start = [ Time::HiRes::gettimeofday() ];

            my $grm_search = CXGN::Genotype::GRM->new({
                bcs_schema=>$schema,
                people_schema=>$people_schema,
                grm_temp_file=>$opt_g.$index.$query_num,
                accession_id_list=>\@accession_stock_ids,
                protocol_id=>$genotyping_protocol_id,
                get_grm_for_parental_accessions=>$compute_from_parents,
                cache_root=>$opt_c,
                download_format=>'matrix',
                minor_allele_frequency=>0.01,
                marker_filter=>0.6,
                individuals_filter=>0.8
            });
            my $genomic_relationship_matrix_file_handle = $grm_search->download_grm(
                'filehandle',
                $shared_cluster_dir_config,
                $backend_config,
                $cluster_host_config,
                $web_cluster_queue_config,
                $basepath_config
            );

            my $grm_end = Time::HiRes::tv_interval($grm_start);
            push @{$execution_times{$genotyping_protocol_name}->{grm_time}->{$compute_from_parents}}, $grm_end;
            print STDERR Dumper $grm_end;


            # open my $fh_grm, "<&", $genomic_relationship_matrix_file_handle or die "Can't open output file: $!";
            # while (my $grm_line = <$fh_grm>) {
            #     print STDERR $grm_line;
            # }

            # Start timer for retrieving GWAS
            my $gwas_start = [ Time::HiRes::gettimeofday() ];

            my $geno = CXGN::Genotype::GWAS->new({
                bcs_schema=>$schema,
                grm_temp_file=>$opt_g.$index.$query_num."_gwas_grm",
                gwas_temp_file=>$opt_g.$index.$query_num."_gwas",
                pheno_temp_file=>$opt_g.$index.$query_num."_gwas_pheno",
                people_schema=>$people_schema,
                download_format=>'manhattan_qq_plots', #either results_tsv or manhattan_qq_plots
                accession_id_list=>\@accession_stock_ids,
                trait_id_list=>[$trait_ids[0],$trait_ids[1]],
                traits_are_repeated_measurements=>0,
                protocol_id=>$genotyping_protocol_id,
                get_grm_for_parental_accessions=>$compute_from_parents,
                cache_root=>$opt_c,
                minor_allele_frequency=>0.01,
                marker_filter=>0.6,
                individuals_filter=>0.8
            });
            my $gwas_file_handle = $geno->download_gwas(
                $shared_cluster_dir_config,
                $backend_config,
                $cluster_host_config,
                $web_cluster_queue_config,
                $basepath_config
            );

            # Stop timer for retrieving GWAS data and record time
            my $gwas_end = Time::HiRes::tv_interval($gwas_start);
            push @{$execution_times{$genotyping_protocol_name}->{gwas_time}->{$compute_from_parents}}, $gwas_end;
            print STDERR Dumper $gwas_end;

            # Start timer for retrieving phenotypic data
            my $pheno_start = [ Time::HiRes::gettimeofday() ];

            # Search for phenotypic data given query parameters
            my $phenotypes_search = CXGN::Phenotypes::SearchFactory->instantiate(
                'MaterializedViewTable',
                {
                    bcs_schema=>$schema,
                    data_level=>'plot',
                    trait_list=>\@trait_ids,
                    accession_list=>\@accession_stock_ids,
                }
            );
            my @data = $phenotypes_search->search();

            # Stop timer for retrieving phenotypic data and record time
            my $pheno_end = Time::HiRes::tv_interval($pheno_start);
            push @{$execution_times{$genotyping_protocol_name}->{phenotyping_time}}, $pheno_end;
            print STDERR Dumper $pheno_end;
        }
    }
}

print STDERR Dumper \%execution_times;

# Print out results of times
while (my ($genotyping_protocol_name, $obj) = each %execution_times) {
    my $geno_vcf_time_mean = mean($obj->{genotyping_time}->{'VCF'}->{0});
    my $geno_vcf_time_std = stddev($obj->{genotyping_time}->{'VCF'}->{0});
    my $geno_dosage_matrix_time_mean = mean($obj->{genotyping_time}->{'DosageMatrix'}->{0});
    my $geno_dosage_matrix_time_std = stddev($obj->{genotyping_time}->{'DosageMatrix'}->{0});

    if ($genotyping_protocol_name eq 'GenoProtMaize') {
        my $compute_from_parents_geno_vcf_time_mean = mean($obj->{genotyping_time}->{'VCF'}->{1});
        my $compute_from_parents_geno_vcf_time_std = stddev($obj->{genotyping_time}->{'VCF'}->{1});
        my $compute_from_parents_geno_dosage_matrix_time_mean = mean($obj->{genotyping_time}->{'DosageMatrix'}->{1});
        my $compute_from_parents_geno_dosage_matrix_time_std = stddev($obj->{genotyping_time}->{'DosageMatrix'}->{1});

        print STDERR "Result ComputedFromParents $genotyping_protocol_name: GenoMeanTimeVCF: $compute_from_parents_geno_vcf_time_mean GenoStdTimeVCF: $compute_from_parents_geno_vcf_time_std GenoMeanTimeDosageMatrix: $compute_from_parents_geno_dosage_matrix_time_mean GenoStdTimeDosageMatrix: $compute_from_parents_geno_dosage_matrix_time_std\n";
    }

    my $pheno_time_mean = mean($obj->{phenotyping_time});
    my $pheno_time_std = stddev($obj->{phenotyping_time});

    my $grm_time_mean = mean($obj->{grm_time});
    my $grm_time_std = stddev($obj->{grm_time});

    print STDERR "Result $genotyping_protocol_name: GenoMeanTimeVCF: $geno_vcf_time_mean GenoStdTimeVCF: $geno_vcf_time_std GenoMeanTimeDosageMatrix: $geno_dosage_matrix_time_mean GenoStdTimeDosageMatrix: $geno_dosage_matrix_time_std GRMMeanTime: $grm_time_mean GRMStdTime: $grm_time_std PhenoMeanTime: $pheno_time_mean PhenoStdTime: $pheno_time_std\n";
}

print STDERR "Complete!\n";
