6 use CXGN
::DB
::InsertDBH
;
8 use CXGN
::Phenome
::Genotype
;
9 use CXGN
::Phenome
::GenotypeRegion
;
10 use CXGN
::Phenome
::GenotypeExperiment
;
11 use CXGN
::Phenome
::Individual
;
12 use CXGN
::Cview
::Map
::Tools
;
13 use CXGN
::Marker
::Tools
;
15 our ($opt_D, $opt_H, $opt_s, $opt_m, $opt_b, $opt_p);
17 getopts
('D:H:s:m:b:p:');
20 print STDERR
" -p population_id is required. Stop.\n";
26 print STDERR
"no -s specified. Using default of 206.\n";
28 my $sp_person_id=$opt_s;
32 print STDERR
"Using a default of $opt_m for the reference map id.\n";
34 my $reference_map_id=$opt_m;
38 print STDERR
"Using a default background accession id of $opt_b.\n";
40 my $background_accession_id=$opt_b;
44 my $dbh = CXGN
::DB
::InsertDBH
->new({ dbname
=>$opt_D,
52 Usage: load_genotypes.pl -H host -D dbname [-s sp_person_id] file\n
59 my $map_version_id = CXGN
::Cview
::Map
::Tools
::find_current_version
($dbh, $reference_map_id);
61 open(F
, "<$file") || die "Can't open file '$file'\n";
63 #my $first_line = (<F>); # throw away, contains chr info
67 my (undef, @markers) = split /\t/, $header;
69 print STDERR
"Markers @markers\n";
73 my $experiment = CXGN
::Phenome
::GenotypeExperiment
->new($dbh);
75 $experiment->set_background_accession_id($background_accession_id);
76 $experiment->set_experiment_name("QTL experiment");
77 $experiment->set_reference_map_id($reference_map_id);
78 $experiment->set_sp_person_id($sp_person_id);
79 $experiment->set_preferred(1);
80 my $experiment_id = $experiment->store();
85 my ($individual_name, @scores) = split /\t/;
86 print STDERR
"Processing individual $individual_name...\n";
87 my (@individuals) = CXGN
::Phenome
::Individual
->new_with_name($dbh, $individual_name);
90 print STDERR
"Found several individuals with name $individual_name. Skipping.\n";
93 my $individual = $individuals[0];
95 if ($individual && $individual->get_population_id() != $opt_p) {
96 print STDERR
"Individual $individual_name is not from population $opt_p\n";
102 print STDERR
"Individual $individual_name not found. \n";
104 print STDERR
"Can't continue without individual $individual_name\n";
105 print STDERR
"Insert individual? Give population id or type N:";
106 my $response = <STDIN
>;
108 if ($response=~/n/i) { next(); }
112 print STDERR
"Creating new individual...\n";
113 $individual=CXGN
::Phenome
::Individual
->new($dbh);
114 $individual->set_name($individual_name);
115 $individual->set_population_id($opt_p); #!!!!!!!!!!!
116 my $individual_id = $individual->store();
118 print STDERR
"Inserted Individual $individual_name with id $individual_id\n";
125 my $genotype = CXGN
::Phenome
::Genotype
->new($dbh);
127 print STDERR
"experiment_id is $experiment_id\n";
128 $genotype->set_genotype_experiment_id($experiment_id);
129 $genotype->set_individual_id($individual->get_individual_id());
132 my $genotype_id = $genotype->store();
134 for(my $i=0; $i<@scores; $i++) {
135 my $genotype_region = CXGN
::Phenome
::GenotypeRegion
->new($dbh);
137 my $clean_name = $markers[$i];
138 $clean_name=~s/\*//g;
139 $clean_name=~s/^ *(.*) *$/$1/; #clean leading/trailing spaces
140 $clean_name = CXGN
::Marker
::Tools
::clean_marker_name
($clean_name);
141 my $marker = CXGN
::Marker
->new_with_name($dbh, $clean_name);
143 if (!$scores[$i] || ($scores[$i] =~/\-/)) {
144 print STDERR
"No zygocity information ($scores[$i]). Skipping...\n";
149 print STDERR
"Marker $clean_name not found. Skipping...\n";
153 my $experiments = $marker->experiments();
155 foreach my $e (@
$experiments) {
156 if (defined($e->{location
})) {
158 if ($e->{location
}->map_version_id() eq $map_version_id) {
159 #print STDERR "Defined location for marker $markers[$i] on map $map_version_id...\n";
160 $lg_id = $e->{location
}->lg_id();
166 print STDERR
"Marker $markers[$i] has no mapped locations on map version $map_version_id. Inserting undef for lg_id \n";
170 $genotype_region->set_phenome_genotype_id($genotype_id);
171 $genotype_region->set_marker_id_nn($marker->marker_id());
172 $genotype_region->set_marker_id_ns($marker->marker_id());
173 $genotype_region->set_marker_id_sn($marker->marker_id());
174 $genotype_region->set_marker_id_ss($marker->marker_id());
175 $genotype_region->set_lg_id($lg_id);
176 print STDERR
"Setting score: $scores[$i]\n";
177 $genotype_region->set_mapmaker_zygocity_code($scores[$i]);
179 $genotype_region->set_type("map");
181 $genotype_region->store();
190 print STDERR
"An error occurred: $@. ROLLED BACK CHANGES.\n";
193 print STDERR
"All fine. Committing...\n";
196 print STDERR
"Done.\n";