| 1 | package FASTX::Reader; | ||||||||||||||||||||||||||||||||||||||||||
| 2 | 39 | ▶ | use 5.012; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 3 | 39 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 4 | 39 | ▶ | use Carp qw(confess); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 5 | 39 | ▶ | use Data::Dumper; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 6 | 39 | ▶ | use PerlIO::encoding; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 7 | 39 | $Data::Dumper::Sortkeys = 1; | |||||||||||||||||||||||||||||||||||||||||
| 8 | 39 | ▶ | use FASTX::Seq; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 9 | 39 | ▶ | use File::Basename; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 10 | 39 | $FASTX::Reader::VERSION = '1.12.1'; | |||||||||||||||||||||||||||||||||||||||||
| 11 | 39 | require Exporter; | |||||||||||||||||||||||||||||||||||||||||
| 12 | 39 | our @ISA = qw(Exporter); | |||||||||||||||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||||||||||||||||
| 14 | #ABSTRACT: A simple module to parse FASTA and FASTQ files, supporting compressed files and paired-ends. | ||||||||||||||||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||||||||||||||||
| 16 | 39 | ▶ | use constant GZIP_SIGNATURE => pack('C3', 0x1f, 0x8b, 0x08); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||||||||||||||||
| 19 | 73 | ▶ | sub new { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=25 SCAR=34.7
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 20 | # Instantiate object | ||||||||||||||||||||||||||||||||||||||||||
| 21 | 73 | my $class = shift @_; | |||||||||||||||||||||||||||||||||||||||||
| 22 | 73 | my $self = bless {} => $class; | |||||||||||||||||||||||||||||||||||||||||
| 23 | 73 | my $args = {}; | |||||||||||||||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||||||||||||||||
| 25 | # Named parameters: undefined $_[0] will read STDIN! | ||||||||||||||||||||||||||||||||||||||||||
| 26 | 73 | ▶ | if (defined $_[0] and substr($_[0], 0, 1) eq '-') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
defined $_[0] and substr($_[0], 0, 1) eq "-"
MC/DC100%2/2
defined $_[0] and substr($_[0], 0, 1) eq "-"
defined $_[0]
substr($_[0], 0, 1) eq "-"
Truth table100%3/3
A and B
A= defined $_[0]B= substr($_[0], 0, 1) eq "-"
| |||||||||||||||||||||||||||||||||||||||||||
| 27 | 9 | my %data = @_; | |||||||||||||||||||||||||||||||||||||||||
| 28 | # Try parsing | ||||||||||||||||||||||||||||||||||||||||||
| 29 | 9 | for my $i (keys %data) { | |||||||||||||||||||||||||||||||||||||||||
| 30 | 13 | ▶ | if ($i =~ /^-(file|filename)/i) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 31 | 8 | $args->{filename} = $data{$i}; | |||||||||||||||||||||||||||||||||||||||||
| 32 | } elsif ($i =~ /^-(loadseqs)/i) { | ||||||||||||||||||||||||||||||||||||||||||
| 33 | 4 | $args->{loadseqs} = $data{$i}; | |||||||||||||||||||||||||||||||||||||||||
| 34 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 35 | 1 | confess "[FASTX::Reader]: Unknown parameter `$i`\n"; | |||||||||||||||||||||||||||||||||||||||||
| 36 | } | ||||||||||||||||||||||||||||||||||||||||||
| 37 | } | ||||||||||||||||||||||||||||||||||||||||||
| 38 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 39 | # Legacy instantiation | ||||||||||||||||||||||||||||||||||||||||||
| 40 | 64 | ($args) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 41 | } | ||||||||||||||||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||||||||||||||||
| 45 | 72 | ▶ | if (defined $args->{loadseqs}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 46 | 6 | ▶ | if ($args->{loadseqs} eq 'name' or $args->{loadseqs} eq 'names' ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
Condition66%2/3
$args->{"loadseqs"} eq "name" or $args->{"loadseqs"} eq "names"
MC/DC50%1/2
$args->{"loadseqs"} eq "name" or $args->{"loadseqs"} eq "names"
$args->{"loadseqs"} eq "name"
$args->{"loadseqs"} eq "names"
Truth table66%2/3
A or B
A= $args->{"loadseqs"} eq "name"B= $args->{"loadseqs"} eq "names"
| |||||||||||||||||||||||||||||||||||||||||||
| 47 | 4 | $args->{loadseqs} = 'name'; | |||||||||||||||||||||||||||||||||||||||||
| 48 | ▶ | } elsif ($args->{loadseqs} eq 'seq' or $args->{loadseqs} eq 'seqs' or $args->{loadseqs} eq "1") { | |||||||||||||||||||||||||||||||||||||||||
|
Condition66%4/6
$args->{"loadseqs"} eq "seq" or $args->{"loadseqs"} eq "seqs" or $args->{"loadseqs"} eq 1
$args->{"loadseqs"} eq "seq" or $args->{"loadseqs"} eq "seqs"
MC/DC33%1/3
$args->{"loadseqs"} eq "seq" or $args->{"loadseqs"} eq "seqs" or $args->{"loadseqs"} eq 1
$args->{"loadseqs"} eq "seq"
$args->{"loadseqs"} eq "seqs"
$args->{"loadseqs"} eq 1
Truth table50%2/4
A or B or C
A= $args->{"loadseqs"} eq "seq"B= $args->{"loadseqs"} eq "seqs"C= $args->{"loadseqs"} eq 1
| |||||||||||||||||||||||||||||||||||||||||||
| 49 | 1 | $args->{loadseqs} = 'seq'; | |||||||||||||||||||||||||||||||||||||||||
| 50 | } elsif ($args->{loadseqs} eq 'records') { | ||||||||||||||||||||||||||||||||||||||||||
| 51 | 1 | $args->{loadseqs} = 'records'; | |||||||||||||||||||||||||||||||||||||||||
| 52 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 53 | 0 | confess("attribute <loadseqs> should be 'name' or 'seq' to specify the key of the hash."); | |||||||||||||||||||||||||||||||||||||||||
| 54 | } | ||||||||||||||||||||||||||||||||||||||||||
| 55 | } | ||||||||||||||||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||||||||||||||||
| 57 | 72 | $self->{filename} = $args->{filename}; | |||||||||||||||||||||||||||||||||||||||||
| 58 | 72 | $self->{loadseqs} = $args->{loadseqs}; | |||||||||||||||||||||||||||||||||||||||||
| 59 | 72 | $self->{aux} = [undef]; | |||||||||||||||||||||||||||||||||||||||||
| 60 | 72 | $self->{compressed} = 0; | |||||||||||||||||||||||||||||||||||||||||
| 61 | 72 | $self->{fh} = undef; | |||||||||||||||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||||||||||||||||
| 64 | # Check if a filename was provided and not {{STDIN}} | ||||||||||||||||||||||||||||||||||||||||||
| 65 | # uncoverable branch false | ||||||||||||||||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||||||||||||||||
| 67 | 72 | ▶ | if ( defined $self->{filename} and -d $self->{filename} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $self->{"filename"} and -d $self->{"filename"}
MC/DC0%0/2
defined $self->{"filename"} and -d $self->{"filename"}
defined $self->{"filename"}
-d $self->{"filename"}
Truth table66%2/3
A and B
A= defined $self->{"filename"}B= -d $self->{"filename"}
| |||||||||||||||||||||||||||||||||||||||||||
| 68 | 0 | confess __PACKAGE__, " Directory provide where file was expected\n"; | |||||||||||||||||||||||||||||||||||||||||
| 69 | } | ||||||||||||||||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||||||||||||||||
| 71 | 72 | ▶ | if (defined $self->{filename} and $self->{filename} ne '{{STDIN}}') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $self->{"filename"} and $self->{"filename"} ne "{{STDIN}}"
MC/DC50%1/2
defined $self->{"filename"} and $self->{"filename"} ne "{{STDIN}}"
defined $self->{"filename"}
$self->{"filename"} ne "{{STDIN}}"
Truth table66%2/3
A and B
A= defined $self->{"filename"}B= $self->{"filename"} ne "{{STDIN}}"
| |||||||||||||||||||||||||||||||||||||||||||
| 72 | 70 | ▶ | open my $initial_fh, '<', $self->{filename} or confess "Unable to read file ", $self->{filename}, "\n"; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 73 | 66 | read( $initial_fh, my $magic_byte, 4 ); | |||||||||||||||||||||||||||||||||||||||||
| 74 | 66 | close $initial_fh; | |||||||||||||||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||||||||||||||||
| 76 | # See: __BioX::Seq::Stream__ for GZIP (and other) compressed file reader | ||||||||||||||||||||||||||||||||||||||||||
| 77 | 66 | ▶ | if (substr($magic_byte,0,3) eq GZIP_SIGNATURE) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 78 | 33 | $self->{compressed} = 1; | |||||||||||||||||||||||||||||||||||||||||
| 79 | 33 | our $GZIP_BIN = _which('pigz', 'gzip'); | |||||||||||||||||||||||||||||||||||||||||
| 80 | #close $fh; | ||||||||||||||||||||||||||||||||||||||||||
| 81 | 33 | ▶ | if (! defined $GZIP_BIN) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 82 | 0 | $self->{decompressor} = 'IO::Uncompress::Gunzip'; | |||||||||||||||||||||||||||||||||||||||||
| 83 | 0 | require IO::Uncompress::Gunzip; | |||||||||||||||||||||||||||||||||||||||||
| 84 | 0 | my $fh = IO::Uncompress::Gunzip->new($self->{filename}, MultiStream => 1); | |||||||||||||||||||||||||||||||||||||||||
| 85 | 0 | $self->{fh} = $fh; | |||||||||||||||||||||||||||||||||||||||||
| 86 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 87 | 33 | $self->{decompressor} = $GZIP_BIN; | |||||||||||||||||||||||||||||||||||||||||
| 88 | 33 | ▶ | open my $fh, '-|', "$GZIP_BIN -dc $self->{filename}" or confess "Error opening gzip file ", $self->{filename}, ": $!\n"; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 89 | 33 | $self->{fh} = $fh; | |||||||||||||||||||||||||||||||||||||||||
| 90 | } | ||||||||||||||||||||||||||||||||||||||||||
| 91 | } elsif (-B $self->{filename}) { | ||||||||||||||||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||||||||||||||||
| 93 | # BINARY FILE NOT SUPPORTED? | ||||||||||||||||||||||||||||||||||||||||||
| 94 | #close $fh; | ||||||||||||||||||||||||||||||||||||||||||
| 95 | 0 | $self->{fh} = undef; | |||||||||||||||||||||||||||||||||||||||||
| 96 | 0 | $self->{status} = 1; | |||||||||||||||||||||||||||||||||||||||||
| 97 | 0 | $self->{message} = 'Binary file not supported'; | |||||||||||||||||||||||||||||||||||||||||
| 98 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||||||||||||||||
| 100 | #close $fh; | ||||||||||||||||||||||||||||||||||||||||||
| 101 | 33 | ▶ | open (my $fh, '<:encoding(utf8):crlf', $self->{filename}) or confess "Unable to read file ", $self->{filename}, ": ", $!, "\n"; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 102 | 33 | $self->{fh} = $fh; | |||||||||||||||||||||||||||||||||||||||||
| 103 | } | ||||||||||||||||||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||||||||||||||||
| 106 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 107 | # Filename not provided, use STDIN | ||||||||||||||||||||||||||||||||||||||||||
| 108 | 2 | $self->{fh} = \*STDIN; | |||||||||||||||||||||||||||||||||||||||||
| 109 | 2 | ▶ | if ($self->{loadseqs}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 110 | 0 | confess("Load sequences not supported for STDIN"); | |||||||||||||||||||||||||||||||||||||||||
| 111 | } | ||||||||||||||||||||||||||||||||||||||||||
| 112 | } | ||||||||||||||||||||||||||||||||||||||||||
| 113 | |||||||||||||||||||||||||||||||||||||||||||
| 114 | |||||||||||||||||||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||||||||||||||||||||
| 117 | 68 | ▶ | if ($self->{loadseqs}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 118 | 6 | _load_seqs($self); | |||||||||||||||||||||||||||||||||||||||||
| 119 | } | ||||||||||||||||||||||||||||||||||||||||||
| 120 | |||||||||||||||||||||||||||||||||||||||||||
| 121 | 68 | return $self; | |||||||||||||||||||||||||||||||||||||||||
| 122 | |||||||||||||||||||||||||||||||||||||||||||
| 123 | } | ||||||||||||||||||||||||||||||||||||||||||
| 124 | |||||||||||||||||||||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||||||||||||||||||
| 126 | 1 | ▶ | sub records { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
records: called CC=2 SCAR=7.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 127 | 1 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 128 | 1 | ▶ | confess "No records loaded with -loadseqs => records!\n" unless $self->{loadseqs} eq 'records'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 129 | 1 | return $self->{seqs}; | |||||||||||||||||||||||||||||||||||||||||
| 130 | } | ||||||||||||||||||||||||||||||||||||||||||
| 131 | |||||||||||||||||||||||||||||||||||||||||||
| 132 | |||||||||||||||||||||||||||||||||||||||||||
| 133 | 181 | ▶ | sub getRead { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
getRead: called CC=21 SCAR=31.6
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 134 | 181 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 135 | |||||||||||||||||||||||||||||||||||||||||||
| 136 | #@<instrument>:<run number>:<flowcell ID>:<lane>:<tile>:<x-pos>:<y-pos>:<UMI> <read>:<is filtered>:<control number>:<index> | ||||||||||||||||||||||||||||||||||||||||||
| 137 | |||||||||||||||||||||||||||||||||||||||||||
| 138 | |||||||||||||||||||||||||||||||||||||||||||
| 139 | 181 | ▶ | return if (defined $self->{status} and $self->{status} == 0); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $self->{"status"} and $self->{"status"} == 0
MC/DC0%0/2
defined $self->{"status"} and $self->{"status"} == 0
defined $self->{"status"}
$self->{"status"} == 0
Truth table33%1/3
A and B
A= defined $self->{"status"}B= $self->{"status"} == 0
| |||||||||||||||||||||||||||||||||||||||||||
| 140 | |||||||||||||||||||||||||||||||||||||||||||
| 141 | #my $aux = $self->{aux}; | ||||||||||||||||||||||||||||||||||||||||||
| 142 | 181 | my $sequence_data; | |||||||||||||||||||||||||||||||||||||||||
| 143 | 0 | ▶ | @{ $self->{aux} } = [undef, 0] if (!(@{ $self->{aux} })); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 144 | |||||||||||||||||||||||||||||||||||||||||||
| 145 | |||||||||||||||||||||||||||||||||||||||||||
| 146 | 181 | ▶ | if ($self->{aux}->[1]) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 147 | 15 | $self->{return_0}++; | |||||||||||||||||||||||||||||||||||||||||
| 148 | } | ||||||||||||||||||||||||||||||||||||||||||
| 149 | |||||||||||||||||||||||||||||||||||||||||||
| 150 | 181 | ▶ | if (!defined($self->{aux}->[0])) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 151 | 117 | ▶ | while ($self->{line} = readline($self->{fh})) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 152 | |||||||||||||||||||||||||||||||||||||||||||
| 153 | 101 | chomp($self->{line}); | |||||||||||||||||||||||||||||||||||||||||
| 154 | 101 | ▶ | if (substr($self->{line}, 0, 1) eq '>' || substr($self->{line}, 0, 1) eq '@') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
substr($self->{"line"}, 0, 1) eq ">" or substr($self->{"line"}, 0, 1) eq "\@"
MC/DC100%2/2
substr($self->{"line"}, 0, 1) eq ">" or substr($self->{"line"}, 0, 1) eq "\@"
substr($self->{"line"}, 0, 1) eq ">"
substr($self->{"line"}, 0, 1) eq "\@"
Truth table100%3/3
A or B
A= substr($self->{"line"}, 0, 1) eq ">"B= substr($self->{"line"}, 0, 1) eq "\@"
| |||||||||||||||||||||||||||||||||||||||||||
| 155 | 95 | $self->{aux}->[0] = $self->{line}; | |||||||||||||||||||||||||||||||||||||||||
| 156 | 95 | last; | |||||||||||||||||||||||||||||||||||||||||
| 157 | } | ||||||||||||||||||||||||||||||||||||||||||
| 158 | } | ||||||||||||||||||||||||||||||||||||||||||
| 159 | 117 | ▶ | if (!defined($self->{aux}->[0])) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 160 | 22 | $self->{aux}->[1] = 1; | |||||||||||||||||||||||||||||||||||||||||
| 161 | 22 | $self->{return_1}++; | |||||||||||||||||||||||||||||||||||||||||
| 162 | 22 | return; | |||||||||||||||||||||||||||||||||||||||||
| 163 | } | ||||||||||||||||||||||||||||||||||||||||||
| 164 | } | ||||||||||||||||||||||||||||||||||||||||||
| 165 | |||||||||||||||||||||||||||||||||||||||||||
| 166 | |||||||||||||||||||||||||||||||||||||||||||
| 167 | # Comments can have more spaces: | ||||||||||||||||||||||||||||||||||||||||||
| 168 | 159 | ▶ | return unless defined $self->{line}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 169 | my ($name, $comm) = $self->{line}=~/^.(\S+)(?:\s+)(.+)/ ? ($1, $2) : | ||||||||||||||||||||||||||||||||||||||||||
| 170 | 159 | ▶ | $self->{line}=~/^.(\S+)/ ? ($1, '') : ('?', ''); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 171 | 159 | my $seq = ''; | |||||||||||||||||||||||||||||||||||||||||
| 172 | 159 | my $c; | |||||||||||||||||||||||||||||||||||||||||
| 173 | 159 | $self->{aux}->[0] = undef; | |||||||||||||||||||||||||||||||||||||||||
| 174 | 159 | ▶ | while ($self->{line} = readline($self->{fh})) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 175 | # PARSE SEQx | ||||||||||||||||||||||||||||||||||||||||||
| 176 | 361 | chomp($self->{line}); | |||||||||||||||||||||||||||||||||||||||||
| 177 | 361 | $c = substr($self->{line}, 0, 1); | |||||||||||||||||||||||||||||||||||||||||
| 178 | 361 | ▶ | last if ($c eq '>' || $c eq '@' || $c eq '+'); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition83%5/6
$c eq ">" or $c eq "\@" or $c eq "+"
$c eq ">" or $c eq "\@"
MC/DC66%2/3
$c eq ">" or $c eq "\@" or $c eq "+"
$c eq ">"
$c eq "\@"
$c eq "+"
Truth table75%3/4
A or B or C
A= $c eq ">"B= $c eq "\@"C= $c eq "+"
| |||||||||||||||||||||||||||||||||||||||||||
| 179 | 220 | $seq .= $self->{line}; | |||||||||||||||||||||||||||||||||||||||||
| 180 | } | ||||||||||||||||||||||||||||||||||||||||||
| 181 | 159 | $self->{aux}->[0] = $self->{line}; | |||||||||||||||||||||||||||||||||||||||||
| 182 | 159 | ▶ | $self->{aux}->[1] = 1 if (!defined($self->{aux}->[0])); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 183 | 159 | $sequence_data->{name} = $name; | |||||||||||||||||||||||||||||||||||||||||
| 184 | 159 | $sequence_data->{comment} = $comm; | |||||||||||||||||||||||||||||||||||||||||
| 185 | 159 | $sequence_data->{seq} = $seq; | |||||||||||||||||||||||||||||||||||||||||
| 186 | 159 | $self->{counter}++; | |||||||||||||||||||||||||||||||||||||||||
| 187 | # Return FASTA | ||||||||||||||||||||||||||||||||||||||||||
| 188 | 159 | ▶ | if ($c ne '+') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 189 | 94 | $self->{return_fasta1}++; | |||||||||||||||||||||||||||||||||||||||||
| 190 | 94 | return $sequence_data; | |||||||||||||||||||||||||||||||||||||||||
| 191 | } | ||||||||||||||||||||||||||||||||||||||||||
| 192 | 65 | my $qual = ''; | |||||||||||||||||||||||||||||||||||||||||
| 193 | |||||||||||||||||||||||||||||||||||||||||||
| 194 | |||||||||||||||||||||||||||||||||||||||||||
| 195 | 65 | ▶ | while ($self->{line} = readline($self->{fh})) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 196 | # PARSE QUALITY | ||||||||||||||||||||||||||||||||||||||||||
| 197 | 65 | chomp($self->{line}); | |||||||||||||||||||||||||||||||||||||||||
| 198 | 65 | $qual .= $self->{line}; | |||||||||||||||||||||||||||||||||||||||||
| 199 | 65 | ▶ | if (length($qual) >= length($seq)) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 200 | 65 | $self->{aux}->[0] = undef; | |||||||||||||||||||||||||||||||||||||||||
| 201 | 65 | $sequence_data->{name} = $name; | |||||||||||||||||||||||||||||||||||||||||
| 202 | 65 | $sequence_data->{seq} = $seq; | |||||||||||||||||||||||||||||||||||||||||
| 203 | 65 | $sequence_data->{comment} = $comm; | |||||||||||||||||||||||||||||||||||||||||
| 204 | 65 | $sequence_data->{qual} = $qual; | |||||||||||||||||||||||||||||||||||||||||
| 205 | # return FASTQ | ||||||||||||||||||||||||||||||||||||||||||
| 206 | 65 | $self->{return_fastq}++; | |||||||||||||||||||||||||||||||||||||||||
| 207 | 65 | return $sequence_data; | |||||||||||||||||||||||||||||||||||||||||
| 208 | } | ||||||||||||||||||||||||||||||||||||||||||
| 209 | } | ||||||||||||||||||||||||||||||||||||||||||
| 210 | # PROCH | ||||||||||||||||||||||||||||||||||||||||||
| 211 | 0 | close $self->{fh}; | |||||||||||||||||||||||||||||||||||||||||
| 212 | |||||||||||||||||||||||||||||||||||||||||||
| 213 | 0 | $self->{aux}->[1] = 1; | |||||||||||||||||||||||||||||||||||||||||
| 214 | 0 | $sequence_data->{name} = $name; | |||||||||||||||||||||||||||||||||||||||||
| 215 | 0 | $sequence_data->{seq} = $seq; | |||||||||||||||||||||||||||||||||||||||||
| 216 | 0 | $sequence_data->{comment} = $comm; | |||||||||||||||||||||||||||||||||||||||||
| 217 | 0 | $self->{counter}++; | |||||||||||||||||||||||||||||||||||||||||
| 218 | # return FASTA | ||||||||||||||||||||||||||||||||||||||||||
| 219 | 0 | $self->{return_fasta2}++; | |||||||||||||||||||||||||||||||||||||||||
| 220 | 0 | return $sequence_data; | |||||||||||||||||||||||||||||||||||||||||
| 221 | |||||||||||||||||||||||||||||||||||||||||||
| 222 | } | ||||||||||||||||||||||||||||||||||||||||||
| 223 | |||||||||||||||||||||||||||||||||||||||||||
| 224 | |||||||||||||||||||||||||||||||||||||||||||
| 225 | 47 | ▶ | sub next { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
next: called CC=6 SCAR=18.5
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 226 | 47 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 227 | 47 | my $scalar_read = $self->getRead(); | |||||||||||||||||||||||||||||||||||||||||
| 228 | 47 | ▶ | return unless defined $scalar_read; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 229 | return FASTX::Seq->new( $scalar_read->{seq} // '', | ||||||||||||||||||||||||||||||||||||||||||
| 230 | $scalar_read->{name} // undef, | ||||||||||||||||||||||||||||||||||||||||||
| 231 | $scalar_read->{comment} // undef, | ||||||||||||||||||||||||||||||||||||||||||
| 232 | 42 | ▶ | $scalar_read->{qual} // undef); | ||||||||||||||||||||||||||||||||||||||||
|
Condition62%5/8
$scalar_read->{"seq"} // ""
$scalar_read->{"name"} // undef
$scalar_read->{"comment"} // undef
$scalar_read->{"qual"} // undef
MC/DC0%0/1
$scalar_read->{"seq"} // ""
$scalar_read->{"seq"}
MC/DC0%0/1
$scalar_read->{"name"} // undef
$scalar_read->{"name"}
MC/DC0%0/1
$scalar_read->{"comment"} // undef
$scalar_read->{"comment"}
MC/DC100%1/1
$scalar_read->{"qual"} // undef
$scalar_read->{"qual"}
Truth table50%1/2
A
A= $scalar_read->{"seq"}
Truth table50%1/2
A
A= $scalar_read->{"name"}
Truth table50%1/2
A
A= $scalar_read->{"comment"}
Truth table100%2/2
A
A= $scalar_read->{"qual"}
| |||||||||||||||||||||||||||||||||||||||||||
| 233 | |||||||||||||||||||||||||||||||||||||||||||
| 234 | } | ||||||||||||||||||||||||||||||||||||||||||
| 235 | |||||||||||||||||||||||||||||||||||||||||||
| 236 | |||||||||||||||||||||||||||||||||||||||||||
| 237 | 7 | ▶ | sub getFastqRead { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
getFastqRead: called CC=10 SCAR=23.4
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 238 | 7 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 239 | 7 | my $seq_object = undef; | |||||||||||||||||||||||||||||||||||||||||
| 240 | |||||||||||||||||||||||||||||||||||||||||||
| 241 | 7 | ▶ | return if (defined $self->{status} and $self->{status} == 0); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $self->{"status"} and $self->{"status"} == 0
MC/DC0%0/2
defined $self->{"status"} and $self->{"status"} == 0
defined $self->{"status"}
$self->{"status"} == 0
Truth table66%2/3
A and B
A= defined $self->{"status"}B= $self->{"status"} == 0
| |||||||||||||||||||||||||||||||||||||||||||
| 242 | |||||||||||||||||||||||||||||||||||||||||||
| 243 | 7 | $self->{status} = 1; | |||||||||||||||||||||||||||||||||||||||||
| 244 | 7 | my $header = readline($self->{fh}); | |||||||||||||||||||||||||||||||||||||||||
| 245 | 7 | my $seq = readline($self->{fh}); | |||||||||||||||||||||||||||||||||||||||||
| 246 | 7 | my $check = readline($self->{fh}); | |||||||||||||||||||||||||||||||||||||||||
| 247 | 7 | my $qual = readline($self->{fh}); | |||||||||||||||||||||||||||||||||||||||||
| 248 | |||||||||||||||||||||||||||||||||||||||||||
| 249 | |||||||||||||||||||||||||||||||||||||||||||
| 250 | # Check 4 lines were found (FASTQ) | ||||||||||||||||||||||||||||||||||||||||||
| 251 | |||||||||||||||||||||||||||||||||||||||||||
| 252 | 7 | ▶ | unless (defined $qual) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 253 | 1 | ▶ | if (defined $header) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 254 | 0 | $self->{message} = "Unknown format: FASTQ truncated at " . $header . "?"; | |||||||||||||||||||||||||||||||||||||||||
| 255 | 0 | $self->{status} = 0; | |||||||||||||||||||||||||||||||||||||||||
| 256 | } | ||||||||||||||||||||||||||||||||||||||||||
| 257 | 1 | return; | |||||||||||||||||||||||||||||||||||||||||
| 258 | } | ||||||||||||||||||||||||||||||||||||||||||
| 259 | |||||||||||||||||||||||||||||||||||||||||||
| 260 | # Fast format control: header and separator | ||||||||||||||||||||||||||||||||||||||||||
| 261 | 6 | ▶ | if ( (substr($header, 0, 1) eq '@') and (substr($check, 0, 1) eq '+') ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
substr($header, 0, 1) eq "\@" and substr($check, 0, 1) eq "+"
MC/DC50%1/2
substr($header, 0, 1) eq "\@" and substr($check, 0, 1) eq "+"
substr($header, 0, 1) eq "\@"
substr($check, 0, 1) eq "+"
Truth table66%2/3
A and B
A= substr($header, 0, 1) eq "\@"B= substr($check, 0, 1) eq "+"
| |||||||||||||||||||||||||||||||||||||||||||
| 262 | 5 | chomp($header); | |||||||||||||||||||||||||||||||||||||||||
| 263 | 5 | chomp($seq); | |||||||||||||||||||||||||||||||||||||||||
| 264 | 5 | chomp($qual); | |||||||||||||||||||||||||||||||||||||||||
| 265 | # Also control sequence integrity | ||||||||||||||||||||||||||||||||||||||||||
| 266 | 5 | ▶ | if ($seq=~/^[ACGTNacgtn]+$/ and length($seq) == length($qual) ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$seq =~ /^[ACGTNacgtn]+$/u and length $seq == length $qual
MC/DC50%1/2
$seq =~ /^[ACGTNacgtn]+$/u and length $seq == length $qual
$seq =~ /^[ACGTNacgtn]+$/u
length $seq == length $qual
Truth table66%2/3
A and B
A= $seq =~ /^[ACGTNacgtn]+$/uB= length $seq == length $qual
| |||||||||||||||||||||||||||||||||||||||||||
| 267 | 4 | my ($name, $comments) = split /\s+/, substr($header, 1); | |||||||||||||||||||||||||||||||||||||||||
| 268 | 4 | $seq_object->{name} = $name; | |||||||||||||||||||||||||||||||||||||||||
| 269 | 4 | $seq_object->{comments} = $comments; | |||||||||||||||||||||||||||||||||||||||||
| 270 | 4 | $seq_object->{seq} = $seq; | |||||||||||||||||||||||||||||||||||||||||
| 271 | 4 | $seq_object->{qual} = $qual; | |||||||||||||||||||||||||||||||||||||||||
| 272 | 4 | $self->{counter}++; | |||||||||||||||||||||||||||||||||||||||||
| 273 | |||||||||||||||||||||||||||||||||||||||||||
| 274 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 275 | # Return error (corrupted FASTQ) | ||||||||||||||||||||||||||||||||||||||||||
| 276 | 1 | $self->{message} = "Unknown format: expecting FASTQ (corrupted?)"; | |||||||||||||||||||||||||||||||||||||||||
| 277 | 1 | $self->{status} = 0; | |||||||||||||||||||||||||||||||||||||||||
| 278 | |||||||||||||||||||||||||||||||||||||||||||
| 279 | } | ||||||||||||||||||||||||||||||||||||||||||
| 280 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 281 | # Return error (not a FASTQ) | ||||||||||||||||||||||||||||||||||||||||||
| 282 | 1 | $self->{message} = "Unknown format: expecting FASTQ but @ header not found"; | |||||||||||||||||||||||||||||||||||||||||
| 283 | |||||||||||||||||||||||||||||||||||||||||||
| 284 | 1 | ▶ | if (substr($header, 0,1 ) eq '>' ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 285 | # HINT: is FASTA? | ||||||||||||||||||||||||||||||||||||||||||
| 286 | 1 | $self->{message} .= " (might be FASTA instead)"; | |||||||||||||||||||||||||||||||||||||||||
| 287 | } | ||||||||||||||||||||||||||||||||||||||||||
| 288 | 1 | $self->{status} = 0; | |||||||||||||||||||||||||||||||||||||||||
| 289 | } | ||||||||||||||||||||||||||||||||||||||||||
| 290 | |||||||||||||||||||||||||||||||||||||||||||
| 291 | 6 | return $seq_object; | |||||||||||||||||||||||||||||||||||||||||
| 292 | } | ||||||||||||||||||||||||||||||||||||||||||
| 293 | |||||||||||||||||||||||||||||||||||||||||||
| 294 | |||||||||||||||||||||||||||||||||||||||||||
| 295 | 16 | ▶ | sub getIlluminaRead { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
getIlluminaRead: called CC=15 SCAR=30.6
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 296 | 16 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 297 | 16 | my $seq_object = undef; | |||||||||||||||||||||||||||||||||||||||||
| 298 | |||||||||||||||||||||||||||||||||||||||||||
| 299 | 16 | ▶ | return if (defined $self->{status} and $self->{status} == 0); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $self->{"status"} and $self->{"status"} == 0
MC/DC0%0/2
defined $self->{"status"} and $self->{"status"} == 0
defined $self->{"status"}
$self->{"status"} == 0
Truth table66%2/3
A and B
A= defined $self->{"status"}B= $self->{"status"} == 0
| |||||||||||||||||||||||||||||||||||||||||||
| 300 | |||||||||||||||||||||||||||||||||||||||||||
| 301 | 16 | $self->{status} = 1; | |||||||||||||||||||||||||||||||||||||||||
| 302 | 16 | my $header = readline($self->{fh}); | |||||||||||||||||||||||||||||||||||||||||
| 303 | 16 | my $seq = readline($self->{fh}); | |||||||||||||||||||||||||||||||||||||||||
| 304 | 16 | my $check = readline($self->{fh}); | |||||||||||||||||||||||||||||||||||||||||
| 305 | 16 | my $qual = readline($self->{fh}); | |||||||||||||||||||||||||||||||||||||||||
| 306 | |||||||||||||||||||||||||||||||||||||||||||
| 307 | |||||||||||||||||||||||||||||||||||||||||||
| 308 | # Check 4 lines were found (FASTQ) | ||||||||||||||||||||||||||||||||||||||||||
| 309 | |||||||||||||||||||||||||||||||||||||||||||
| 310 | 16 | ▶ | unless (defined $qual) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 311 | 2 | ▶ | if (defined $header) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 312 | 0 | $self->{message} = "Unknown format: FASTQ truncated at " . $header . "?"; | |||||||||||||||||||||||||||||||||||||||||
| 313 | 0 | $self->{status} = 0; | |||||||||||||||||||||||||||||||||||||||||
| 314 | } | ||||||||||||||||||||||||||||||||||||||||||
| 315 | 2 | return; | |||||||||||||||||||||||||||||||||||||||||
| 316 | } | ||||||||||||||||||||||||||||||||||||||||||
| 317 | |||||||||||||||||||||||||||||||||||||||||||
| 318 | # Fast format control: header and separator | ||||||||||||||||||||||||||||||||||||||||||
| 319 | 14 | ▶ | if ( (substr($header, 0, 1) eq '@') and (substr($check, 0, 1) eq '+') ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
substr($header, 0, 1) eq "\@" and substr($check, 0, 1) eq "+"
MC/DC0%0/2
substr($header, 0, 1) eq "\@" and substr($check, 0, 1) eq "+"
substr($header, 0, 1) eq "\@"
substr($check, 0, 1) eq "+"
Truth table33%1/3
A and B
A= substr($header, 0, 1) eq "\@"B= substr($check, 0, 1) eq "+"
| |||||||||||||||||||||||||||||||||||||||||||
| 320 | 14 | chomp($header); | |||||||||||||||||||||||||||||||||||||||||
| 321 | 14 | chomp($seq); | |||||||||||||||||||||||||||||||||||||||||
| 322 | 14 | chomp($qual); | |||||||||||||||||||||||||||||||||||||||||
| 323 | # Also control sequence integrity | ||||||||||||||||||||||||||||||||||||||||||
| 324 | 14 | ▶ | if ($seq=~/^[ACGTNacgtn]+$/ and length($seq) == length($qual) ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$seq =~ /^[ACGTNacgtn]+$/u and length $seq == length $qual
MC/DC0%0/2
$seq =~ /^[ACGTNacgtn]+$/u and length $seq == length $qual
$seq =~ /^[ACGTNacgtn]+$/u
length $seq == length $qual
Truth table33%1/3
A and B
A= $seq =~ /^[ACGTNacgtn]+$/uB= length $seq == length $qual
| |||||||||||||||||||||||||||||||||||||||||||
| 325 | 14 | my ($name, $comments) = split /\s+/, substr($header, 1); | |||||||||||||||||||||||||||||||||||||||||
| 326 | #@<instrument>:<run number>:<flowcell ID>:<lane>:<tile>:<x-pos>:<y-pos>:<UMI> <read>:<is filtered>:<control number>:<index> | ||||||||||||||||||||||||||||||||||||||||||
| 327 | 14 | my ($instrument, $run, $flowcell, $lane, $tile, $x, $y, $umi) = split /:/, $name; | |||||||||||||||||||||||||||||||||||||||||
| 328 | 14 | my ($read, $filtered, $ctrl, $index1, $index2); | |||||||||||||||||||||||||||||||||||||||||
| 329 | |||||||||||||||||||||||||||||||||||||||||||
| 330 | 14 | ▶ | if (not defined $y) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 331 | 0 | $self->{message} = "Unknown format: not Illumina naming: <instrument>:<run number>:<flowcell ID>:<lane>:<tile>:<x-pos>:<y-pos>"; | |||||||||||||||||||||||||||||||||||||||||
| 332 | 0 | $self->{status} = 0; | |||||||||||||||||||||||||||||||||||||||||
| 333 | } | ||||||||||||||||||||||||||||||||||||||||||
| 334 | |||||||||||||||||||||||||||||||||||||||||||
| 335 | 14 | $seq_object->{name} = $name; | |||||||||||||||||||||||||||||||||||||||||
| 336 | 14 | $seq_object->{comments} = $comments; | |||||||||||||||||||||||||||||||||||||||||
| 337 | 14 | $seq_object->{seq} = $seq; | |||||||||||||||||||||||||||||||||||||||||
| 338 | 14 | $seq_object->{qual} = $qual; | |||||||||||||||||||||||||||||||||||||||||
| 339 | |||||||||||||||||||||||||||||||||||||||||||
| 340 | 14 | $seq_object->{instrument} = $instrument; | |||||||||||||||||||||||||||||||||||||||||
| 341 | 14 | $seq_object->{run} = $run; | |||||||||||||||||||||||||||||||||||||||||
| 342 | 14 | $seq_object->{flowcell} = $flowcell; | |||||||||||||||||||||||||||||||||||||||||
| 343 | 14 | $seq_object->{lane} = $lane; | |||||||||||||||||||||||||||||||||||||||||
| 344 | 14 | $seq_object->{tile} = $tile; | |||||||||||||||||||||||||||||||||||||||||
| 345 | 14 | $seq_object->{x} = $x; | |||||||||||||||||||||||||||||||||||||||||
| 346 | 14 | $seq_object->{y} = $y; | |||||||||||||||||||||||||||||||||||||||||
| 347 | 14 | $seq_object->{umi} = $umi; | |||||||||||||||||||||||||||||||||||||||||
| 348 | 14 | $seq_object->{instrument} = $instrument; | |||||||||||||||||||||||||||||||||||||||||
| 349 | 14 | $seq_object->{run} = $run; | |||||||||||||||||||||||||||||||||||||||||
| 350 | 14 | $seq_object->{flowcell} = $flowcell; | |||||||||||||||||||||||||||||||||||||||||
| 351 | |||||||||||||||||||||||||||||||||||||||||||
| 352 | 14 | ▶ | if (defined $comments) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 353 | 7 | ($read, $filtered, $ctrl, $index1, $index2) = split /[:+]/, $comments; | |||||||||||||||||||||||||||||||||||||||||
| 354 | 7 | ▶ | if ( defined $ctrl ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 355 | 7 | $seq_object->{read} = $read; | |||||||||||||||||||||||||||||||||||||||||
| 356 | 7 | ▶ | $filtered eq 'N' ? $seq_object->{filtered} = 0 : $seq_object->{filtered} = 1; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 357 | 7 | $seq_object->{control} = $ctrl; | |||||||||||||||||||||||||||||||||||||||||
| 358 | 7 | ▶ | if ($read eq '1') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 359 | 7 | $seq_object->{index} = $index1; | |||||||||||||||||||||||||||||||||||||||||
| 360 | 7 | $seq_object->{paired_index} = $index2; | |||||||||||||||||||||||||||||||||||||||||
| 361 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 362 | 0 | $seq_object->{paired_index} = $index1; | |||||||||||||||||||||||||||||||||||||||||
| 363 | 0 | $seq_object->{index} = $index2; | |||||||||||||||||||||||||||||||||||||||||
| 364 | } | ||||||||||||||||||||||||||||||||||||||||||
| 365 | } | ||||||||||||||||||||||||||||||||||||||||||
| 366 | } | ||||||||||||||||||||||||||||||||||||||||||
| 367 | 14 | $self->{counter}++; | |||||||||||||||||||||||||||||||||||||||||
| 368 | |||||||||||||||||||||||||||||||||||||||||||
| 369 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 370 | # Return error (corrupted FASTQ) | ||||||||||||||||||||||||||||||||||||||||||
| 371 | 0 | $self->{message} = "Unknown format: expecting FASTQ (corrupted?)"; | |||||||||||||||||||||||||||||||||||||||||
| 372 | 0 | $self->{status} = 0; | |||||||||||||||||||||||||||||||||||||||||
| 373 | |||||||||||||||||||||||||||||||||||||||||||
| 374 | } | ||||||||||||||||||||||||||||||||||||||||||
| 375 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 376 | # Return error (not a FASTQ) | ||||||||||||||||||||||||||||||||||||||||||
| 377 | 0 | $self->{message} = "Unknown format: expecting FASTQ but @ header not found"; | |||||||||||||||||||||||||||||||||||||||||
| 378 | |||||||||||||||||||||||||||||||||||||||||||
| 379 | 0 | ▶ | if (substr($header, 0,1 ) eq '>' ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 380 | # HINT: is FASTA? | ||||||||||||||||||||||||||||||||||||||||||
| 381 | 0 | $self->{message} .= " (might be FASTA instead)"; | |||||||||||||||||||||||||||||||||||||||||
| 382 | } | ||||||||||||||||||||||||||||||||||||||||||
| 383 | 0 | $self->{status} = 0; | |||||||||||||||||||||||||||||||||||||||||
| 384 | } | ||||||||||||||||||||||||||||||||||||||||||
| 385 | |||||||||||||||||||||||||||||||||||||||||||
| 386 | 14 | return $seq_object; | |||||||||||||||||||||||||||||||||||||||||
| 387 | } | ||||||||||||||||||||||||||||||||||||||||||
| 388 | |||||||||||||||||||||||||||||||||||||||||||
| 389 | 4 | ▶ | sub getFileFormat { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
getFileFormat: called CC=10 SCAR=26.4
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 390 | 4 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 391 | 4 | my ($filename) = shift; | |||||||||||||||||||||||||||||||||||||||||
| 392 | 4 | ▶ | return 0 if (not defined $filename); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 393 | |||||||||||||||||||||||||||||||||||||||||||
| 394 | 4 | ▶ | open my $fh, '<', $filename or confess "Unable to read file ", $filename, "\n"; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 395 | 4 | read( $fh, my $magic_byte, 4 ); | |||||||||||||||||||||||||||||||||||||||||
| 396 | 4 | close $fh; | |||||||||||||||||||||||||||||||||||||||||
| 397 | |||||||||||||||||||||||||||||||||||||||||||
| 398 | 4 | ▶ | if (substr($magic_byte,0,3) eq GZIP_SIGNATURE) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 399 | # GZIPPED FILE | ||||||||||||||||||||||||||||||||||||||||||
| 400 | 0 | ▶ | if (! defined $self->{GZIP_BIN}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 401 | 0 | require IO::Uncompress::Gunzip; | |||||||||||||||||||||||||||||||||||||||||
| 402 | 0 | $fh = IO::Uncompress::Gunzip->new($filename, MultiStream => 1); | |||||||||||||||||||||||||||||||||||||||||
| 403 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 404 | 0 | ▶ | open $fh, '-|', "$self->{GZIP_BIN} -dc $filename" or confess "Error opening gzip file ", $filename, ": $!\n"; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 405 | } | ||||||||||||||||||||||||||||||||||||||||||
| 406 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 407 | # NOT COMPRESSED | ||||||||||||||||||||||||||||||||||||||||||
| 408 | 4 | ▶ | open $fh, '<:encoding(utf8)', "$filename" || confess "Unable to read $filename\n$!\n"; | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
"$filename" || confess("Unable to read $filename\n$!\n")
MC/DC0%0/1
"$filename" || confess("Unable to read $filename\n$!\n")
"$filename"
Truth table50%1/2
A
A= "$filename"
| |||||||||||||||||||||||||||||||||||||||||||
| 409 | } | ||||||||||||||||||||||||||||||||||||||||||
| 410 | 4 | my $first = readline($fh); | |||||||||||||||||||||||||||||||||||||||||
| 411 | 4 | ▶ | if (substr($first, 0,1) eq '>') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 412 | #should be FASTA | ||||||||||||||||||||||||||||||||||||||||||
| 413 | 1 | return 'fasta'; | |||||||||||||||||||||||||||||||||||||||||
| 414 | } elsif (substr($first, 0, 1) eq '@') { | ||||||||||||||||||||||||||||||||||||||||||
| 415 | #should be fastq | ||||||||||||||||||||||||||||||||||||||||||
| 416 | 2 | readline($fh); | |||||||||||||||||||||||||||||||||||||||||
| 417 | 2 | my $sep = readline($fh); | |||||||||||||||||||||||||||||||||||||||||
| 418 | 2 | ▶ | if ( substr($sep, 0, 1) eq '+' ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 419 | #second check for fastq | ||||||||||||||||||||||||||||||||||||||||||
| 420 | 2 | return 'fastq'; | |||||||||||||||||||||||||||||||||||||||||
| 421 | } | ||||||||||||||||||||||||||||||||||||||||||
| 422 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 423 | #unknown format | ||||||||||||||||||||||||||||||||||||||||||
| 424 | 1 | return; | |||||||||||||||||||||||||||||||||||||||||
| 425 | } | ||||||||||||||||||||||||||||||||||||||||||
| 426 | } | ||||||||||||||||||||||||||||||||||||||||||
| 427 | 6 | ▶ | sub _load_seqs { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_load_seqs: called CC=5 SCAR=16.1
| |||||||||||||||||||||||||||||||||||||||||||
| 428 | 6 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 429 | 6 | ▶ | return 0 unless (defined $self->{loadseqs}); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 430 | |||||||||||||||||||||||||||||||||||||||||||
| 431 | 6 | my $seqs = undef; | |||||||||||||||||||||||||||||||||||||||||
| 432 | 6 | ▶ | while (my $s = $self->getRead() ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 433 | 22 | my ($name, $seq) = ($s->{name}, $s->{seq}); | |||||||||||||||||||||||||||||||||||||||||
| 434 | 22 | ▶ | if ($self->{loadseqs} eq 'name') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 435 | 12 | $seqs->{$name} = $seq; | |||||||||||||||||||||||||||||||||||||||||
| 436 | } elsif ($self->{loadseqs} eq 'seq') { | ||||||||||||||||||||||||||||||||||||||||||
| 437 | 3 | $seqs->{$seq} = $name; | |||||||||||||||||||||||||||||||||||||||||
| 438 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 439 | my $r = FASTX::Seq->new( | ||||||||||||||||||||||||||||||||||||||||||
| 440 | -name => $name, | ||||||||||||||||||||||||||||||||||||||||||
| 441 | -seq => $seq, | ||||||||||||||||||||||||||||||||||||||||||
| 442 | -comment => $s->{comments}, | ||||||||||||||||||||||||||||||||||||||||||
| 443 | -qual => $s->{qual}, | ||||||||||||||||||||||||||||||||||||||||||
| 444 | 7 | ); | |||||||||||||||||||||||||||||||||||||||||
| 445 | 7 | push(@{$seqs}, $r); | |||||||||||||||||||||||||||||||||||||||||
| 446 | } | ||||||||||||||||||||||||||||||||||||||||||
| 447 | |||||||||||||||||||||||||||||||||||||||||||
| 448 | } | ||||||||||||||||||||||||||||||||||||||||||
| 449 | 6 | $self->{seqs} = $seqs; | |||||||||||||||||||||||||||||||||||||||||
| 450 | } | ||||||||||||||||||||||||||||||||||||||||||
| 451 | |||||||||||||||||||||||||||||||||||||||||||
| 452 | |||||||||||||||||||||||||||||||||||||||||||
| 453 | 33 | ▶ | sub _which { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_which: called CC=8 SCAR=30.1
| |||||||||||||||||||||||||||||||||||||||||||
| 454 | 33 | ▶ | return if ($^O eq 'MSWin32'); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 455 | 33 | my $has_which = eval { require File::Which; File::Which->import(); 1}; | |||||||||||||||||||||||||||||||||||||||||
| 456 | 33 | ▶ | if ($has_which) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 457 | 33 | foreach my $cmd (@_) { | |||||||||||||||||||||||||||||||||||||||||
| 458 | 33 | ▶ | return which($cmd) if (which($cmd)); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 459 | } | ||||||||||||||||||||||||||||||||||||||||||
| 460 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 461 | 0 | foreach my $cmd (@_) { | |||||||||||||||||||||||||||||||||||||||||
| 462 | 0 | my $exit; | |||||||||||||||||||||||||||||||||||||||||
| 463 | 0 | eval { | |||||||||||||||||||||||||||||||||||||||||
| 464 | 0 | `which $cmd 2> /dev/null`; | |||||||||||||||||||||||||||||||||||||||||
| 465 | 0 | $exit = $?; | |||||||||||||||||||||||||||||||||||||||||
| 466 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 467 | 0 | ▶ | return $cmd if ($exit == 0 and not $@); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$exit == 0 and not $@
MC/DC0%0/2
$exit == 0 and not $@
$exit == 0
not $@
Truth table0%0/3
A and not(B)
A= $exit == 0B= not $@
| |||||||||||||||||||||||||||||||||||||||||||
| 468 | } | ||||||||||||||||||||||||||||||||||||||||||
| 469 | } | ||||||||||||||||||||||||||||||||||||||||||
| 470 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||
| 471 | } | ||||||||||||||||||||||||||||||||||||||||||
| 472 | 39 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 473 | |||||||||||||||||||||||||||||||||||||||||||
| 474 | __END__ | ||||||||||||||||||||||||||||||||||||||||||