Mercurial > repos > mcharles > rapsosnp
comparison rapsodyn/filtersam_mapped_and_unique.pl @ 10:0a6c1cfe4dc8 draft
Uploaded
author | mcharles |
---|---|
date | Mon, 19 Jan 2015 04:33:21 -0500 |
parents | 3f7b0788a1c4 |
children |
comparison
equal
deleted
inserted
replaced
9:0e7c6fe60646 | 10:0a6c1cfe4dc8 |
---|---|
1 #!/usr/bin/perl | 1 #!/usr/bin/perl |
2 #V1.1.0 manage empty files | |
2 #V1.0.1 added log, option parameters | 3 #V1.0.1 added log, option parameters |
3 use strict; | 4 use strict; |
4 use warnings; | 5 use warnings; |
5 use Getopt::Long; | 6 use Getopt::Long; |
6 | 7 |
7 my $input_sam_file; | 8 my $input_sam_file; |
8 my $output_sam_file; | 9 my $output_sam_file; |
9 my $log_file; | 10 my $log_file; |
11 my $empty_file=1; | |
10 | 12 |
11 my %bitscore_all; | 13 my %bitscore_all; |
12 my %bitscore_selected; | 14 my %bitscore_selected; |
13 | 15 |
14 GetOptions ( | 16 GetOptions ( |
35 } | 37 } |
36 if (($line =~ /XT\:A\:U/)&&($line =~ /X0\:i\:1/)&&($line =~ /X1\:i\:0\s/)){ | 38 if (($line =~ /XT\:A\:U/)&&($line =~ /X0\:i\:1/)&&($line =~ /X1\:i\:0\s/)){ |
37 my @fields_selected = split (/\s+/,$line); | 39 my @fields_selected = split (/\s+/,$line); |
38 if (($fields_selected[1]==83)||($fields_selected[1]==163)||($fields_selected[1]==147)||($fields_selected[1]==99)){ | 40 if (($fields_selected[1]==83)||($fields_selected[1]==163)||($fields_selected[1]==147)||($fields_selected[1]==99)){ |
39 print $line; | 41 print $line; |
42 $empty_file=0; | |
40 my $bit = $fields_selected[1]; | 43 my $bit = $fields_selected[1]; |
41 if ($bitscore_selected{$bit}){ | 44 if ($bitscore_selected{$bit}){ |
42 $bitscore_selected{$bit}++; | 45 $bitscore_selected{$bit}++; |
43 } | 46 } |
44 else { | 47 else { |
48 } | 51 } |
49 } | 52 } |
50 } | 53 } |
51 | 54 |
52 close (IN); | 55 close (IN); |
53 | |
54 open (LF,">$log_file") or die("Can't open $log_file\n"); | 56 open (LF,">$log_file") or die("Can't open $log_file\n"); |
55 print LF "\n####\t Sam filtering \n"; | 57 if ($empty_file==0){ |
56 print LF "## Before filtering\n"; | 58 print LF "\n####\t Sam filtering \n"; |
57 print LF "bitscore\t:\t"; | 59 print LF "## Before filtering\n"; |
58 foreach my $key (sort {$bitscore_all{$b} <=> $bitscore_all{$a}} keys %bitscore_all) { | 60 print LF "bitscore\t:\t"; |
59 print LF $key,"\t*\t"; | 61 foreach my $key (sort {$bitscore_all{$b} <=> $bitscore_all{$a}} keys %bitscore_all) { |
62 print LF $key,"\t*\t"; | |
63 } | |
64 print LF "\n number \t:\t"; | |
65 foreach my $key (sort {$bitscore_all{$b} <=> $bitscore_all{$a}} keys %bitscore_all) { | |
66 print LF $bitscore_all{$key},"\t*\t"; | |
67 } | |
68 print LF "\n"; | |
69 print LF "## After filtering\n"; | |
70 print LF "bitscore\t:\t"; | |
71 foreach my $key (sort {$bitscore_selected{$b} <=> $bitscore_selected{$a}} keys %bitscore_selected) { | |
72 print LF $key,"\t*\t"; | |
73 } | |
74 print LF "\n number \t:\t"; | |
75 foreach my $key (sort {$bitscore_selected{$b} <=> $bitscore_selected{$a}} keys %bitscore_selected) { | |
76 print LF $bitscore_selected{$key},"\t*\t"; | |
77 } | |
78 print LF "\n"; | |
60 } | 79 } |
61 print LF "\n number \t:\t"; | |
62 foreach my $key (sort {$bitscore_all{$b} <=> $bitscore_all{$a}} keys %bitscore_all) { | |
63 print LF $bitscore_all{$key},"\t*\t"; | |
64 } | |
65 print LF "\n"; | |
66 print LF "## After filtering\n"; | |
67 print LF "bitscore\t:\t"; | |
68 foreach my $key (sort {$bitscore_selected{$b} <=> $bitscore_selected{$a}} keys %bitscore_selected) { | |
69 print LF $key,"\t*\t"; | |
70 } | |
71 print LF "\n number \t:\t"; | |
72 foreach my $key (sort {$bitscore_selected{$b} <=> $bitscore_selected{$a}} keys %bitscore_selected) { | |
73 print LF $bitscore_selected{$key},"\t*\t"; | |
74 } | |
75 print LF "\n"; | |
76 close (LF); | 80 close (LF); |
77 | 81 |
78 | 82 |
79 | 83 |
80 | 84 |