1 package CXGN
::Cview
::Cview_data_adapter
;
3 # NOTE: THIS MODULE IS DEPRECATED AND WILL BE REMOVED SOON.
9 use CXGN
::Cview
::Marker
;
10 use CXGN
::Cview
::Marker
::SequencedBAC
;
11 use CXGN
::Cview
::Marker
::FISHMarker
;
12 use CXGN
::Genomic
::Clone
;
14 use CXGN
::Cview
::Config
;
16 our $config = CXGN
::Cview
::Config
->new;
19 =head2 function get_chromosome()
21 Synopsis: gets a chromosome object of the appropriate type given a map_version_id
22 Arguments: database handle, CXGN::Map object, and a chr_nr.
23 Returns: a chromosome object of the appropriate type.
31 my $map = shift; # CXGN::Map object
35 unless (defined($type)) {$type='';}
36 if ($type =~ /fish/i) {
37 $c=CXGN
::Cview
::Chromosome
::PachyteneIdiogram
-> new
($chr_nr, 100, 100, 40);
38 CXGN
::Cview
::Cview_data_adapter
::fetch_pachytene_idiogram
($c, $chr_nr);
39 CXGN
::Cview
::Cview_data_adapter
::fetch_fish_chromosome
($dbh, $c, $map, $chr_nr, 0, $type);
45 $c= CXGN
::Cview
::Chromosome
-> new
($chr_nr, 60, 100, 40);
46 CXGN
::Cview
::Cview_data_adapter
::fetch_chromosome
($dbh, $c, $map, $chr_nr, 0, $type);
52 sub fetch_chromosome
{
54 my $chromosome = shift; # the chromosome object
55 my $map = shift; # CXGN::Map object
56 my $chr_nr = shift; # the chromosome name
57 my $marker_confidence_cutoff = shift; # the confidence cutoff. 3=frame 2=coseg 1=interval LOD=2 0=interval
60 # if ($type=~/fish/i) {
61 # return fetch_fish_chromosome($dbh, $chromosome, $map_id, $chr_nr);
65 if (!$marker_confidence_cutoff) { $marker_confidence_cutoff=-1; }
69 my $sgn = $dbh->qualify_schema('sgn');
70 my $physical = $dbh->qualify_schema('physical');
72 if ($map->map_id() == CXGN
::Map
::Tools
::current_tomato_map_id
()) {
74 my $Sequenced_BAC_query =
77 distinct $physical.bac_marker_matches.bac_id,
78 $physical.bac_marker_matches.cornell_clone_name,
79 $physical.bac_marker_matches.marker_id,
80 $physical.bac_marker_matches.position
82 $physical.bac_marker_matches
83 LEFT JOIN $sgn.linkage_group USING (lg_id)
84 LEFT JOIN sgn_people.bac_status USING (bac_id)
86 $sgn.linkage_group.lg_name=?
87 AND sgn_people.bac_status.status='complete'
89 my $sth2 = $dbh->prepare($Sequenced_BAC_query);
90 $sth2->execute($chr_nr);
91 while (my ($bac_id, $name, $marker_id, $offset)=$sth2->fetchrow_array()) {
92 # print STDERR "Sequenced BAC for: $bac_id, $name, $marker_id, $offset...\n";
93 $name = CXGN
::Genomic
::Clone
->retrieve($bac_id)->clone_name();
95 my $m = CXGN
::Cview
::Marker
::SequencedBAC
->new($chromosome, $bac_id, $name, "", "", "", "", $offset);
96 $m->get_label()->set_text_color(200,200,80);
97 $m->get_label()->set_line_color(200,200,80);
98 $seq_bac{$marker_id}=$m;
102 # get the "normal" markers
107 marker_experiment.marker_id,
117 inner join $sgn.linkage_group using (map_version_id)
118 inner join $sgn.marker_location using (lg_id)
119 inner join $sgn.marker_experiment using (location_id)
120 inner join $sgn.marker_alias using (marker_id)
121 inner join $sgn.marker_confidence using (confidence_id)
122 left join $sgn.marker_collectible using (marker_id)
123 left join $sgn.marker_collection using (mc_id)
125 map_version.map_version_id=?
137 # marker_types.type_name,
139 # marker_locations.order_in_loc,
140 # location_subscript,
144 my $sth = $dbh -> prepare
($query);
145 $sth -> execute
($map->map_version_id(), $chr_nr);
147 while (my ($marker_id, $marker_name, $marker_type, $confidence, $order_in_loc, $location_subscript, $offset, $loc_type) = $sth->fetchrow_array()) {
148 #print STDERR "Marker Read: $marker_id\t$marker_name\t$marker_type\t$offset\n";
149 my $m = CXGN
::Cview
::Marker
-> new
($chromosome, $marker_id, $marker_name, $marker_type, $confidence, $order_in_loc, $location_subscript, $offset, undef , $loc_type, 0);
150 #print STDERR "dataadapter baccount = $bac_count!\n";
151 if ($loc_type == 100) { $m -> set_frame_marker
(); }
152 $m -> set_url
("/search/markers/markerinfo.pl?marker_id=".$m->get_id());
153 $chromosome->add_marker($m);
155 if (exists($seq_bac{$marker_id})) {
156 #print STDERR "Adding Sequenced BAC [".($seq_bac{$marker_id}->get_name())."] to map...[$marker_id]\n";
157 $chromosome->add_marker($seq_bac{$marker_id});
161 $chromosome -> _calculate_chromosome_length
();
164 sub fetch_fish_chromosome
{
166 my $chromosome = shift;
167 my $map = shift; # CXGN::Map object
169 # The following query is a composition of 3 subqueries (look for the 'AS'
170 # keywords), joined using the clone_id. Here's what the subqueries do:
172 # * clone_id_and_percent: gets the average percent distance from the
173 # centromere as a signed float between -1.0 and +1.0, for each
174 # BAC on a given chromosome. This is done by first computing the
175 # average absolute distance from the centromere (signed, in um),
176 # and then dividing by the length of the arm that the average
177 # would be located on.
179 # * min_marker_for_clone: finds one marker associated with the BAC
182 # * clone_info: finds the library shortname and clone name components.
184 SELECT shortname, clone_id, platenum, wellrow, wellcol, percent, marker_id
185 FROM (SELECT clone_id, (CASE WHEN absdist < 0
186 THEN absdist / short_arm_length
187 ELSE absdist / long_arm_length END) AS percent
188 FROM (SELECT clone_id, chromo_num,
189 AVG(percent_from_centromere * arm_length *
190 CASE WHEN r.chromo_arm = 'P' THEN -1 ELSE 1 END)
193 JOIN fish_karyotype_constants k USING (chromo_num, chromo_arm)
195 GROUP BY clone_id, chromo_num) AS clone_id_and_absdist
196 JOIN (SELECT k1.chromo_num, k1.arm_length AS short_arm_length,
197 k2.arm_length AS long_arm_length
198 FROM fish_karyotype_constants k1
199 JOIN fish_karyotype_constants k2 USING (chromo_num)
200 WHERE k1.chromo_arm = 'P' AND k2.chromo_arm = 'Q')
201 AS karyotype_rearranged USING (chromo_num))
202 AS clone_id_and_percent
203 LEFT JOIN (SELECT clone_id, MIN (m.marker_id) AS marker_id
204 FROM sgn.fish_result AS c
205 LEFT JOIN physical.overgo_associations a ON (c.clone_id = a.bac_id)
206 LEFT JOIN physical.probe_markers m USING (overgo_probe_id)
207 LEFT JOIN marker_experiment e ON (m.marker_id = e.marker_id)
208 LEFT JOIN marker_location l ON (l.location_id = e.location_id)
209 LEFT JOIN linkage_group g ON (g.lg_id = l.lg_id)
210 LEFT JOIN map_version v ON (g.map_version_id = v.map_version_id)
211 WHERE (v.current_version = 't' OR v.current_version IS NULL)
212 AND (v.map_id = ? OR v.map_id IS NULL)
214 AS min_marker_for_clone USING (clone_id)
215 LEFT JOIN (SELECT shortname, clone_id, platenum, wellrow, wellcol
217 JOIN genomic.library USING (library_id))
218 AS clone_info USING (clone_id)
222 my $sth = $dbh -> prepare
($query);
223 $sth->execute($chr_nr, CXGN
::Map
::Tools
::current_tomato_map_id
);
224 while (my ($library_name, $clone_id, $platenum, $wellcol, $wellrow, $percent, $marker_id) = $sth->fetchrow_array()) {
225 #print STDERR "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!Adding marker BAC:$library_name, $wellrow, $wellcol, $chromo_arm etc.\n";
228 $offset = $percent * 100;
230 my $clone_name = CXGN
::Genomic
::Clone
->retrieve($clone_id)->clone_name();
232 my $m = CXGN
::Cview
::Marker
::FISHMarker
-> new
($chromosome, $marker_id, $clone_name, "", 3, $offset+100, "", $offset );
233 $m -> set_url
("/maps/physical/clone_info.pl?id=".$clone_id);
234 $chromosome->add_marker($m);
240 # sub get_overgo_bac_data {
247 # if (physical.probe_markers.overgo_probe_id IS NULL, 0, 1),
248 # count(distinct(physical.overgo_associations.bac_id))
251 # left join physical.probe_markers using (marker_id)
252 # left join physical.overgo_associations using (overgo_probe_id)
259 # my $sth = $dbh -> prepare($query);
260 # $sth -> execute($m->get_id());
262 # if (my ($probes, $bacs) = $sth -> fetchrow_array()) {
263 # if ($probes) { $m->set_has_overgo(); }
264 # if ($bacs) { $m->set_has_bacs($bacs); }
270 sub fetch_chromosome_overgo
{
272 my $chromosome = shift; # the chromosome object
273 my $map = shift; # CXGN::Map object
274 my $chr_nr = shift; # the chromosome number
275 my $start = shift; # the start of the section in cM
276 my $end = shift; # the end of the section in cM
278 # main query to get the marker data, including the BACs that are associated with this
279 # marker -- needs to be refactored to work with the materialized views for speed improvements.
284 marker_experiment.marker_id,
292 min(physical.probe_markers.overgo_probe_id),
293 count(distinct(physical.overgo_associations.bac_id)),
294 max(physical.oa_plausibility.plausible)
297 inner join linkage_group using (map_version_id)
298 inner join marker_location using (lg_id)
299 inner join marker_experiment using (location_id)
300 inner join marker_alias using (marker_id)
301 inner join marker_confidence using (confidence_id)
302 left join marker_collectible using (marker_id)
303 left join marker_collection using (mc_id)
304 LEFT JOIN physical.probe_markers ON (marker_experiment.marker_id=physical.probe_markers.marker_id)
305 LEFT JOIN physical.overgo_associations USING (overgo_probe_id)
306 LEFT JOIN physical.oa_plausibility USING (overgo_assoc_id)
308 map_version.map_version_id=?
311 -- and current_version='t'
315 marker_experiment.marker_id,
324 max(physical.oa_plausibility.plausible),
325 max(physical.probe_markers.overgo_probe_id)
329 my $sth = $dbh -> prepare
($query);
330 # print STDERR "START/END: $start/$end\n";
331 $sth -> execute
($map->map_version_id, $chr_nr, $start, $end);
333 # for each marker, look if there is a associated fully sequenced BAC, and add that
334 # as a marker of type Sequenced_BAC to the map at the right location
342 physical.bac_marker_matches
343 JOIN sgn_people.bac_status using (bac_id)
345 physical.bac_marker_matches.marker_id=?
346 AND sgn_people.bac_status.status='complete'
349 my $bac_status_h = $dbh->prepare($bac_status_q);
352 while (my ($marker_id, $marker_name, $marker_type, $confidence, $order_in_loc, $location_subscript, $offset, $loc_type, $overgo, $bac_count, $plausible, $status, $bac_name, $bac_id) = $sth->fetchrow_array()) {
353 #print STDERR "Marker Read: $marker_id\t$marker_name\t$marker_type\toffset: $offset\tovergo: $overgo\tbac_count: $bac_count\tplausible: $plausible\n";
357 if (!$plausible || $plausible == 0) { $bac_count = 0; }
358 my $m = CXGN
::Cview
::Marker
-> new
($chromosome, $marker_id, $marker_name, $marker_type, $confidence, $order_in_loc, $location_subscript, $offset, , $loc_type, 0, $overgo, $bac_count);
359 #print STDERR "dataadapter baccount = $bac_count!\n";
360 if ($loc_type == 100) { $m -> set_frame_marker
(); }
362 # only add the sequenced BAC information to the F2-2000.
364 if ($map->map_id == CXGN
::Map
::Tools
::current_tomato_map_id
()) {
366 $bac_status_h->execute($marker_id);
367 ($seq_bac_name, $seq_bac_id) = $bac_status_h->fetchrow_array();
369 # change the name to look more standard
372 if ($seq_bac_name =~ m/(\d+)([A-Z])(\d+)/i) {
373 $seq_bac_name = sprintf ("%3s%04d%1s%02d", "HBa",$1,$2,$3);
375 $seq_bac = CXGN
::Cview
::Marker
::SequencedBAC
->new($chromosome, $seq_bac_id, $seq_bac_name, "", "", "", "", $offset);
379 # add the marker $m to the chromosome
381 $chromosome->add_marker($m);
383 # add the sequenced BAC to the chromosome
384 # -url link needs to be changed
385 # -add a confidence level of 3 so that it is always displayed.
388 $seq_bac->set_confidence(3);
389 $seq_bac->set_url("/maps/physical/clone_info.pl?id=$seq_bac_id");
390 $chromosome->add_marker($seq_bac);
393 $chromosome -> _calculate_chromosome_length
();
397 =head2 fetch_chromosome_connections
408 sub fetch_chromosome_connections
{
410 my $map = shift; # CXGN::Map object
416 c_map_version.map_version_id,
418 c_linkage_group.lg_name,
419 count(distinct(marker.marker_id)) as marker_count
422 join marker_experiment using(marker_id)
423 join marker_location using (location_id)
424 join linkage_group on (marker_location.lg_id=linkage_group.lg_id)
425 join map_version on (linkage_group.map_version_id=map_version.map_version_id)
427 join marker_experiment as c_marker_experiment on
428 (marker.marker_id=c_marker_experiment.marker_id)
429 join marker_location as c_marker_location on
430 (c_marker_experiment.location_id=c_marker_location.location_id)
431 join linkage_group as c_linkage_group on (c_marker_location.lg_id=c_linkage_group.lg_id)
432 join map_version as c_map_version on
433 (c_linkage_group.map_version_id=c_map_version.map_version_id)
434 join map as c_map on (c_map.map_id=c_map_version.map_id)
436 map_version.map_version_id=?
437 and linkage_group.lg_name=?
438 and c_map_version.map_version_id !=map_version.map_version_id
439 and c_map_version.current_version='t'
441 c_map_version.map_version_id,
442 c_linkage_group.lg_name,
448 my $sth = $dbh -> prepare
($query);
449 $sth -> execute
($map->map_version_id(), $chr_nr);
452 #print STDERR "***************** Done with query..\n";
453 while (my $hashref = $sth->fetchrow_hashref()) {
454 #print STDERR "READING----> $hashref->{map_version_id} $hashref->{chr_nr} $hashref->{marker_count}\n";
455 push @chr_list, $hashref;
461 =head2 fetch_available_maps
472 sub fetch_available_maps
{
475 my $query = "SELECT map_version.map_version_id, short_name
476 FROM map_version JOIN map using (map_id)
477 WHERE current_version='t' order by short_name";
478 my $sth = $dbh -> prepare
($query);
482 while (my $map_ref = $sth -> fetchrow_hashref
()) {
483 push @maps, $map_ref;
490 my $physical = shift;
491 my $map = shift; # CXGN::Map object
497 distinct(physical.bacs.bac_id),
498 marker_experiment.marker_id,
502 inner join linkage_group using (map_version_id)
503 inner join marker_location using (lg_id)
504 inner join marker_experiment using (location_id)
505 inner join physical.probe_markers using (marker_id)
506 inner join physical.overgo_associations using (overgo_probe_id)
507 inner join physical.bacs using (bac_id)
508 inner join physical.oa_plausibility using (overgo_assoc_id)
510 map_version.map_version_id=?
512 and current_version='t'
513 and physical.oa_plausibility.plausible=1
516 # print STDERR "Query: $query\n";
517 my $sth = $dbh->prepare($query);
518 $sth -> execute
($map->map_version_id, $chr_nr);
519 while (my ($bac_id, $marker_id, $offset) = $sth->fetchrow_array()) {
520 #print STDERR "Physical: Marker Read: $bac_id\t$marker_id\t$offset\n";
521 $physical -> add_bac_association
($offset, $bac_id, "overgo");
524 my $sgn = $dbh -> qualify_schema
("sgn");
525 my $computational_query = "
526 SELECT distinct(physical.computational_associations.clone_id),
527 physical.computational_associations.marker_id,
528 marker_location.position
529 FROM physical.computational_associations
530 JOIN $sgn.marker_experiment using(marker_id)
531 JOIN $sgn.marker_location using (location_id)
532 JOIN $sgn.linkage_group using (lg_id)
533 JOIN $sgn.map_version on (map_version.map_version_id=linkage_group.map_version_id)
534 WHERE map_version.map_version_id=?
535 AND linkage_group.lg_name=?
536 ORDER BY marker_location.position
539 my $cq_sth = $dbh->prepare($computational_query);
540 $cq_sth->execute($map->map_version_id(), $chr_nr);
542 while (my ($clone_id, $marker_id, $offset)=$cq_sth->fetchrow_array()) {
543 $physical -> add_bac_association
($offset, $clone_id, "computational");
556 my @m2 = $IL -> get_markers
();
557 foreach my $m (@m2) {
558 $marker_pos{$m->get_name()} = $m-> get_offset
();
561 my $data_folder= $config->get_conf('basepath') . $config->get_conf('documents_subdir');
563 open (F
, '<', "$data_folder/cview/IL_defs/$IL_name".".txt") || die "Can't open IL file IL_defs/$IL_name $!\n";
567 my ($chromosome, $name, $start_marker, $end_marker) = split/\t/;
569 if ($chr_nr == $chromosome) {
570 $start_marker =~ s/^\s+(.*)/$1/;
571 $start_marker =~ s/(.*)\s+/$1/;
572 $end_marker =~ s/^\s+(.*)/$1/;
573 $end_marker =~ s/(.*)\s+/$1/;
574 if (exists($marker_pos{$start_marker}) && exists($marker_pos{$end_marker})) {
575 if ($name=~ /^\d+\-\w+/) {
576 $IL -> add_section
($name, $start_marker, $marker_pos{$start_marker}, $end_marker, $marker_pos{$end_marker});
578 elsif ($name =~/IL/i) {
579 $IL -> add_fragment
($name, $start_marker, $marker_pos{$start_marker},$end_marker,$marker_pos{$end_marker});
582 else { print STDERR
"$start_marker or $end_marker where not found.\n";}
590 =head2 fetch_pachytene_idiogram(pachytene_object, chromosome_number)
592 for a pachytene object, fetches the definition data from a file. The tab delimited file has the following columns:
595 feature type ( can be short_arm, telomere, centromere, )
596 feature start (a signed integer, negative numbers are on the short (top) arm, in arbitrary units, positive values on the long arm.
599 Comment lines starting with # are ignored.
604 sub fetch_pachytene_idiogram
{
605 my $pachytene_object = shift;
606 my $chromosome_number = shift;
608 #print STDERR "Fetching $chromosome_number pachytene\n";
609 my $vhost_conf=CXGN
::Cview
::Config
->new();
610 my $data_folder=$vhost_conf->get_conf('basepath').$vhost_conf->get_conf('documents_subdir');
611 open (F
, '<', "<$data_folder/cview/pachytene/pachytene_tomato_dapi.txt") || die "Can't open pachytene def file $!";
616 my ($chr, $type, $start, $end) = split/\t/;
618 # skip comment lines.
619 if (/^\#/) { next(); }
621 if ($chr == $chromosome_number) {
622 #print STDERR "Adding feature $type ($start, $end)\n";
623 $pachytene_object -> add_feature
($type, $start, $end);