5 use SGN::Test::Fixture;
7 use Test::WWW::Mechanize;
9 use CXGN::Genotype::Protocol;
13 local $Data::Dumper::Indent = 0;
15 my $f = SGN::Test::Fixture->new();
16 my $schema = $f->bcs_schema;
17 my $dbh = $schema->storage->dbh;
18 my $people_schema = $f->people_schema;
20 my $mech = Test::WWW::Mechanize->new;
22 $mech->post_ok('http://localhost:3010/brapi/v1/token', [ "username"=> "janedoe", "password"=> "secretpw", "grant_type"=> "password" ]);
23 my $response = decode_json $mech->content;
24 is($response->{'metadata'}->{'status'}->[2]->{'message'}, 'Login Successfull');
25 my $sgn_session_id = $response->{access_token};
27 my $location_rs = $schema->resultset('NaturalDiversity::NdGeolocation')->search({description => 'Cornell Biotech'});
28 my $location_id = $location_rs->first->nd_geolocation_id;
30 my $bp_rs = $schema->resultset('Project::Project')->search({name => 'test'});
31 my $breeding_program_id = $bp_rs->first->project_id;
33 #adding genotyping data for testing markerset and accession search
34 my $file = $f->config->{basepath}."/t/data/genotype_data/test_genotype_upload.vcf";
36 my $ua = LWP::UserAgent->new;
37 $response = $ua->post(
38 'http://localhost:3010/ajax/genotype/upload',
39 Content_Type => 'form-data',
41 upload_genotype_vcf_file_input => [ $file, 'genotype_vcf_data_upload' ],
42 "sgn_session_id"=>$sgn_session_id,
43 "upload_genotypes_species_name_input"=>"Manihot esculenta",
44 "upload_genotype_vcf_project_name"=>"test_genotype_project",
45 "upload_genotype_location_select"=>$location_id,
46 "upload_genotype_year_select"=>"2015",
47 "upload_genotype_breeding_program_select"=>$breeding_program_id,
48 "upload_genotype_vcf_observation_type"=>"accession",
49 "upload_genotype_vcf_facility_select"=>"IGD",
50 "upload_genotype_vcf_project_description"=>"Test uploading",
51 "upload_genotype_vcf_protocol_name"=>"2015_genotype_protocol",
52 "upload_genotype_vcf_include_igd_numbers"=>0,
53 "upload_genotype_vcf_reference_genome_name"=>"Mesculenta_511_v7",
54 "upload_genotype_add_new_accessions"=>0,
55 "upload_genotype_accept_warnings"=>1,
59 #print STDERR Dumper $response;
60 ok($response->is_success);
61 my $message = $response->decoded_content;
62 my $message_hash = decode_json $message;
63 is($message_hash->{success}, 1);
64 ok($message_hash->{project_id});
65 ok($message_hash->{nd_protocol_id});
67 my $protocol_id = $message_hash->{nd_protocol_id};
68 my $project_id = $message_hash->{project_id};
70 #test adding markerset
71 $mech->get_ok('http://localhost:3010/list/new?name=test_markerset_1&desc=test');
72 $response = decode_json $mech->content;
73 my $markerset_list_id = $response->{list_id};
74 #print STDERR "MARKERSET LIST ID =".Dumper($markerset_list_id)."\n";
75 ok($markerset_list_id);
77 $mech->get_ok('http://localhost:3010/list/item/add?list_id='.$markerset_list_id.'&element={"genotyping_protocol_name":"2015_genotype_protocol", "genotyping_protocol_id":'.$protocol_id.', "genotyping_data_type":"Dosage"}');
78 $response = decode_json $mech->content;
79 is($response->[0],'SUCCESS');
81 $mech->get_ok('http://localhost:3010/list/item/add?list_id='.$markerset_list_id.'&element={"marker_name":"S1_21597", "allele_dosage":"0"}');
82 $response = decode_json $mech->content;
83 is($response->[0],'SUCCESS');
85 $mech->get_ok('http://localhost:3010/list/new?name=test_markerset_2&desc=test');
86 $response = decode_json $mech->content;
87 my $markerset2_list_id = $response->{list_id};
88 #print STDERR "MARKERSET LIST ID =".Dumper($markerset_list_id)."\n";
89 ok($markerset2_list_id);
91 $mech->get_ok('http://localhost:3010/list/item/add?list_id='.$markerset2_list_id.'&element={"genotyping_protocol_name":"2015_genotype_protocol", "genotyping_protocol_id":'.$protocol_id.', "genotyping_data_type":"SNP"}');
92 $response = decode_json $mech->content;
93 is($response->[0],'SUCCESS');
95 $mech->get_ok('http://localhost:3010/list/item/add?list_id='.$markerset2_list_id.'&element={"marker_name":"S1_21597","allele1":"G","allele2":"G"}');
96 $response = decode_json $mech->content;
97 is($response->[0],'SUCCESS');
99 #create a list of accessions
100 $mech->get_ok('http://localhost:3010/list/new?name=accession_list_1&desc=test');
101 $response = decode_json $mech->content;
102 my $accession_list_id = $response->{list_id};
103 #print STDERR "ACCESSION LIST ID =".Dumper($accession_list_id)."\n";
104 ok($accession_list_id);
106 my @accessions = qw(UG120001 UG120002 UG120003 UG120004 UG120005 UG120006 UG120007 UG120008 UG120009 UG120010 UG120011 UG120012 UG120013 UG120014 UG120015 UG120016 UG120017 UG120018 UG120019 UG120020 UG120021);
108 my $accession_list = CXGN::List->new( { dbh=>$dbh, list_id => $accession_list_id });
109 my $response = $accession_list->add_bulk(\@accessions);
110 is($response->{'count'},21);
112 #test searching accessions with dosage
113 $mech->get_ok('http://localhost:3010/ajax/search/search_stocks_using_markerset?stock_list_id='.$accession_list_id.'&markerset_id='.$markerset_list_id);
114 $response = decode_json $mech->content;
115 #print STDERR "RESPONSE 4=".Dumper($response)."\n";
116 my %result_hash1 = %{$response};
117 my $selected_accessions_dosage = $result_hash1{'data'};
118 my $number_of_accessions_dosage = scalar@$selected_accessions_dosage;
119 is($number_of_accessions_dosage,16);
121 #test searching accessions with snp
122 $mech->get_ok('http://localhost:3010/ajax/search/search_stocks_using_markerset?stock_list_id='.$accession_list_id.'&markerset_id='.$markerset2_list_id);
123 $response = decode_json $mech->content;
124 #print STDERR "RESPONSE 4=".Dumper($response)."\n";
125 my %result_hash2 = %{$response};
126 my $selected_accessions_snp = $result_hash2{'data'};
127 my $number_of_accessions_snp = scalar@$selected_accessions_snp;
128 is($number_of_accessions_snp,14);
130 # Delete genotype protocol after testing
131 $mech->get("/ajax/genotyping_protocol/delete/$protocol_id");
132 $response = decode_json $mech->content;
133 is($response->{'success'}, 1);
136 CXGN::List::delete_list($schema->storage->dbh, $markerset_list_id);
137 CXGN::List::delete_list($schema->storage->dbh, $markerset2_list_id);
138 CXGN::List::delete_list($schema->storage->dbh, $accession_list_id);
139 $schema->resultset("Project::Project")->find({project_id=>$project_id})->delete();