annotate conventional.pl @ 32:399d8dbdedd6 draft

Uploaded
author big-tiandm
date Sat, 15 Nov 2014 01:33:20 -0500
parents 07745c0958dd
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
07745c0958dd Uploaded
big-tiandm
parents:
diff changeset
1 #!/usr/bin/perl -w
07745c0958dd Uploaded
big-tiandm
parents:
diff changeset
2 #Filename:
07745c0958dd Uploaded
big-tiandm
parents:
diff changeset
3 #Author: Chentt
07745c0958dd Uploaded
big-tiandm
parents:
diff changeset
4 #Email: chentt@big.ac.cn
07745c0958dd Uploaded
big-tiandm
parents:
diff changeset
5 #Date: 2014/04/09
07745c0958dd Uploaded
big-tiandm
parents:
diff changeset
6 #Modified:
07745c0958dd Uploaded
big-tiandm
parents:
diff changeset
7 #Description: islands merged of merged samples
07745c0958dd Uploaded
big-tiandm
parents:
diff changeset
8 my $version=1.00;
07745c0958dd Uploaded
big-tiandm
parents:
diff changeset
9
07745c0958dd Uploaded
big-tiandm
parents:
diff changeset
10 use strict;
07745c0958dd Uploaded
big-tiandm
parents:
diff changeset
11 use Getopt::Long;
07745c0958dd Uploaded
big-tiandm
parents:
diff changeset
12
07745c0958dd Uploaded
big-tiandm
parents:
diff changeset
13 my %opts;
07745c0958dd Uploaded
big-tiandm
parents:
diff changeset
14 GetOptions(\%opts,"i=s","d=i","o=s","N=i","t=s","mark=s","h");
07745c0958dd Uploaded
big-tiandm
parents:
diff changeset
15 if (!(defined $opts{i} and defined $opts{d} and defined $opts{N} and defined $opts{mark} and defined $opts{t} and defined $opts{o} ) || defined $opts{h}) { #necessary arguments
07745c0958dd Uploaded
big-tiandm
parents:
diff changeset
16 &usage;
07745c0958dd Uploaded
big-tiandm
parents:
diff changeset
17 }
07745c0958dd Uploaded
big-tiandm
parents:
diff changeset
18
07745c0958dd Uploaded
big-tiandm
parents:
diff changeset
19 my $filein=$opts{'i'};
07745c0958dd Uploaded
big-tiandm
parents:
diff changeset
20 my $fileout=$opts{'o'};
07745c0958dd Uploaded
big-tiandm
parents:
diff changeset
21 my $distance=$opts{'d'};
07745c0958dd Uploaded
big-tiandm
parents:
diff changeset
22 my $tempout=$opts{'t'};
07745c0958dd Uploaded
big-tiandm
parents:
diff changeset
23 my $mark=$opts{'mark'};
07745c0958dd Uploaded
big-tiandm
parents:
diff changeset
24 my @sample=split/\#/,$mark;
07745c0958dd Uploaded
big-tiandm
parents:
diff changeset
25 $mark=join"\"\t\"",@sample;
07745c0958dd Uploaded
big-tiandm
parents:
diff changeset
26
07745c0958dd Uploaded
big-tiandm
parents:
diff changeset
27 open IN,"<$filein"; #input file
07745c0958dd Uploaded
big-tiandm
parents:
diff changeset
28 open OUT,">$fileout"; #output file
07745c0958dd Uploaded
big-tiandm
parents:
diff changeset
29 print OUT "\"Chr\"\t\"MajorLength\"\t\"Percent\"\t\"$mark\"\n";
07745c0958dd Uploaded
big-tiandm
parents:
diff changeset
30 open TMP,">$tempout";
07745c0958dd Uploaded
big-tiandm
parents:
diff changeset
31 print TMP "\#Chr\tMajorLength\tPercent\tTagsNumber\tTagsInfor\n";
07745c0958dd Uploaded
big-tiandm
parents:
diff changeset
32 my %hash;
07745c0958dd Uploaded
big-tiandm
parents:
diff changeset
33 while (my $aline=<IN>) {
07745c0958dd Uploaded
big-tiandm
parents:
diff changeset
34 chomp $aline;
07745c0958dd Uploaded
big-tiandm
parents:
diff changeset
35 if($aline=~/^\#/){
07745c0958dd Uploaded
big-tiandm
parents:
diff changeset
36 #print OUT "$aline\n";
07745c0958dd Uploaded
big-tiandm
parents:
diff changeset
37 next;
07745c0958dd Uploaded
big-tiandm
parents:
diff changeset
38 }
07745c0958dd Uploaded
big-tiandm
parents:
diff changeset
39 my @tmp=split/\t/,$aline;
07745c0958dd Uploaded
big-tiandm
parents:
diff changeset
40 my $chr=shift @tmp;
07745c0958dd Uploaded
big-tiandm
parents:
diff changeset
41 #shift @tmp;
07745c0958dd Uploaded
big-tiandm
parents:
diff changeset
42 push @{$hash{$chr}},[@tmp];
07745c0958dd Uploaded
big-tiandm
parents:
diff changeset
43 }
07745c0958dd Uploaded
big-tiandm
parents:
diff changeset
44
07745c0958dd Uploaded
big-tiandm
parents:
diff changeset
45 close IN;
07745c0958dd Uploaded
big-tiandm
parents:
diff changeset
46
07745c0958dd Uploaded
big-tiandm
parents:
diff changeset
47 foreach my $key (keys %hash) {
07745c0958dd Uploaded
big-tiandm
parents:
diff changeset
48 my @tag=sort{$a->[1] <=> $b->[1]} @{$hash{$key}};
07745c0958dd Uploaded
big-tiandm
parents:
diff changeset
49 my @sample;
07745c0958dd Uploaded
big-tiandm
parents:
diff changeset
50 my $start=$tag[0][1];
07745c0958dd Uploaded
big-tiandm
parents:
diff changeset
51 my $end=$tag[0][2];
07745c0958dd Uploaded
big-tiandm
parents:
diff changeset
52 push @sample,[@{$tag[0]}];
07745c0958dd Uploaded
big-tiandm
parents:
diff changeset
53 for (my $i=1;$i<@tag-1;$i++) {
07745c0958dd Uploaded
big-tiandm
parents:
diff changeset
54 if ($tag[$i][1]-$end<=$distance) {
07745c0958dd Uploaded
big-tiandm
parents:
diff changeset
55 if ($tag[$i][2]>$end) {
07745c0958dd Uploaded
big-tiandm
parents:
diff changeset
56 $end=$tag[$i][2];
07745c0958dd Uploaded
big-tiandm
parents:
diff changeset
57 }
07745c0958dd Uploaded
big-tiandm
parents:
diff changeset
58 push @sample,[@{$tag[$i]}];
07745c0958dd Uploaded
big-tiandm
parents:
diff changeset
59 }
07745c0958dd Uploaded
big-tiandm
parents:
diff changeset
60 else{
07745c0958dd Uploaded
big-tiandm
parents:
diff changeset
61 my ($max_length,$max_p,$tag,@cluster_exp)=Max_length(\@sample);
07745c0958dd Uploaded
big-tiandm
parents:
diff changeset
62 my $cluster_exp=join"\t",@cluster_exp;
07745c0958dd Uploaded
big-tiandm
parents:
diff changeset
63 if ($max_length>30) {
07745c0958dd Uploaded
big-tiandm
parents:
diff changeset
64 print TMP "$key\:$start\-$end\t$max_length"."nt\t$max_p\t$tag\n";
07745c0958dd Uploaded
big-tiandm
parents:
diff changeset
65 $max_length="\>30";
07745c0958dd Uploaded
big-tiandm
parents:
diff changeset
66 }
07745c0958dd Uploaded
big-tiandm
parents:
diff changeset
67 else{print TMP "$key\:$start\-$end\t$max_length"."nt\t$max_p\t$tag\n";}
07745c0958dd Uploaded
big-tiandm
parents:
diff changeset
68 print OUT "$key\:$start\-$end\t$max_length"."nt\t$max_p\t$cluster_exp\n";
07745c0958dd Uploaded
big-tiandm
parents:
diff changeset
69 $start=$tag[$i][1];
07745c0958dd Uploaded
big-tiandm
parents:
diff changeset
70 $end=$tag[$i][2];
07745c0958dd Uploaded
big-tiandm
parents:
diff changeset
71
07745c0958dd Uploaded
big-tiandm
parents:
diff changeset
72 @sample=();
07745c0958dd Uploaded
big-tiandm
parents:
diff changeset
73 push @sample,[@{$tag[$i]}];
07745c0958dd Uploaded
big-tiandm
parents:
diff changeset
74 }
07745c0958dd Uploaded
big-tiandm
parents:
diff changeset
75 }
07745c0958dd Uploaded
big-tiandm
parents:
diff changeset
76 if ($tag[$#tag][1]-$end<=$distance) {
07745c0958dd Uploaded
big-tiandm
parents:
diff changeset
77 if ($tag[$#tag][2]>$end) {
07745c0958dd Uploaded
big-tiandm
parents:
diff changeset
78 $end=$tag[$#tag][2];
07745c0958dd Uploaded
big-tiandm
parents:
diff changeset
79 }
07745c0958dd Uploaded
big-tiandm
parents:
diff changeset
80 push @sample,[@{$tag[$#tag]}];
07745c0958dd Uploaded
big-tiandm
parents:
diff changeset
81 my ($max_length,$max_p,$tag,@cluster_exp)=Max_length(\@sample);
07745c0958dd Uploaded
big-tiandm
parents:
diff changeset
82 my $cluster_exp=join"\t",@cluster_exp;
07745c0958dd Uploaded
big-tiandm
parents:
diff changeset
83 if ($max_length>30) {
07745c0958dd Uploaded
big-tiandm
parents:
diff changeset
84 $max_length="\>30";
07745c0958dd Uploaded
big-tiandm
parents:
diff changeset
85 print TMP "$key\:$start\-$end\t$max_length"."nt\t$max_p\t$tag\n";
07745c0958dd Uploaded
big-tiandm
parents:
diff changeset
86 }
07745c0958dd Uploaded
big-tiandm
parents:
diff changeset
87 else{print TMP "$key\:$start\-$end\t$max_length"."nt\t$max_p\t$tag\n";}
07745c0958dd Uploaded
big-tiandm
parents:
diff changeset
88 print OUT "$key\:$start\-$end\t$max_length"."nt\t$max_p\t$cluster_exp\n";
07745c0958dd Uploaded
big-tiandm
parents:
diff changeset
89 }
07745c0958dd Uploaded
big-tiandm
parents:
diff changeset
90 else{
07745c0958dd Uploaded
big-tiandm
parents:
diff changeset
91 my ($max_length,$max_p,$tag,@cluster_exp)=Max_length(\@sample);
07745c0958dd Uploaded
big-tiandm
parents:
diff changeset
92 my $cluster_exp=join"\t",@cluster_exp;
07745c0958dd Uploaded
big-tiandm
parents:
diff changeset
93 if ($max_length>30) {
07745c0958dd Uploaded
big-tiandm
parents:
diff changeset
94 $max_length="\>30";
07745c0958dd Uploaded
big-tiandm
parents:
diff changeset
95 print TMP "$key\:$start\-$end\t$max_length"."nt\t$max_p\t$tag\n";
07745c0958dd Uploaded
big-tiandm
parents:
diff changeset
96 }
07745c0958dd Uploaded
big-tiandm
parents:
diff changeset
97 else{print TMP "$key\:$start\-$end\t$max_length"."nt\t$max_p\t$tag\n";}
07745c0958dd Uploaded
big-tiandm
parents:
diff changeset
98 print OUT "$key\:$start\-$end\t$max_length"."nt\t$max_p\t$cluster_exp\n";
07745c0958dd Uploaded
big-tiandm
parents:
diff changeset
99
07745c0958dd Uploaded
big-tiandm
parents:
diff changeset
100 }
07745c0958dd Uploaded
big-tiandm
parents:
diff changeset
101 }
07745c0958dd Uploaded
big-tiandm
parents:
diff changeset
102 close OUT;
07745c0958dd Uploaded
big-tiandm
parents:
diff changeset
103 close TMP;
07745c0958dd Uploaded
big-tiandm
parents:
diff changeset
104 sub Max_length{
07745c0958dd Uploaded
big-tiandm
parents:
diff changeset
105 my @exp=@{$_[0]};
07745c0958dd Uploaded
big-tiandm
parents:
diff changeset
106 my %sample_length;
07745c0958dd Uploaded
big-tiandm
parents:
diff changeset
107 my $total_exp;
07745c0958dd Uploaded
big-tiandm
parents:
diff changeset
108 my @each;
07745c0958dd Uploaded
big-tiandm
parents:
diff changeset
109 my @tag;
07745c0958dd Uploaded
big-tiandm
parents:
diff changeset
110 for (my $i=0;$i<=$#exp ;$i++) {
07745c0958dd Uploaded
big-tiandm
parents:
diff changeset
111 my $length=$exp[$i][2]-$exp[$i][1]+1;
07745c0958dd Uploaded
big-tiandm
parents:
diff changeset
112 #if ($length>30) {
07745c0958dd Uploaded
big-tiandm
parents:
diff changeset
113 # $length=40;
07745c0958dd Uploaded
big-tiandm
parents:
diff changeset
114 #}
07745c0958dd Uploaded
big-tiandm
parents:
diff changeset
115 my $exp=0;
07745c0958dd Uploaded
big-tiandm
parents:
diff changeset
116 foreach (1..$opts{'N'}) {
07745c0958dd Uploaded
big-tiandm
parents:
diff changeset
117 $exp+=$exp[$i][$_+2];
07745c0958dd Uploaded
big-tiandm
parents:
diff changeset
118 $each[$_-1]+=$exp[$i][$_+2];
07745c0958dd Uploaded
big-tiandm
parents:
diff changeset
119 }
07745c0958dd Uploaded
big-tiandm
parents:
diff changeset
120 $sample_length{$length}+=$exp;
07745c0958dd Uploaded
big-tiandm
parents:
diff changeset
121 $total_exp+=$exp;
07745c0958dd Uploaded
big-tiandm
parents:
diff changeset
122 push @tag,($exp[$i][1].",".$exp[$i][2].",".$exp[$i][0].",".$exp);
07745c0958dd Uploaded
big-tiandm
parents:
diff changeset
123 }
07745c0958dd Uploaded
big-tiandm
parents:
diff changeset
124 my $max=0;
07745c0958dd Uploaded
big-tiandm
parents:
diff changeset
125 my $max_key;
07745c0958dd Uploaded
big-tiandm
parents:
diff changeset
126 foreach my $key (sort keys %sample_length) {
07745c0958dd Uploaded
big-tiandm
parents:
diff changeset
127 my $p=$sample_length{$key}/$total_exp;
07745c0958dd Uploaded
big-tiandm
parents:
diff changeset
128 if ($p>$max) {
07745c0958dd Uploaded
big-tiandm
parents:
diff changeset
129 $max=$p;
07745c0958dd Uploaded
big-tiandm
parents:
diff changeset
130 $max_key=$key;
07745c0958dd Uploaded
big-tiandm
parents:
diff changeset
131 }
07745c0958dd Uploaded
big-tiandm
parents:
diff changeset
132 $sample_length{$key}=sprintf("%.2f",$p);
07745c0958dd Uploaded
big-tiandm
parents:
diff changeset
133 }
07745c0958dd Uploaded
big-tiandm
parents:
diff changeset
134 my $tag_n=@tag;
07745c0958dd Uploaded
big-tiandm
parents:
diff changeset
135 my $tag=join";",@tag;
07745c0958dd Uploaded
big-tiandm
parents:
diff changeset
136 $tag=$tag_n."\t".$tag;
07745c0958dd Uploaded
big-tiandm
parents:
diff changeset
137 return($max_key,$sample_length{$max_key},$tag,@each);
07745c0958dd Uploaded
big-tiandm
parents:
diff changeset
138 }
07745c0958dd Uploaded
big-tiandm
parents:
diff changeset
139
07745c0958dd Uploaded
big-tiandm
parents:
diff changeset
140 sub usage{
07745c0958dd Uploaded
big-tiandm
parents:
diff changeset
141 print <<"USAGE";
07745c0958dd Uploaded
big-tiandm
parents:
diff changeset
142 Version $version
07745c0958dd Uploaded
big-tiandm
parents:
diff changeset
143 Usage:
07745c0958dd Uploaded
big-tiandm
parents:
diff changeset
144 $0 -i -o -d -N -t -mark
07745c0958dd Uploaded
big-tiandm
parents:
diff changeset
145 options:
07745c0958dd Uploaded
big-tiandm
parents:
diff changeset
146 -i input file
07745c0958dd Uploaded
big-tiandm
parents:
diff changeset
147 -d distance of two islands
07745c0958dd Uploaded
big-tiandm
parents:
diff changeset
148 -mark sample name;
07745c0958dd Uploaded
big-tiandm
parents:
diff changeset
149 -o output file
07745c0958dd Uploaded
big-tiandm
parents:
diff changeset
150 -N sample number
07745c0958dd Uploaded
big-tiandm
parents:
diff changeset
151 -t temp output file
07745c0958dd Uploaded
big-tiandm
parents:
diff changeset
152 -h help
07745c0958dd Uploaded
big-tiandm
parents:
diff changeset
153 USAGE
07745c0958dd Uploaded
big-tiandm
parents:
diff changeset
154 exit(1);
07745c0958dd Uploaded
big-tiandm
parents:
diff changeset
155 }
07745c0958dd Uploaded
big-tiandm
parents:
diff changeset
156