annotate sam2Bed_bowtie.pl @ 53:f5a2e8308836 draft default tip

Uploaded
author big-tiandm
date Mon, 08 Dec 2014 01:51:16 -0500
parents 7b5a48b972e9
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
50
7b5a48b972e9 Uploaded
big-tiandm
parents:
diff changeset
1 #!/usr/bin/perl -w
7b5a48b972e9 Uploaded
big-tiandm
parents:
diff changeset
2 #Filename:
7b5a48b972e9 Uploaded
big-tiandm
parents:
diff changeset
3 #Author: Tian Dongmei
7b5a48b972e9 Uploaded
big-tiandm
parents:
diff changeset
4 #Email: tiandm@big.ac.cn
7b5a48b972e9 Uploaded
big-tiandm
parents:
diff changeset
5 #Date: 2011/11/7
7b5a48b972e9 Uploaded
big-tiandm
parents:
diff changeset
6 #Modified:
7b5a48b972e9 Uploaded
big-tiandm
parents:
diff changeset
7 #Description: sam2BED
7b5a48b972e9 Uploaded
big-tiandm
parents:
diff changeset
8 my $version=1.00;
7b5a48b972e9 Uploaded
big-tiandm
parents:
diff changeset
9
7b5a48b972e9 Uploaded
big-tiandm
parents:
diff changeset
10 use strict;
7b5a48b972e9 Uploaded
big-tiandm
parents:
diff changeset
11 use Getopt::Long;
7b5a48b972e9 Uploaded
big-tiandm
parents:
diff changeset
12
7b5a48b972e9 Uploaded
big-tiandm
parents:
diff changeset
13 my %opts;
7b5a48b972e9 Uploaded
big-tiandm
parents:
diff changeset
14 GetOptions(\%opts,"i=s","mark=s","o=s","h");
7b5a48b972e9 Uploaded
big-tiandm
parents:
diff changeset
15 if (!(defined $opts{i} and defined $opts{o}) || defined $opts{h}) { #necessary arguments
7b5a48b972e9 Uploaded
big-tiandm
parents:
diff changeset
16 &usage;
7b5a48b972e9 Uploaded
big-tiandm
parents:
diff changeset
17 }
7b5a48b972e9 Uploaded
big-tiandm
parents:
diff changeset
18
7b5a48b972e9 Uploaded
big-tiandm
parents:
diff changeset
19 my $filein=$opts{'i'};
7b5a48b972e9 Uploaded
big-tiandm
parents:
diff changeset
20 my $fileout=$opts{'o'};
7b5a48b972e9 Uploaded
big-tiandm
parents:
diff changeset
21 my $mark=$opts{'mark'};
7b5a48b972e9 Uploaded
big-tiandm
parents:
diff changeset
22 my @sample=split/\#/,$mark;
7b5a48b972e9 Uploaded
big-tiandm
parents:
diff changeset
23 $mark=join"\t",@sample;
7b5a48b972e9 Uploaded
big-tiandm
parents:
diff changeset
24 open OUT,">$fileout"; #output file
7b5a48b972e9 Uploaded
big-tiandm
parents:
diff changeset
25 print OUT "#chr\tstrand\tstart\tend\t$mark\n";
7b5a48b972e9 Uploaded
big-tiandm
parents:
diff changeset
26
7b5a48b972e9 Uploaded
big-tiandm
parents:
diff changeset
27 open IN,"<$filein"; #input file
7b5a48b972e9 Uploaded
big-tiandm
parents:
diff changeset
28 my $Tags_num=0;
7b5a48b972e9 Uploaded
big-tiandm
parents:
diff changeset
29 my @read_num;
7b5a48b972e9 Uploaded
big-tiandm
parents:
diff changeset
30 #print OUT "#chr\tstart\tend\tnum\t<=20\t21\t22\t23\t24\t>=25\n";
7b5a48b972e9 Uploaded
big-tiandm
parents:
diff changeset
31 while (my $aline=<IN>) {
7b5a48b972e9 Uploaded
big-tiandm
parents:
diff changeset
32 chomp $aline;
7b5a48b972e9 Uploaded
big-tiandm
parents:
diff changeset
33 next if($aline=~/^\@/);
7b5a48b972e9 Uploaded
big-tiandm
parents:
diff changeset
34 my @tmp=split/\t/,$aline;
7b5a48b972e9 Uploaded
big-tiandm
parents:
diff changeset
35 my $strand=$tmp[1];
7b5a48b972e9 Uploaded
big-tiandm
parents:
diff changeset
36 my $start=$tmp[3]+1;
7b5a48b972e9 Uploaded
big-tiandm
parents:
diff changeset
37 my $length=length($tmp[4]);
7b5a48b972e9 Uploaded
big-tiandm
parents:
diff changeset
38 my $end=$start+$length-1;
7b5a48b972e9 Uploaded
big-tiandm
parents:
diff changeset
39 my $hit=$tmp[6]+1;
7b5a48b972e9 Uploaded
big-tiandm
parents:
diff changeset
40 #======express caculate weighted===================================
7b5a48b972e9 Uploaded
big-tiandm
parents:
diff changeset
41 my $exp;
7b5a48b972e9 Uploaded
big-tiandm
parents:
diff changeset
42 my @tempID=split/\:/,$tmp[0];
7b5a48b972e9 Uploaded
big-tiandm
parents:
diff changeset
43 my @exp=split/\_/,$tempID[1];
7b5a48b972e9 Uploaded
big-tiandm
parents:
diff changeset
44 pop @exp;
7b5a48b972e9 Uploaded
big-tiandm
parents:
diff changeset
45 for (my $j=0;$j<@exp ;$j++) {
7b5a48b972e9 Uploaded
big-tiandm
parents:
diff changeset
46 #my @tempID1=split/\=/,$tempID[$j];
7b5a48b972e9 Uploaded
big-tiandm
parents:
diff changeset
47 $exp[$j]=sprintf("%.2f",$exp[$j]/$hit);
7b5a48b972e9 Uploaded
big-tiandm
parents:
diff changeset
48 $read_num[$j]+=$exp[$j];
7b5a48b972e9 Uploaded
big-tiandm
parents:
diff changeset
49 #print OUT "\t$exp";
7b5a48b972e9 Uploaded
big-tiandm
parents:
diff changeset
50 }
7b5a48b972e9 Uploaded
big-tiandm
parents:
diff changeset
51 $exp=join "\t",@exp;
7b5a48b972e9 Uploaded
big-tiandm
parents:
diff changeset
52 print OUT $tmp[2],"\t",$strand,"\t",$start,"\t",$end,"\t",$exp,"\n";
7b5a48b972e9 Uploaded
big-tiandm
parents:
diff changeset
53 $Tags_num++;
7b5a48b972e9 Uploaded
big-tiandm
parents:
diff changeset
54
7b5a48b972e9 Uploaded
big-tiandm
parents:
diff changeset
55 }
7b5a48b972e9 Uploaded
big-tiandm
parents:
diff changeset
56 print "Total Tags numer: $Tags_num\n";
7b5a48b972e9 Uploaded
big-tiandm
parents:
diff changeset
57 my $read_number=join "\t",@read_num;
7b5a48b972e9 Uploaded
big-tiandm
parents:
diff changeset
58 print "Each sample numer: $read_number\n";
7b5a48b972e9 Uploaded
big-tiandm
parents:
diff changeset
59 close IN;
7b5a48b972e9 Uploaded
big-tiandm
parents:
diff changeset
60 close OUT;
7b5a48b972e9 Uploaded
big-tiandm
parents:
diff changeset
61 sub usage{
7b5a48b972e9 Uploaded
big-tiandm
parents:
diff changeset
62 print <<"USAGE";
7b5a48b972e9 Uploaded
big-tiandm
parents:
diff changeset
63 Version $version
7b5a48b972e9 Uploaded
big-tiandm
parents:
diff changeset
64 Usage:
7b5a48b972e9 Uploaded
big-tiandm
parents:
diff changeset
65 $0 -i -o
7b5a48b972e9 Uploaded
big-tiandm
parents:
diff changeset
66 options:
7b5a48b972e9 Uploaded
big-tiandm
parents:
diff changeset
67 -i input file
7b5a48b972e9 Uploaded
big-tiandm
parents:
diff changeset
68 -mark sampleA sampleB sampleC.....
7b5a48b972e9 Uploaded
big-tiandm
parents:
diff changeset
69 -o output file
7b5a48b972e9 Uploaded
big-tiandm
parents:
diff changeset
70 -h help
7b5a48b972e9 Uploaded
big-tiandm
parents:
diff changeset
71 USAGE
7b5a48b972e9 Uploaded
big-tiandm
parents:
diff changeset
72 exit(1);
7b5a48b972e9 Uploaded
big-tiandm
parents:
diff changeset
73 }
7b5a48b972e9 Uploaded
big-tiandm
parents:
diff changeset
74