comparison sam2Bed_bowtie.pl @ 50:7b5a48b972e9 draft

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