modified: makefile
[GalaxyCodeBases.git] / tools / genotyping / pl / plot.pl
blobc1fedf436c8e9a4afa2803a7ff611b54c88c8091
1 #!/usr/bin/perl -w
2 use strict;
3 use SVG;
4 unless(@ARGV)
6 die "perl $0 <chrlen file><input file><out file><chr><width><proportion>\n";
8 my $chrlen;
9 open IN,"$ARGV[0]" or die "The chrlen file can't open:$!\n";
10 while(<IN>)
12 chomp;
13 my @temp=split;
14 if($temp[0]=~/$ARGV[3]/i)
16 $chrlen=$temp[1];
19 close IN;
20 open CIN,"$ARGV[1]" or die "The input file can't open:$!\n";
22 my $temp='#';
23 while ($temp =~ /^#/) {
24 $temp=<CIN>;
26 chomp $temp;
27 #chomp(my $temp=<CIN>);
29 my @name=split /\s+/,$temp;
30 #shift @name;
31 my $samnum=@name;
32 #print "@name\n$samnum\n";
33 #ast;
34 my $side=100;
35 my $width=$chrlen/$ARGV[5]+$side*3;
36 my $height=$samnum*$ARGV[4]+200;
37 my $svg=SVG->new('width',$width,'height',$height);
38 $svg->rect('x',0,'y',0,'width',$width,'height',$height,'stroke','white','fill','white');
40 my %ReFormatGT=(0=>1, 1=>2, 0.5=>3,'NA'=>0, 'N'=>-1);
41 my %FormatGT=(1=>0, 2=>1, 3=>0.5, 0=>'NA', -1=>'N');
42 #my @color=("#2A2F7F","#68BE4A","#8C63A4","#B6292B","#FCDAD5");
43 my %Color=(
44 1 => '#CC0000',
45 3 => '#1100CC',
46 2 => '#008800',
47 0 => '#CCCCCC',
48 -1 => '#000022',
50 #my @label=("9311","pair64","no_decide","het","no_cov");
51 my @Label=( [1,'9311'],[2,'PA64'],[3,'Hete'],[0,'N/A'],[-1,'N Zone'] );
52 pop @Label;
53 my $i=0;
54 foreach(@Label) {
55 my ($id,$label)=@$_;
56 $svg->line('x1',$side,'y1',$side/2+$ARGV[4]*$i*2,'x2',$side+20,'y2',$side/2+$ARGV[4]*$i*2,'stroke',$Color{$id},'stroke-width',$ARGV[4]);
57 $svg->text('x',$side+25,'y',$side/2+$ARGV[4]*$i*2+3,'font-family','Arial','stroke-width',0.3,'font-size',12,'-cdata',$label);
58 ++$i;
60 #plot left
61 $svg->line('x1',$side,'y1',$side,'x2',$side,'y2',$height-100,'stroke','black','stroke-width',1);
62 foreach(1..int(($height-200)/($ARGV[4]*20)))
64 $svg->line('x1',$side,'y1',$height-100-20*$_*$ARGV[4],'x2',$side-5,'y2',$height-100-20*$_*$ARGV[4],'stroke','black','stroke-width',0.7);
65 $svg->text('x',$side-30,'y',$height-100-20*$_*$ARGV[4]+5,'font-family','Arial','stroke-width',0.3,'font-size',14,'-cdata',20*$_);
67 my $sit=($height-200)/2+100+30;
68 $svg->text('x',50,'y',$sit,'font-family','Arial','stroke-width',0.5,'font-size',16,'-cdata','Individuals','transform',"rotate(270,50,$sit)");
69 #plot down
70 $svg->line('x1',$side,'y1',$height-100,'x2',$width-$side*2,'y2',$height-100,'stroke','black','stroke-width',1);
71 my $par=int($chrlen/5000000);
72 my $len=int($chrlen/($ARGV[5]*$par));
73 foreach(0..$par)
75 $svg->line('x1',$side+$_*$len,'y1',$height-100,'x2',$side+$_*$len,'y2',$height-100+5,'stroke','black','stroke-width',0.7);
76 $svg->text('x',$side+$_*$len-5,'y',$height-100+20,'font-family','Arial','stroke-width',0.3,'font-size',14,'-cdata',5*$_);
78 $svg->text('x',($width-$side*3)/2+$side,'y',$height-100+50,'font-family','Arial','stroke-width',0.5,'font-size',16,'-cdata','Position(Mb)');
79 #plot right
80 $svg->line('x1',$width-200,'y1',$side,'x2',$width-200,'y2',$height-100,'stroke','black','stroke-width',1);
81 my $m=0;
82 foreach my $sam(1..$samnum)
84 $svg->line('x1',$width-2*$side,'y1',$height-$side-$ARGV[4]*$sam+$ARGV[4]/2,'x2',$width-2*$side+$ARGV[4]*4,'y2',$height-$side-$ARGV[4]*$sam-$ARGV[4]*2,'stroke','black','stroke-width',0.7);
85 if($sam%2==1)
87 $svg->line('x1',$width-2*$side+$ARGV[4]*4,'y1',$height-$side-$ARGV[4]*$sam-$ARGV[4]*2,'x2',$width-2*$side+$ARGV[4]*14,'y2',$height-$side-$ARGV[4]*$sam-$ARGV[4]*2,'stroke','black','stroke-width',0.7);
88 $svg->text('x',$width-2*$side+$ARGV[4]*15,'y',$height-$side-$ARGV[4]*$sam-$ARGV[4]*2+$ARGV[4]/2+2,'font-family','Arial','stroke-width',0.5,'font-size',10,'-cdata',$name[$sam-1]);
90 else
92 $svg->line('x1',$width-2*$side+$ARGV[4]*4,'y1',$height-$side-$ARGV[4]*$sam-$ARGV[4]*2,'x2',$width-2*$side+$ARGV[4]*6,'y2',$height-$side-$ARGV[4]*$sam-$ARGV[4]*2,'stroke','black','stroke-width',0.7);
93 $svg->text('x',$width-2*$side+$ARGV[4]*6,'y',$height-$side-$ARGV[4]*$sam-$ARGV[4]*2+$ARGV[4]/2+2,'font-family','Arial','stroke-width',0.5,'font-size',10,'-cdata',$name[$sam-1]);
96 #plot up
97 $svg->line('x1',$side,'y1',$side,'x2',$width-200,'y2',$side,'stroke','black','stroke-width',1);
98 #plot data
99 #chomp(my $line=<CIN>);
100 #my @last=split /\s+/,$line;
101 #my @color=("#2A2F7F","#00A06B");
102 my $mark=0;
103 my @new;
104 my @last;
105 my @start;
106 while(<CIN>)
108 next if /^#/;
109 chomp;
110 my @now=split;
111 if($mark==0)
113 @last=@now;
114 foreach my $sam(1..$samnum)
116 $start[$sam]=1;
118 $start[0]="seat";
120 foreach my $sam(1..$samnum)
122 if($last[$sam] ne $now[$sam])
124 my $n=$last[$sam];
125 my $x1=$side+$start[$sam]/$ARGV[5];
126 my $y1=$height-$side-$ARGV[4]*$sam+$ARGV[4]/2;
127 my $x2=$now[0]/$ARGV[5]+$side;
128 my $y2=$y1;
129 my $colr=$Color{$ReFormatGT{$n}};
130 # print "$x1\t$y1\n";
131 =pod
132 if($n eq 0.5)
134 $colr=$color[3];
136 elsif($n eq "NA")
138 $colr=$color[4];
140 else
142 $colr=$color[$n];
144 =cut
145 $svg->line('x1',$x1,'y1',$y1,'x2',$x2,'y2',$y2,'stroke',$colr,'stroke-width',$ARGV[4]);# unless $n =~ /^N/;
146 $last[$sam]=$now[$sam];
147 $start[$sam]=$now[0];
150 # print "@last\n";
151 # last;
152 $mark=1;
153 @new=@now;
155 foreach my $sam(1..$samnum)
157 if($last[$sam] eq $new[$sam])
159 my $n=$last[$sam];
160 my $x1=$side+$start[$sam]/$ARGV[5];
161 my $y1=$height-$side-$ARGV[4]*$sam+$ARGV[4]/2;
162 my $x2=$new[0]/$ARGV[5]+$side;
163 my $y2=$y1;
164 # print "$x1\t$y1\n";
165 my $colr=$Color{$ReFormatGT{$n}};
166 $svg->line('x1',$x1,'y1',$y1,'x2',$x2,'y2',$y2,'stroke',$colr,'stroke-width',$ARGV[4]);# unless $n =~ /^N/;
170 open(OUT,">$ARGV[2]")or die;
171 print OUT $svg->xmlify();
172 close OUT;
174 __END__
175 /nas/RD_09C/resequencing/user/zhangxm/soft/zijiao/new_selfing.pl
176 perl /nas/RD_09C/resequencing/user/zhangxm/soft/zijiao/new_selfing.pl /nas/RD_09C/resequencing/Genome/Rice/Genome_9311/chr.nfo /panfs/POPULATION/PROJECT/Rice_RIL/chongqiong_RIL/data/Chr01.out.new /panfs/POPULATION/PROJECT/Rice_RIL/chongqiong_RIL/pic/Chr01.out.new.svg Chr01 5 40000
177 cat ../9311/chrorder |while read a; do ./plot.pl ../9311/chr.nfo ril.$a.rgt ril.$a.r.svg $a 6 40000; done
178 find . -name '*.?1.svg'|perl -lane '$a=$_;s/\.svg$/\.png/;system "convert $a $_"'