lib/Bio/Tradis/RemoveTags.pm

filter: Statementstmt 92.8% 52 / 56 Branchbran 91.6% 11 / 12 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 83.3% 5 / 6 Podpod 0.0% 0 / 1 totaltotal 90.6% 68 / 75 CC 8 SCAR 13.5
CC
8
Cov
93%
remove_tags
6.0
_tag_mismatch
3.0
__ANON__
2.0
CRAP 3.8
« lib/Bio/Tradis/FilterTags.pm ↑ Summary lib/Bio/Tradis/Map.pm »
1 package Bio::Tradis::RemoveTags;
2 6 $Bio::Tradis::RemoveTags::VERSION = '1.4.5';
3 # ABSTRACT: Remove tags from seqs a fastq file
4  
5  
6 6 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 6 ▶use Bio::Tradis::Parser::Fastq;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 6 has 'fastqfile' => ( is => 'rw', isa => 'Str', required => 1 );
10 6 has 'tag' => ( is => 'rw', isa => 'Str', required => 1 );
11 6 has 'mismatch' => ( is => 'rw', isa => 'Int', required => 0 );
12 has 'outfile' => (
13 is => 'rw',
14 isa => 'Str',
15 required => 0,
16 0 ▶ default => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
17 0 my ($self) = @_;
18 0 my $o = $self->bamfile;
19 0 $o =~ s/\.fastq/\.rmtag\.fastq/;
20 0 return $o;
21 }
22 6 );
23  
24 6 ▶sub remove_tags {
Subroutine remove_tags: called CC=6 SCAR=17.9
Pod undocumented
25 6 my ($self) = @_;
26 6 my $tag = uc( $self->tag );
27 6 my $outfile = $self->outfile;
28  
29 #set up fastq parser
30 6 my $filename = $self->fastqfile;
31 6 my $pars = Bio::Tradis::Parser::Fastq->new( file => $filename );
32  
33 # create file handle for output
34 6 open( OUTFILE, ">$outfile" );
35  
36 # loop through fastq
37 6 ▶ while ( $pars->next_read ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($pars->next_read) 81 6 87
38 81 my @read = $pars->read_info;
39 81 my $id = $read[0];
40 81 my $seq_string = $read[1];
41 81 my $qual_string = $read[2];
42  
43 # remove the tag
44 81 my $rm = 0;
45 81 ▶ if ( $self->mismatch == 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->mismatch == 0) { } 71 10 81
46 71 ▶ if ( $seq_string =~ m/^$tag/ ) { $rm = 1; }
Branch: 1 branch
BranchTrueFalseTotal
if ($seq_string =~ /^$tag/) 69 2 71
47 }
48 else {
49 10 my $mm = $self->_tag_mismatch($seq_string);
50 10 ▶ if ( $mm <= $self->mismatch ) { $rm = 1; }
Branch: 1 branch
BranchTrueFalseTotal
if ($mm <= $self->mismatch) 10 0 10
51 }
52  
53 81 ▶ if ($rm) {
Branch: 1 branch
BranchTrueFalseTotal
if ($rm) 79 2 81
54 79 my $l = length($tag);
55 79 $seq_string = substr( $seq_string, $l );
56 79 $qual_string = substr( $qual_string, $l );
57 }
58  
59 81 print OUTFILE "\@$id\n";
60 81 print OUTFILE $seq_string . "\n+\n";
61 81 print OUTFILE $qual_string . "\n";
62 }
63 6 close OUTFILE;
64 6 return 1;
65 }
66  
67 10 ▶sub _tag_mismatch {
Subroutine _tag_mismatch: called CC=3 SCAR=11.0
68 10 my ( $self, $seq_string ) = @_;
69 10 my $tag_len = length( $self->tag );
70  
71 10 my @tag = split( "", $self->tag );
72 10 my @seq = split( "", substr( $seq_string, 0, $tag_len ) );
73 10 my $mismatches = 0;
74 10 foreach my $i ( 0 .. ( $tag_len - 1 ) ) {
75 90 ▶ if ( $tag[$i] ne $seq[$i] ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($tag[$i] ne $seq[$i]) 2 88 90
76 2 $mismatches++;
77 }
78 }
79 10 return $mismatches;
80 }
81  
82 6 __PACKAGE__->meta->make_immutable;
83 6 ▶no Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
84 6 1;
85  
86 __END__
« lib/Bio/Tradis/FilterTags.pm ↑ Summary lib/Bio/Tradis/Map.pm »