19
|
1 #!/usr/bin/perl -w
|
|
2 #==========================================================================================
|
|
3 # Date:
|
|
4 # Title:
|
|
5 # Comment: Program to plot gene structure
|
|
6 # Input: 1. input file of Gene region annotation which format like GenePred
|
|
7 # 2. input file of Transcripts region annotation which format like GenePred
|
|
8 # 3. input file of gene snp detail info
|
|
9 # Output: output file of gene structure graph by html or svg formt
|
|
10 # Test Usage:
|
|
11 #========================================================================================
|
|
12 #use strict;
|
|
13 my $version=1.00;
|
|
14 use SVG;
|
|
15 use Getopt::Long;
|
|
16 my %opt;
|
|
17 GetOptions(\%opt,"i=s","o=s",,"h");
|
|
18 if (!(defined $opt{i} and defined $opt{o}) || defined $opt{h}) {
|
|
19 &usage;
|
|
20 }
|
|
21 #===============================Define Attribute==========================================
|
|
22 my %attribute=(
|
|
23 canvas=>{
|
|
24 'width'=>1500,
|
|
25 'height'=>1800
|
|
26 },
|
|
27 text=>{
|
|
28 'stroke'=>"#000000",
|
|
29 'fill'=>"none",
|
|
30 'stroke-width'=>0.5
|
|
31 #'stroke-width2'=>1
|
|
32 },
|
|
33 line=>{
|
|
34 'stroke'=>"black",
|
|
35 'stroke-width'=>1
|
|
36 },
|
|
37 font=>{
|
|
38 'fill'=>"#000000",
|
|
39 'font-size'=>12,
|
|
40 'font-size2'=>10,
|
|
41 'font-weight'=>'bold',
|
|
42 'font-family'=>"Arial"
|
|
43 #'font-family2'=>"ArialNarrow-bold"
|
|
44 },
|
|
45 rect=>{
|
|
46 'fill'=>"lightgreen",
|
|
47 'stroke'=>"black",
|
|
48 'stroke-width'=>0.5
|
|
49 },
|
|
50 readwidth=>0.5
|
|
51 );
|
|
52 #my $Xscale=600/$length;#定义X轴比例尺 1:1000 x轴的坐标长度都要按照此比例尺换算
|
|
53 #========================================data============================
|
|
54 open(IN,"$opt{i}")||die"cannot open the file $opt{i}";
|
|
55 my @R_length;
|
|
56 my @T_length;
|
|
57 my $R_number=0;
|
|
58 my $T_number=0;
|
|
59 my $R_max=0;
|
|
60 my $T_max=0;
|
|
61
|
|
62 my $title=<IN>;
|
|
63 chomp $title;
|
|
64 my @title=split/\t/,$title;
|
|
65 my @mark=split/\s+/,$title[1];
|
|
66 my $sample_number=@mark;
|
|
67 while (my $aline=<IN>) {
|
|
68 if ($aline=~/^\s/) {
|
|
69 my $T_title=<IN>;
|
|
70 chomp $T_title;
|
|
71 while (my $a_aline=<IN>) {
|
|
72 chomp $a_aline;
|
|
73 my @temp=split/\t/,$a_aline;
|
|
74 my @number=split/\s+/,$temp[1];
|
|
75 for (my $i=0;$i<@number ;$i++) {
|
|
76 if ($R_max<$number[$i]) {
|
|
77 $R_max=$number[$i];
|
|
78 }
|
|
79 }
|
|
80 push @R_length,[$temp[0],@number];
|
|
81 $R_number++;
|
|
82 }
|
|
83 }
|
|
84 else {
|
|
85 chomp $aline;
|
|
86 my @temp=split/\t/,$aline;
|
|
87 my @number=split/\s+/,$temp[1];
|
|
88 for (my $i=0;$i<@number ;$i++) {
|
|
89 if ($T_max<$number[$i]) {
|
|
90 $T_max=$number[$i];
|
|
91 }
|
|
92 }
|
|
93 push @T_length,[$temp[0],@number];
|
|
94 $T_number++;
|
|
95 }
|
|
96 }
|
|
97 close IN;
|
|
98 print "Tag max: $T_max\nRead max: $R_max\n";
|
|
99 my $kd_number=5;
|
|
100 ##=======================Reads 纵坐标刻度==========================
|
|
101 my $r=1;
|
|
102 my $rr=1;
|
|
103 my $R=$R_max;
|
|
104 while ($R>10) {
|
|
105 $R=$R/10;
|
|
106 $r=$r*10;
|
|
107 $rr++;
|
|
108 }
|
|
109 $R=int($R+0.5);
|
|
110 my $R_xg=$R/$kd_number*$r;#纵坐标一小格大小(一共10格)
|
|
111 my $R_kedu_scale_x=6*$rr;#纵坐标刻度文字
|
|
112 ##=======================Tags 纵坐标刻度==========================
|
|
113 my $t=1;
|
|
114 my $tt=1;
|
|
115 my $T=$T_max;
|
|
116 while ($T>10) {
|
|
117 $T=$T/10;
|
|
118 $t=$t*10;
|
|
119 $tt++;
|
|
120 }
|
|
121 $T=int($T+0.5);
|
|
122 my $T_xg=$T/$kd_number*$t;#纵坐标一小格大小(一共10格)
|
|
123 my $T_kedu_scale_x=6*$tt;#纵坐标刻度文字
|
|
124
|
|
125 #############################s#define start coordinate and scale
|
|
126 my $XOFFSET=50;
|
|
127 my $YOFFSET=60;
|
|
128 my $width=800;
|
|
129 my $heigth=800;
|
|
130 my $X_width=600;
|
|
131 #my $height=1600;
|
|
132 #### Starting ####
|
|
133 #新建画布
|
|
134 my $svg=SVG->new(width=>$width,height=>$heigth);
|
|
135 ####坐标轴
|
|
136 my $axisL=300;#read 纵坐标长度
|
|
137 my $x_margin = 50;
|
|
138 #=========Reads number setting==========================================
|
|
139 my $Y_R_title=30;#标题的纵向宽度
|
|
140 my $Y_R_0=$YOFFSET+$axisL+$Y_R_title;
|
|
141 my $X_R_0=$XOFFSET+$x_margin;
|
|
142 my $R_Yscale=$axisL/$R_xg/$kd_number;
|
|
143 my $R_Xscale=$X_width/$R_number/($sample_number+1);
|
|
144 #=====================================Reads Y axis======================
|
|
145 $svg->line('x1',$X_R_0,'y1',$Y_R_0,'x2',$X_R_0,'y2',$Y_R_0-$axisL,'stroke',$attribute{line}{'stroke'},'stroke-width',$attribute{line}{'stroke-width'});
|
|
146 for (my $i=1;$i<$kd_number ;$i++) {
|
|
147 $svg->line('x1',$X_R_0-5,'y1',$Y_R_0-$i*$R_xg*$R_Yscale,'x2',$X_R_0,'y2',$Y_R_0-$i*$R_xg*$R_Yscale,'stroke',$attribute{line}{'stroke'},'stroke-width',$attribute{line}{'stroke-width'});
|
|
148 $svg->text('x',$X_R_0-$R_kedu_scale_x,'y',$Y_R_0-$i*$R_xg*$R_Yscale+4,'style','fill:black;text-anchor:middle','stroke',$attribute{text}{'stroke'},'stroke-width',$attribute{text}{'stroke-width'},'font-size',6,'font-family',$attribute{font}{'font-family'},'-cdata',$i*$R_xg);
|
|
149 }
|
|
150 #=====================================Reads X axis======================
|
|
151 $svg->line('x1',$X_R_0,'y1',$Y_R_0,'x2',$X_R_0+$X_width,'y2',$Y_R_0,'stroke',$attribute{line}{'stroke'},'stroke-width',$attribute{line}{'stroke-width'});
|
|
152
|
|
153 #print "$R_number\t$sample_number\n";
|
|
154 for ($i=0;$i<$R_number ;$i++) {
|
|
155 for (my $j=1;$j<$sample_number+1 ;$j++) {
|
|
156 my $red=$j/$sample_number*255;
|
|
157 $svg->rect('x',$X_R_0+($j+$i*($sample_number+1))*$R_Xscale,'y',$Y_R_0-$R_length[$i][$j]*$R_Yscale,'width',$R_Xscale,'height',$R_length[$i][$j]*$R_Yscale,'stroke',"black",'stroke-width',"0.5",'fill',"rgb($red,125,0)");
|
|
158 }
|
|
159 $svg->text('x',$X_R_0+(1+$sample_number/2+$i*($sample_number+1))*$R_Xscale,'y',$Y_R_0+15,'style','fill:black;text-anchor:middle','stroke',$attribute{text}{'stroke'},'stroke-width',$attribute{text}{'stroke-width'},'font-size',6,'font-family',$attribute{font}{'font-family'},'-cdata',$R_length[$i][0]);
|
|
160 }
|
|
161 #===Reads number title
|
|
162 $svg->text('x',$XOFFSET+400,'y',$YOFFSET,'style','fill:black;text-anchor:middle','stroke',$attribute{text}{'stroke'},'stroke-width',"1",'font-size',15,'font-family',$attribute{font}{'font-family'},'-cdata',"Reads Length Distribution");
|
|
163 #===Reads
|
|
164 for (my $i=0;$i<$sample_number ;$i++) {
|
|
165 my $red=($i+1)/$sample_number*255;
|
|
166 $svg->rect('x',$X_R_0+550,'y',$YOFFSET+$Y_R_title+20*$i,'width',15,'height',10,'stroke',"black",'stroke-width',"0.5",'fill',"rgb($red,125,0)");
|
|
167 $svg->text('x',$X_R_0+550+30,'y',$YOFFSET+$Y_R_title+20*$i+10,'style','fill:black;text-anchor:middle','stroke',$attribute{text}{'stroke'},'stroke-width',$attribute{text}{'stroke-width'},'font-size',10,'font-family',$attribute{font}{'font-family'},'-cdata',$mark[$i]);
|
|
168 }
|
|
169 ####==================================================================================
|
|
170 #=========================================Tag s
|
|
171 my $Y_T_title=30;#标题的纵向宽度
|
|
172 my $Y_T_0=$Y_R_0+$axisL+$Y_R_title+50;#length size
|
|
173 my $X_T_0=$XOFFSET+$x_margin;
|
|
174 my $T_Yscale=$axisL/$T_xg/$kd_number;
|
|
175 my $T_Xscale=$X_width/$T_number/($sample_number+1);
|
|
176 #=====================================Tags Y axis======================
|
|
177 $svg->line('x1',$X_T_0,'y1',$Y_T_0,'x2',$X_T_0,'y2',$Y_T_0-$axisL,'stroke',$attribute{line}{'stroke'},'stroke-width',$attribute{line}{'stroke-width'});
|
|
178 for (my $i=1;$i<$kd_number ;$i++) {
|
|
179 $svg->line('x1',$X_T_0-5,'y1',$Y_T_0-$i*$T_xg*$T_Yscale,'x2',$X_T_0,'y2',$Y_T_0-$i*$T_xg*$T_Yscale,'stroke',$attribute{line}{'stroke'},'stroke-width',$attribute{line}{'stroke-width'});
|
|
180 $svg->text('x',$X_T_0-$T_kedu_scale_x,'y',$Y_T_0-$i*$T_xg*$T_Yscale+4,'style','fill:black;text-anchor:middle','stroke',$attribute{text}{'stroke'},'stroke-width',$attribute{text}{'stroke-width'},'font-size',6,'font-family',$attribute{font}{'font-family'},'-cdata',$i*$T_xg);
|
|
181 }
|
|
182 #=====================================Tags X axis======================
|
|
183 $svg->line('x1',$X_T_0,'y1',$Y_T_0,'x2',$X_T_0+$X_width,'y2',$Y_T_0,'stroke',$attribute{line}{'stroke'},'stroke-width',$attribute{line}{'stroke-width'});
|
|
184
|
|
185 #print "$R_number\t$sample_number\n";
|
|
186 for ($i=0;$i<$T_number ;$i++) {
|
|
187 for (my $j=1;$j<$sample_number+1 ;$j++) {
|
|
188 my $red=$j/$sample_number*255;
|
|
189 $svg->rect('x',$X_T_0+($j+$i*($sample_number+1))*$T_Xscale,'y',$Y_T_0-$T_length[$i][$j]*$T_Yscale,'width',$T_Xscale,'height',$T_length[$i][$j]*$T_Yscale,'stroke',"black",'stroke-width',"0.5",'fill',"rgb($red,125,0)");
|
|
190 }
|
|
191 $svg->text('x',$X_T_0+(1+$sample_number/2+$i*($sample_number+1))*$T_Xscale,'y',$Y_T_0+15,'style','fill:black;text-anchor:middle','stroke',$attribute{text}{'stroke'},'stroke-width',$attribute{text}{'stroke-width'},'font-size',6,'font-family',$attribute{font}{'font-family'},'-cdata',$T_length[$i][0]);
|
|
192 }
|
|
193 #===Reads number title
|
|
194 $svg->text('x',$XOFFSET+400,'y',$Y_R_0+30+$Y_T_title,'style','fill:black;text-anchor:middle','stroke',$attribute{text}{'stroke'},'stroke-width',"1",'font-size',15,'font-family',$attribute{font}{'font-family'},'-cdata',"Tags Length Distribution");
|
|
195 #===Reads
|
|
196 for (my $i=0;$i<$sample_number ;$i++) {
|
|
197 my $red=($i+1)/$sample_number*255;
|
|
198 $svg->rect('x',$X_T_0+550,'y',$Y_R_0+30+$Y_T_title+20*$i,'width',15,'height',10,'stroke',"black",'stroke-width',"0.5",'fill',"rgb($red,125,0)");
|
|
199 $svg->text('x',$X_T_0+550+30,'y',$Y_R_0+30+$Y_T_title+20*$i+10,'style','fill:black;text-anchor:middle','stroke',$attribute{text}{'stroke'},'stroke-width',$attribute{text}{'stroke-width'},'font-size',10,'font-family',$attribute{font}{'font-family'},'-cdata',$mark[$i]);
|
|
200 }
|
|
201
|
|
202
|
|
203
|
|
204
|
|
205 open (OUT,">$opt{o}");
|
|
206 print OUT $svg->xmlify();
|
|
207
|
|
208 sub usage{
|
|
209 print <<"USAGE";
|
|
210 Version $version
|
|
211 Usage:
|
|
212 $0
|
|
213 options:
|
|
214 -i
|
|
215 -o svg output
|
|
216 -h help
|
|
217 USAGE
|
|
218 exit(1);
|
|
219 } |