annotate sam2Bed_bowtie.pl @ 0:87fe81de0931 draft default tip

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