3 use Test::More qw | no_plan |;
5 use File::Temp qw | tempfile |;
6 use File::Basename qw | basename dirname |;
8 use CXGN::Dataset::File;
12 use SGN::Test::Fixture;
14 my $f = SGN::Test::Fixture->new();
19 my ($fh, $tempfile) = tempfile( "mixedmodelsXXXXXX", DIR => $dir."/static/documents/tempfiles/", UNLINK => 0 );
21 print STDERR "Using tempfile $tempfile\n";
24 ok(-e $tempfile, "temp file created test");
27 my $ds = CXGN::Dataset->new( { people_schema => $f->people_schema(), schema => $f->bcs_schema() });
29 $ds->years( [ "2014", "2015" ]);
34 my $dsf = CXGN::Dataset::File->new( { people_schema => $f->people_schema(), schema => $f->bcs_schema(), sp_dataset_id => $ds->sp_dataset_id(), quotes => 0 });
36 $dsf->file_name($tempfile);
37 $dsf->retrieve_phenotypes();
39 ok( -e $tempfile."_phenotype.txt", "phenotype file exists test");
41 my $pheno_tempfile = $tempfile."_phenotype.txt";
43 my $file_size = `ls -al $pheno_tempfile`;
44 print STDERR "file size: $file_size\n";
45 ok($file_size =~ /167672/, 'phenotype file size test');
47 my $mm = CXGN::MixedModels->new();
49 $mm->tempfile($pheno_tempfile);
51 is($mm->engine(), "lme4", "test engine default setting");
53 my $SYSTEM_MODE = $ENV{SYSTEM};
55 foreach my $engine ("lme4", "sommer") {
59 $mm->dependent_variables( [ "dry matter content percentage|CO_334:0000092" ]); #, "fresh root weight|CO_334:0000012" ] );
61 $mm->fixed_factors( [ "replicate" ] );
63 $mm->random_factors( [ "germplasmName" ] );
65 my ($model_string, $error) = $mm->generate_model();
67 print STDERR "MODEL STRING: $model_string ERROR: $error\n";
69 if ($engine eq "lme4") {
70 is($model_string, "replicate + (1|germplasmName)", "model string test for BLUPs");
73 print STDERR "MODEL STRING: $model_string\n";
76 $mm->run_model("Slurm", "localhost", dirname($pheno_tempfile) );
78 print STDERR "Using tempfile base ".$mm->tempfile()."\n";
81 skip "Skip if run under git", 3 unless $SYSTEM_MODE ne "GITACTION";
83 ok( -e $mm->tempfile().".params", "check existence of parmams file");
84 ok( -e $mm->tempfile().".adjustedBLUPs", "check existence of adjustedBLUPs result file");
85 ok( -e $mm->tempfile().".BLUPs", "check existence of BLUPs result file");
87 # is( scalar(my @a = read_file($mm->tempfile().".adjustedBLUPs")), 413, "check number of lines in adjustedBLUEs file...");
94 # from package "emmeans"
96 # # An error caused by it - is captured in matrix structure build for the base package,
98 # https://github.com/cran/Matrix/blob/master/R/AllClass.R
99 # because that error is not from "emmeans" code and it happens only on gitaction with Slurm running
101 # invalid class "corMatrix" object: 'sd' slot has non-finite entries
103 # It only happens, at least for me, in gitaction build. Neither on local R system or in any alternative docker build that error not exist
104 # It makes no sense to try repair error which is not an error but very specific problem with gitaction workflow environment
105 ### END OF ERROR ON GITACTION EXPLANATION
108 $mm->dependent_variables( [ "fresh root weight|CO_334:0000012" ] );
110 $mm->fixed_factors([ "germplasmName" ]);
112 $mm->random_factors([ "replicate" ]);
114 my ($model_string, $error) = $mm->generate_model();
116 print STDERR "MODEL STRING = $model_string\n";
118 is($model_string, "germplasmName + (1|replicate)", "model string test for BLUEs");
120 $mm->run_model("Slurm", "localhost", dirname($pheno_tempfile));
125 skip "Skip if run under git", 2 unless $SYSTEM_MODE ne "GITACTION";
126 ok( -e $mm->tempfile() . ".adjustedBLUPs", "check existence of adjustedBLUEs result file");
127 ok( -e $mm->tempfile() . ".BLUPs", "check existence of BLUEs result file");
128 # is(scalar(my @a = read_file($mm->tempfile() . ".adjustedBLUEs")), 413, "check number of lines in adjustedBLUPs file...");
131 # cleanup for next test :-)
132 unlink($mm->tempfile() . ".adjustedBLUEs");
133 unlink($mm->tempfile() . ".BLUEs");