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