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
::MapFactory
;
27 use CXGN
::Cview
::Map
::SGN
::Genetic
;
28 use CXGN
::Cview
::Chromosome
::Physical
;
29 use CXGN
::Cview
::Marker
::Physical
;
31 use CatalystX
::GlobalContext
'$c';
33 use base qw
| CXGN
::Cview
::Map
::SGN
::Genetic
|;
38 Arguments: a database handle (preferably generated through
39 CXGN::DB::Connection) and a map id. Currently,
40 only one map_id is supported, with the alpha-
41 numeric id of "contig".
54 my $db_version_id = get_db_id
($dbh, $id);
55 my $self = $class -> SUPER
::new
($dbh, $db_version_id);
57 $self->set_preferred_chromosome_width(18);
58 $self->set_short_name($args->{short_name
});
59 $self->set_long_name($args->{long_name
});
60 $self->{gbrowse_fpc
} = $args->{gbrowse_fpc
};
61 $self->{temp_dir
} = $args->{temp_dir
} || '/tmp';
62 $self->set_abstract($args->{abstract
});
63 $self->{marker_link
} = $args->{marker_link
};
70 =head2 function get_chromosome()
84 my $map_factory = CXGN
::Cview
::MapFactory
->new($self->get_dbh());
85 my $id = get_db_id
($self->get_dbh(), $self->get_id());
86 my $genetic_map = $map_factory->create({map_version_id
=>$id});
87 my $genetic=$genetic_map->get_chromosome($chr_nr);
88 my $chromosome = CXGN
::Cview
::Chromosome
::Physical
->new();
90 my $largest_offset = 0;
92 my @gff = $self->{gbrowse_fpc
}->databases()
94 public_message
=> "Map not found.",
95 developer_message
=> 'No gbrowse_fpc databases found',
101 if ( @gff > 1 ) { die "Can't deal with multiple databases right now..." }
105 for my $m ($genetic->get_markers()) {
106 $m->set_chromosome($chromosome);
107 $chromosome->add_marker($m);
108 my $offset = $m->get_offset();
109 if ($offset > $largest_offset) {
110 $largest_offset=$offset;
114 my @gff_markers = $gff->features(-method
=> 'marker',
115 -attributes
=> { Name
=> $m->get_name() },
118 for my $gm (@gff_markers) {
119 @contigs = $gm->refseq();
122 for my $c (@contigs) {
123 my $contig = CXGN
::Cview
::Marker
::Physical
->new();
124 $contig->set_chromosome($chromosome);
125 $contig->set_name($c);
127 #my $url = "/gbrowse/gbrowse/sanger_tomato_fpc/?name=$c";
128 my $url = $self->{gbrowse_fpc
}->view_url({ name
=> $c });
129 $contig->set_marker_name($c);
130 $contig->set_marker_type("contig");
131 $contig->set_url($url);
132 $contig->set_offset($m->get_offset());
133 $contig->get_label()->set_name($c);
134 $contig->get_label()->set_url($url);
135 $contig->set_tooltip("Contig: $c. Anchored to: ".($m->get_name()).".");
136 $chromosome -> add_marker
($contig);
140 $chromosome->set_length($largest_offset);
141 $self->{chr}->[$chr_nr]=$chromosome;
146 =head2 function get_overview_chromosome()
156 sub get_overview_chromosome
{
160 my $bargraph = CXGN
::Cview
::Chromosome
::BarGraph
->new();
162 my $largest_offset = 0;
164 my $chromosome = $self->get_chromosome($chr_nr);
166 for my $m ($chromosome->get_markers()) {
167 if ($m->get_marker_type() eq "contig") {
168 my $offset = $m->get_offset();
169 $bargraph -> add_association
("manual", $offset, 1);
170 if ($offset>$largest_offset) { $largest_offset = $offset; }
176 =head2 function get_chromosome_connections()
186 sub get_chromosome_connections
{
190 # this map has no connections.!!!!
191 # 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" };
199 $db_id=~s/^.*(\d+)$/$1/;
200 return CXGN
::Cview
::Map
::Tools
::find_current_version
($dbh, $db_id);
208 sub get_marker_link
{
211 if ($clone_id) { return ""; }
215 sub get_marker_count
{
221 my @lengths = $self->cache_marker_counts();
222 return $lengths[$chr_nr-1];
225 sub cache_marker_counts
{
229 my $temp_file = File
::Spec
->catfile($self->{temp_dir
}, 'contig'.$self->get_id()."_marker_counts.txt");
231 if (! -e
($temp_file)) {
232 open(my $TEMP, '>', $temp_file) or die "Can't open $temp_file for writing: $!";
235 my $chr = $self->get_chromosome($c);
236 for my $m ($chr->get_markers()) {
237 if ($m->get_marker_name()=~ /^ctg/) {
241 print $TEMP "$c\t$count\n";
247 open(my $TEMP, '<', $temp_file) or die "Can't open $temp_file for reading: $!";
250 my ($c, $length) = split /\t/;
251 push @lengths, $length;
263 $count += $self->get_marker_count($c);
266 return "$count contigs have been assigned to this map";