-
Notifications
You must be signed in to change notification settings - Fork 2
/
Genes_to_image.pm
executable file
·132 lines (112 loc) · 3.55 KB
/
Genes_to_image.pm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
package main;
our ($IMAGE_X_SIZE, $DEBUG);
package Genes_to_image;
use strict;
use Sequence_coords_image;
use CDNA::CDNA_alignment;
use Gene_obj;
my $consensus = 10;
my $consensus_color = "blue";
sub create_image {
my (@genes) = @_;
my @data;
foreach my $obj (@genes) {
my $struct = &get_struct_from_gene_obj($obj);
push (@data, $struct);
}
my %info;
my @c;
my $highlight = 0;
foreach my $gene_struct (@data) {
my $coords_aref = $gene_struct->{coords};
foreach my $href (@$coords_aref) {
my $c1 = $href->{end5};
my $c2 = $href->{end3};
if ($gene_struct->{type} eq "gene" && (!$highlight)) {
$info{$c1} = 1;
$info{$c2} = 1;
}
push (@c, $c1, $c2);
}
$highlight = 1; #only track coords for first gene.
}
@c = sort {$a<=>$b} @c;
my $min_end5 = shift @c;
$min_end5 -= 1;
if ($DEBUG) {
print "---\nMIN_COORD: $min_end5\n----\n";
print "CREATING IMAGE\n";
}
my $obj = new Sequence_coords_image(
IMAGE_X_SIZE => $IMAGE_X_SIZE || 750, #default image length in pixels
DRAW_PANEL_SCALER => 0.6, #percentage of image to draw matches, rest for text-annotation of match
ELEMENT_VERTICAL_SPACING => 15, #amount of vertical space consumed by each element
TICKER_TOGGLE => 1 #toggle for displaying a ticker for protein length, default is on.
#SEQ_START => $min_end5
);
foreach my $alignment (@data) {
my $accession = $alignment->{name};
my @coordsets = @{$alignment->{coords}};
my @list; #initialize
foreach my $coordset (@coordsets) {
my $end5 = $coordset->{end5};
my $end3 = $coordset->{end3};
my $end5_agree = $info{$end5};
my $end3_agree = $info{$end3};
$end5 -= $min_end5;
$end3 -= $min_end5;
if ($DEBUG) {
print "END5: $end5\tEND3: $end3\t$accession\n";
}
my $color = ($accession =~ /\sFL/) ? "119:119:119" : "black";
push (@list, $end5, "full", $end3, "full", $color);
if ((my $cds_end5 = $coordset->{cds_end5}) && (my $cds_end3 = $coordset->{cds_end3})) {
$cds_end5 -= $min_end5;
$cds_end3 -= $min_end5;
push (@list, $cds_end5, "full", $cds_end3, "full", "red");
}
if ($end5_agree) {
push (@list, $end5, "full", ($end5 + $consensus) , "full", $consensus_color);
}
if ($end3_agree) {
push (@list, ($end3 - $consensus), "full", $end3, "full", $consensus_color);
}
# element params (end5, end5_type, end3, end3_type, color, [... repeat for each match ....])
# end_types: (arrow, full, partial)
# colors ( (white, blue, red, black, or green) or ("R:G:B") )
}
my $element = new Sequence_coords_image::Element(@list);
$element->set_text($accession);
$obj->add_element($element);
}
#print image
my $img = $obj->create_image();
return ($img);
}
####
sub get_struct_from_gene_obj {
my $gene_obj = shift;
my @coords;
my $strand = $gene_obj->{strand};
my @exons = $gene_obj->get_exons();
my %cds;
my $i = 0;
foreach my $exon (@exons) {
my ($end5, $end3) = sort {$a<=>$b} $exon->get_coords();
$coords[$i]->{end5} = $end5;
$coords[$i]->{end3} = $end3;
if (my $cds_ref = $exon->get_CDS_obj()) {
my ($end5, $end3) = sort {$a<=>$b} $cds_ref->get_coords();
$coords[$i]->{cds_end5} = $end5;
$coords[$i]->{cds_end3} = $end3;
}
$i++;
}
my $com_name = $gene_obj->{com_name} || "";
my $struct = { type => 'gene',
strand => $strand,
coords => \@coords,
name => "($strand)" . $gene_obj->{Model_feat_name} . " $com_name"};
return ($struct);
}
1; #EOM