changes to the parameters of map overview constructors
[cview.git] / lib / CXGN / Cview / Map / SGN / Contig.pm
blobf0155ac59db61505c0a857b3e27d9a2dc94ffec2
1 =head1 NAME
3 CXGN::Cview::Map::SGN::Contig - a class to generate maps of contigs aligned to the genome
5 =head1 SYNOPSYS
7 my $map = CXGN::Cview::Map::SGN::Contig->new($dbh, $id);
8 my $chr = $map->get_chromosome(1);
9 # etc...
11 =head1 AUTHOR(S)
13 Lukas Mueller <lam87@cornell.edu>
15 =head1 FUNCTIONS
17 This class implements the following functions:
19 =cut
21 package CXGN::Cview::Map::SGN::Contig;
22 use strict;
23 use warnings;
25 use File::Spec;
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 |;
33 =head2 function new
35 Synopsis:
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".
40 Returns:
41 Side effects:
42 Description:
44 =cut
46 sub new {
47 my $class = shift;
48 my $dbh = shift;
49 my $id = shift;
50 my $args = shift;
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};
62 $self->set_id($id);
64 return $self;
68 =head2 function get_chromosome()
70 Synopsis:
71 Arguments:
72 Returns:
73 Side effects:
74 Description:
76 =cut
78 sub get_chromosome {
79 my $self = shift;
80 my $chr_nr = shift;
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!"; }
93 my ($gff) = @gff;
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;
102 $m->hide();
104 my @gff_markers = $gff->features(-method => 'marker',
105 -attributes => { Name => $m->get_name() },
107 my @contigs = ();
108 for my $gm (@gff_markers) {
109 @contigs = $gm->refseq();
111 my $count = 0;
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);
127 $count++;
130 $chromosome->set_length($largest_offset);
131 $self->{chr}->[$chr_nr]=$chromosome;
132 return $chromosome;
136 =head2 function get_overview_chromosome()
138 Synopsis:
139 Arguments:
140 Returns:
141 Side effects:
142 Description:
144 =cut
146 sub get_overview_chromosome {
147 my $self = shift;
148 my $chr_nr = shift;
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; }
163 return $bargraph;
166 =head2 function get_chromosome_connections()
168 Synopsis:
169 Arguments:
170 Returns:
171 Side effects:
172 Description:
174 =cut
176 sub get_chromosome_connections {
177 my $self = shift;
178 my $chr_nr = shift;
179 my @list = ();
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" };
182 return @list;
185 sub get_db_id {
186 my $dbh = shift;
187 my $id = shift;
188 my $db_id = $id;
189 $db_id=~s/^.*(\d+)$/$1/;
190 return CXGN::Cview::Map::Tools::find_current_version($dbh, $db_id);
194 sub can_zoom {
195 return 0;
198 sub get_marker_link {
199 my $self = shift;
200 my $clone_id= shift;
201 if ($clone_id) { return ""; }
202 else { return ""; }
205 sub get_marker_count {
206 my $self = shift;
207 my $chr_nr = shift;
209 my $tmp_file = "";
211 my @lengths = $self->cache_marker_counts();
212 return $lengths[$chr_nr-1];
215 sub cache_marker_counts {
216 my $self = shift;
218 my @lengths = ();
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: $!";
223 for my $c (1..12) {
224 my $count = 0;
225 my $chr = $self->get_chromosome($c);
226 for my $m ($chr->get_markers()) {
227 if ($m->get_marker_name()=~ /^ctg/) {
228 $count++;
231 print $TEMP "$c\t$count\n";
236 else {
237 open(my $TEMP, '<', $temp_file) or die "Can't open $temp_file for reading: $!";
238 while (<$TEMP>) {
239 chomp;
240 my ($c, $length) = split /\t/;
241 push @lengths, $length;
245 return @lengths;
248 sub get_map_stats {
249 my $self = shift;
251 my $count = 0;
252 for my $c (1..12) {
253 $count += $self->get_marker_count($c);
256 return "$count contigs have been assigned to this map";
259 =head2 get_abstract
261 Usage:
262 Desc:
263 Ret:
264 Args:
265 Side Effects:
266 Example:
268 =cut