blib/lib/Bio/Tradis/RemoveTags.pm untested

filter: Statementstmt 0.0% 0 / 55 Branchbran 0.0% 0 / 10 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 5 Podpod 0.0% 0 / 2 totaltotal 0.0% 0 / 72 CC 6 SCAR 28.2
CC
6
Cov
0%
remove_tags
30.0
_tag_mismatch
6.0
BEGIN
2.0
CRAP 16.8
1 package Bio::Tradis::RemoveTags;
2  
3 # ABSTRACT: Remove tags from seqs a fastq file
4  
5  
6 use Moose;
7 use Bio::Tradis::Parser::Fastq;
8  
9 has 'fastqfile' => ( is => 'rw', isa => 'Str', required => 1 );
10 has 'tag' => ( is => 'rw', isa => 'Str', required => 1 );
11 has 'mismatch' => ( is => 'rw', isa => 'Int', required => 0 );
12 has 'outfile' => (
13 is => 'rw',
14 isa => 'Str',
15 required => 0,
16 default => sub {
17 my ($self) = @_;
18 my $o = $self->bamfile;
19 $o =~ s/\.fastq/\.rmtag\.fastq/;
20 return $o;
21 }
22 );
23  
24 sub remove_tags {
25 my ($self) = @_;
26 my $tag = uc( $self->tag );
27 my $outfile = $self->outfile;
28  
29 #set up fastq parser
30 my $filename = $self->fastqfile;
31 my $pars = Bio::Tradis::Parser::Fastq->new( file => $filename );
32  
33 # create file handle for output
34 open( OUTFILE, ">$outfile" );
35  
36 # loop through fastq
37 while ( $pars->next_read ) {
38 my @read = $pars->read_info;
39 my $id = $read[0];
40 my $seq_string = $read[1];
41 my $qual_string = $read[2];
42  
43 # remove the tag
44 my $rm = 0;
45 if ( $self->mismatch == 0 ) {
46 if ( $seq_string =~ m/^$tag/ ) { $rm = 1; }
47 }
48 else {
49 my $mm = $self->_tag_mismatch($seq_string);
50 if ( $mm <= $self->mismatch ) { $rm = 1; }
51 }
52  
53 if ($rm) {
54 my $l = length($tag);
55 $seq_string = substr( $seq_string, $l );
56 $qual_string = substr( $qual_string, $l );
57 }
58  
59 print OUTFILE "\@$id\n";
60 print OUTFILE $seq_string . "\n+\n";
61 print OUTFILE $qual_string . "\n";
62 }
63 close OUTFILE;
64 return 1;
65 }
66  
67 sub _tag_mismatch {
68 my ( $self, $seq_string ) = @_;
69 my $tag_len = length( $self->tag );
70  
71 my @tag = split( "", $self->tag );
72 my @seq = split( "", substr( $seq_string, 0, $tag_len ) );
73 my $mismatches = 0;
74 foreach my $i ( 0 .. ( $tag_len - 1 ) ) {
75 if ( $tag[$i] ne $seq[$i] ) {
76 $mismatches++;
77 }
78 }
79 return $mismatches;
80 }
81  
82 __PACKAGE__->meta->make_immutable;
83 no Moose;
84 1;
85  
86 __END__
87  
88 =pod
89  
90 =head1 NAME
91  
92 Bio::Tradis::RemoveTags - Remove tags from seqs a fastq file
93  
94 =head1 VERSION
95  
96 version 1.132190
97  
98 =head1 SYNOPSIS
99  
100 Reads in a fastq file with tradis tags already attached to the start of the sequence
101 Removes tags from the sequence and quality strings
102 Outputs a file *.rmtag.fastq unless an out file is specified
103  
104 use Bio::Tradis::RemoveTags;
105
106 my $pipeline = Bio::Tradis::RemoveTags->new(fastqfile => 'abc', tag => 'abc');
107 $pipeline->remove_tags();
108  
109 =head1 PARAMETERS
110  
111 =head2 Required
112  
113 =over
114 =item * C<fastqfile> - path to/name of file to filter
115 =item * C<tag> - TraDIS tag to remove
116 =back
117  
118 =head2 Optional
119  
120 =over
121 =item * C<mismatch> - number of mismatches to allow when removing the tag. Default = 0
122 =item * C<outfile> - defaults to C<file.rmtag.fastq> for and input file named C<file.fastq>
123 =back
124  
125 =head1 METHODS
126 C<remove_tags> - output all reads with the tags removed to C<outfile>
127  
128 =head1 AUTHOR
129  
130 Carla Cummins <cc21@sanger.ac.uk>
131  
132 =head1 COPYRIGHT AND LICENSE
133  
134 This software is Copyright (c) 2013 by Wellcome Trust Sanger Institute.
135  
136 This is free software, licensed under:
137  
138 The GNU General Public License, Version 3, June 2007
139  
140 =cut