annotate sam2Bed_bowtie.pl @ 10:b20345ef3995 draft

Uploaded
author big-tiandm
date Wed, 29 Oct 2014 04:18:27 -0400
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: Tian Dongmei
07745c0958dd Uploaded
big-tiandm
parents:
diff changeset
4 #Email: tiandm@big.ac.cn
07745c0958dd Uploaded
big-tiandm
parents:
diff changeset
5 #Date: 2011/11/7
07745c0958dd Uploaded
big-tiandm
parents:
diff changeset
6 #Modified:
07745c0958dd Uploaded
big-tiandm
parents:
diff changeset
7 #Description: sam2BED
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","mark=s","o=s","h");
07745c0958dd Uploaded
big-tiandm
parents:
diff changeset
15 if (!(defined $opts{i} 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 $mark=$opts{'mark'};
07745c0958dd Uploaded
big-tiandm
parents:
diff changeset
22 my @sample=split/\#/,$mark;
07745c0958dd Uploaded
big-tiandm
parents:
diff changeset
23 $mark=join"\t",@sample;
07745c0958dd Uploaded
big-tiandm
parents:
diff changeset
24 open OUT,">$fileout"; #output file
07745c0958dd Uploaded
big-tiandm
parents:
diff changeset
25 print OUT "#chr\tstrand\tstart\tend\t$mark\n";
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 my $Tags_num=0;
07745c0958dd Uploaded
big-tiandm
parents:
diff changeset
29 my @read_num;
07745c0958dd Uploaded
big-tiandm
parents:
diff changeset
30 #print OUT "#chr\tstart\tend\tnum\t<=20\t21\t22\t23\t24\t>=25\n";
07745c0958dd Uploaded
big-tiandm
parents:
diff changeset
31 while (my $aline=<IN>) {
07745c0958dd Uploaded
big-tiandm
parents:
diff changeset
32 chomp $aline;
07745c0958dd Uploaded
big-tiandm
parents:
diff changeset
33 next if($aline=~/^\@/);
07745c0958dd Uploaded
big-tiandm
parents:
diff changeset
34 my @tmp=split/\t/,$aline;
07745c0958dd Uploaded
big-tiandm
parents:
diff changeset
35 my $strand=$tmp[1];
07745c0958dd Uploaded
big-tiandm
parents:
diff changeset
36 my $start=$tmp[3]+1;
07745c0958dd Uploaded
big-tiandm
parents:
diff changeset
37 my $length=length($tmp[4]);
07745c0958dd Uploaded
big-tiandm
parents:
diff changeset
38 my $end=$start+$length-1;
07745c0958dd Uploaded
big-tiandm
parents:
diff changeset
39 my $hit=$tmp[6]+1;
07745c0958dd Uploaded
big-tiandm
parents:
diff changeset
40 #======express caculate weighted===================================
07745c0958dd Uploaded
big-tiandm
parents:
diff changeset
41 my $exp;
07745c0958dd Uploaded
big-tiandm
parents:
diff changeset
42 my @tempID=split/\:/,$tmp[0];
07745c0958dd Uploaded
big-tiandm
parents:
diff changeset
43 my @exp=split/\_/,$tempID[1];
07745c0958dd Uploaded
big-tiandm
parents:
diff changeset
44 pop @exp;
07745c0958dd Uploaded
big-tiandm
parents:
diff changeset
45 for (my $j=0;$j<@exp ;$j++) {
07745c0958dd Uploaded
big-tiandm
parents:
diff changeset
46 #my @tempID1=split/\=/,$tempID[$j];
07745c0958dd Uploaded
big-tiandm
parents:
diff changeset
47 $exp[$j]=sprintf("%.2f",$exp[$j]/$hit);
07745c0958dd Uploaded
big-tiandm
parents:
diff changeset
48 $read_num[$j]+=$exp[$j];
07745c0958dd Uploaded
big-tiandm
parents:
diff changeset
49 #print OUT "\t$exp";
07745c0958dd Uploaded
big-tiandm
parents:
diff changeset
50 }
07745c0958dd Uploaded
big-tiandm
parents:
diff changeset
51 $exp=join "\t",@exp;
07745c0958dd Uploaded
big-tiandm
parents:
diff changeset
52 print OUT $tmp[2],"\t",$strand,"\t",$start,"\t",$end,"\t",$exp,"\n";
07745c0958dd Uploaded
big-tiandm
parents:
diff changeset
53 $Tags_num++;
07745c0958dd Uploaded
big-tiandm
parents:
diff changeset
54
07745c0958dd Uploaded
big-tiandm
parents:
diff changeset
55 }
07745c0958dd Uploaded
big-tiandm
parents:
diff changeset
56 print "Total Tags numer: $Tags_num\n";
07745c0958dd Uploaded
big-tiandm
parents:
diff changeset
57 my $read_number=join "\t",@read_num;
07745c0958dd Uploaded
big-tiandm
parents:
diff changeset
58 print "Each sample numer: $read_number\n";
07745c0958dd Uploaded
big-tiandm
parents:
diff changeset
59 close IN;
07745c0958dd Uploaded
big-tiandm
parents:
diff changeset
60 close OUT;
07745c0958dd Uploaded
big-tiandm
parents:
diff changeset
61 sub usage{
07745c0958dd Uploaded
big-tiandm
parents:
diff changeset
62 print <<"USAGE";
07745c0958dd Uploaded
big-tiandm
parents:
diff changeset
63 Version $version
07745c0958dd Uploaded
big-tiandm
parents:
diff changeset
64 Usage:
07745c0958dd Uploaded
big-tiandm
parents:
diff changeset
65 $0 -i -o
07745c0958dd Uploaded
big-tiandm
parents:
diff changeset
66 options:
07745c0958dd Uploaded
big-tiandm
parents:
diff changeset
67 -i input file
07745c0958dd Uploaded
big-tiandm
parents:
diff changeset
68 -mark sampleA sampleB sampleC.....
07745c0958dd Uploaded
big-tiandm
parents:
diff changeset
69 -o output file
07745c0958dd Uploaded
big-tiandm
parents:
diff changeset
70 -h help
07745c0958dd Uploaded
big-tiandm
parents:
diff changeset
71 USAGE
07745c0958dd Uploaded
big-tiandm
parents:
diff changeset
72 exit(1);
07745c0958dd Uploaded
big-tiandm
parents:
diff changeset
73 }
07745c0958dd Uploaded
big-tiandm
parents:
diff changeset
74