start fixing test for multi cat phenotype upload.
[sgn.git] / t / unit_fixture / CXGN / Dataset.t
blob107bcd357bc13f412f21d22d36b2eeaae7d0f39c
2 use strict;
4 use lib 't/lib';
6 use Test::More;
7 use Data::Dumper;
8 use SGN::Test::Fixture;
9 use CXGN::Dataset;
10 use CXGN::Dataset::File;
11 use CXGN::Dataset::Cache;
13 my $t = SGN::Test::Fixture->new();
15 $t->dbh()->begin_work();
17 my $cache_root_dir = $t->config->{cache_file_path};
18 my $cluster_shared_tempdir_config = $t->config->{cluster_shared_tempdir};
19 my $backend_config = $t->config->{backend};
20 my $cluster_host_config = $t->config->{cluster_host};
21 my $web_cluster_queue_config = $t->config->{'web_cluster_queue'};
22 my $basepath_config = $t->config->{basepath};
23 my $forbid_cache = 0;
25 my $ds = CXGN::Dataset->new( people_schema => $t->people_schema(), schema => $t->bcs_schema());
26 $ds->accessions( [ 38913, 38914, 38915 ]);
27 $ds->years(['2012', '2013']);
28 $ds->traits([ 70666, 70741 ]);
29 $ds->trials([ 139, 144 ]);
30 $ds->plots( [ 40034, 40035 ]);
31 $ds->name("test");
32 $ds->description("test description");
34 $ds->name("test");
35 $ds->description("test description");
36 $ds->sp_person_id(41);
38 my $sp_dataset_id = $ds->store();
40 print STDERR "Dataset_id = $sp_dataset_id\n";
42 my $new_ds = CXGN::Dataset->new( people_schema => $t->people_schema(), schema => $t->bcs_schema(), sp_dataset_id => $sp_dataset_id);
44 is_deeply($new_ds->accessions(), $ds->accessions(), "accession store");
45 is_deeply($new_ds->years(), $ds->years(), "years store");
46 is_deeply($new_ds->traits(), $ds->traits(), "traits store");
47 is_deeply($new_ds->plots(), $ds->plots(), "plots store");
49 is($new_ds->name(), $ds->name(), "name store");
50 is($new_ds->description(), $ds->description(), "desc store");
51 is($new_ds->sp_person_id(), 41, "dataset owner");
53 my @datasets = (
54     CXGN::Dataset->new( people_schema => $t->people_schema(), schema => $t->bcs_schema()),
55     CXGN::Dataset::File->new( people_schema => $t->people_schema(), schema => $t->bcs_schema()),
56     CXGN::Dataset::Cache->new( people_schema => $t->people_schema(), schema => $t->bcs_schema(), cache_root => '/tmp/dataset_cache_root'),
57     );
59 foreach my $ds (@datasets) {
60     if ($ds->can("cache")) { $ds->cache->clear(); }
61     $ds->name("test");
62     $ds->description("test description");
64     $ds->accessions( [ 38913, 38914, 38915 ] );
66     my $sp_dataset_id = $ds->store();
68     my $trials = $ds->retrieve_trials();
70     is_deeply($trials, [
71                   [
72                    139,
73                    'Kasese solgs trial'
74                   ],
75                   [
76                    144,
77                    'test_t'
78                   ],
79                   [
80                    141,
81                    'trial2 NaCRRI'
82                   ]
83               ]
84               , "trial retrieve test");
86     if ($ds->isa("CXGN::Dataset::File")) {
87         ok(-e $ds->file_name()."_trials.txt", "trial file exists");
88     }
90     my $traits = $ds->retrieve_traits();
92     print STDERR Dumper($traits);
94     is_deeply($traits, [
95                   [
96                    70741,
97                    'dry matter content percentage|CO_334:0000092'
98                   ],
99                   [
100                    70666,
101                    'fresh root weight|CO_334:0000012'
102                   ],
103                   [
104                    70773,
105                    'fresh shoot weight measurement in kg|CO_334:0000016'
106                   ],
107                   [
108                    70668,
109                    'harvest index variable|CO_334:0000015'
110                   ]
111               ]
112         );
114     my $phenotypes = $ds->retrieve_phenotypes();
116     if ($ds->isa("CXGN::Dataset::File")) {
117         my$geno_filename = $ds->file_name()."_genotype.txt";
118         my $genotypes = $ds->retrieve_genotypes(1,$geno_filename,$cache_root_dir,$cluster_shared_tempdir_config,$backend_config,$cluster_host_config,$web_cluster_queue_config,$basepath_config,$forbid_cache);
119     } else {
120         my $genotypes = $ds->retrieve_genotypes(1);
121     }
123     my $years = $ds->retrieve_years();
125     is_deeply($years, [
126           [
127             '2014',
128             '2014'
129           ],
130           [
131             '2016',
132             '2016'
133           ]
134         ], "Year retrieve test");
136     my $plots = $ds->retrieve_plots();
138     is_deeply($plots, [
139                   [
140                    39299,
141                    'KASESE_TP2013_1029'
142                   ],
143                   [
144                    39895,
145                    'KASESE_TP2013_1590'
146                   ],
147                   [
148                    39424,
149                    'KASESE_TP2013_1717'
150                   ],
151                   [
152                    39607,
153                    'KASESE_TP2013_707'
154                   ],
155                   [
156                    39733,
157                    'KASESE_TP2013_880'
158                   ],
159                   [
160                    40343,
161                    'test_t113'
162                   ],
163                   [
164                    40493,
165                    'test_t249'
166                   ],
167                   [
168                    40669,
169                    'test_t407'
170                   ],
171                   [
172                    40676,
173                    'test_t413'
174                   ],
175                   [
176                    40814,
177                    'test_t538'
178                   ],
179                   [
180                    40819,
181                    'test_t542'
182                   ],
183                   [
184                    40956,
185                    'test_t666'
186                   ],
187                   [
188                    41168,
189                    'test_t857'
190                   ],
191                   [
192                    41237,
193                    'test_t919'
194                   ],
195                   [
196                    40033,
197                    'UG120036_block:2_plot:TP36_2012_NaCRRI'
198                   ],
199                   [
200                    40034,
201                    'UG120037_block:2_plot:TP37_2012_NaCRRI'
202                   ],
203                   [
204                    40035,
205                    'UG120038_block:2_plot:TP38_2012_NaCRRI'
206                   ]
207               ], "plot retrieve test");
213 print STDERR "DATA = ".$ds->data()."\n";
215 $ds->delete();
218 $t->dbh->rollback();
220 done_testing();