3 CXGN::Cview::Map::SGN::Contig - a class to generate maps of contigs aligned to the genome
7 my $map = CXGN::Cview::Map::SGN::Contig->new($dbh, $id);
8 my $chr = $map->get_chromosome(1);
13 Lukas Mueller <lam87@cornell.edu>
17 This class implements the following functions:
21 package CXGN
::Cview
::Map
::SGN
::Contig
;
26 use CXGN
::Cview
::Map
::SGN
::Genetic
;
27 use CXGN
::Cview
::Chromosome
::Physical
;
28 use CXGN
::Cview
::Marker
::Physical
;
31 use base qw
| CXGN
::Cview
::Map
::SGN
::Genetic
|;
36 Arguments: a database handle (preferably generated through
37 CXGN::DB::Connection) and a map id. Currently,
38 only one map_id is supported, with the alpha-
39 numeric id of "contig".
52 my $db_version_id = get_db_id
($dbh, $id);
53 my $self = $class -> SUPER
::new
($dbh, $db_version_id);
55 $self->set_preferred_chromosome_width(18);
56 $self->set_short_name($args->{short_name
});
57 $self->set_long_name($args->{long_name
});
58 $self->{gbrowse_fpc
} = $args->{gbrowse_fpc
};
59 $self->{temp_dir
} = $args->{temp_dir
} || '/tmp';
60 $self->set_abstract($args->{abstract
});
61 $self->{marker_link
} = $args->{marker_link
};
68 =head2 function get_chromosome()
82 my $map_factory = CXGN
::Cview
::MapFactory
->new($self->get_dbh());
83 my $id = get_db_id
($self->get_dbh(), $self->get_id());
84 my $genetic_map = $map_factory->create({map_version_id
=>$id});
85 my $genetic=$genetic_map->get_chromosome($chr_nr);
86 my $chromosome = CXGN
::Cview
::Chromosome
::Physical
->new();
88 my $largest_offset = 0;
90 my (@gff) = $self->{gbrowse_fpc
}->databases();
91 if (@gff > 1) { die "Can't deal with multiple databases right now..."; }
92 if (!@gff) { die "No database found!"; }
95 for my $m ($genetic->get_markers()) {
96 $m->set_chromosome($chromosome);
97 $chromosome->add_marker($m);
98 my $offset = $m->get_offset();
99 if ($offset > $largest_offset) {
100 $largest_offset=$offset;
104 my @gff_markers = $gff->features(-method
=> 'marker',
105 -attributes
=> { Name
=> $m->get_name() },
108 for my $gm (@gff_markers) {
109 @contigs = $gm->refseq();
112 for my $c (@contigs) {
113 my $contig = CXGN
::Cview
::Marker
::Physical
->new();
114 $contig->set_chromosome($chromosome);
115 $contig->set_name($c);
117 #my $url = "/gbrowse/gbrowse/sanger_tomato_fpc/?name=$c";
118 my $url = $self->{gbrowse_fpc
}->view_url({ name
=> $c });
119 $contig->set_marker_name($c);
120 $contig->set_marker_type("contig");
121 $contig->set_url($url);
122 $contig->set_offset($m->get_offset());
123 $contig->get_label()->set_name($c);
124 $contig->get_label()->set_url($url);
125 $contig->set_tooltip("Contig: $c. Anchored to: ".($m->get_name()).".");
126 $chromosome -> add_marker
($contig);
130 $chromosome->set_length($largest_offset);
131 $self->{chr}->[$chr_nr]=$chromosome;
136 =head2 function get_overview_chromosome()
146 sub get_overview_chromosome
{
150 my $bargraph = CXGN
::Cview
::Chromosome
::BarGraph
->new();
152 my $largest_offset = 0;
154 my $chromosome = $self->get_chromosome($chr_nr);
156 for my $m ($chromosome->get_markers()) {
157 if ($m->get_marker_type() eq "contig") {
158 my $offset = $m->get_offset();
159 $bargraph -> add_association
("manual", $offset, 1);
160 if ($offset>$largest_offset) { $largest_offset = $offset; }
166 =head2 function get_chromosome_connections()
176 sub get_chromosome_connections
{
180 # this map has no connections.!!!!
181 # push @list, { map_version_id=>CXGN::Cview::Map::Tools::find_current_version($self->get_dbh(), CXGN::Cview::Map::Tools::current_tomato_map_id), lg_name=>$chr_nr, marker_count=>"?", short_name=>"F2-2000" };
189 $db_id=~s/^.*(\d+)$/$1/;
190 return CXGN
::Cview
::Map
::Tools
::find_current_version
($dbh, $db_id);
198 sub get_marker_link
{
201 if ($clone_id) { return ""; }
205 sub get_marker_count
{
211 my @lengths = $self->cache_marker_counts();
212 return $lengths[$chr_nr-1];
215 sub cache_marker_counts
{
219 my $temp_file = File
::Spec
->catfile($self->{temp_dir
}, 'contig'.$self->get_id()."_marker_counts.txt");
221 if (! -e
($temp_file)) {
222 open(my $TEMP, '>', $temp_file) or die "Can't open $temp_file for writing: $!";
225 my $chr = $self->get_chromosome($c);
226 for my $m ($chr->get_markers()) {
227 if ($m->get_marker_name()=~ /^ctg/) {
231 print $TEMP "$c\t$count\n";
237 open(my $TEMP, '<', $temp_file) or die "Can't open $temp_file for reading: $!";
240 my ($c, $length) = split /\t/;
241 push @lengths, $length;
253 $count += $self->get_marker_count($c);
256 return "$count contigs have been assigned to this map";