-
Notifications
You must be signed in to change notification settings - Fork 12
/
fastq_2_fasta.pl
executable file
·67 lines (55 loc) · 1.19 KB
/
fastq_2_fasta.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#!/usr/bin/perl
# edited by Tina to print out 60 sequence chars per line
#
# This program converts Sanger formatted fastq files to fasta files
# The Sanger format encodes quality scores 0-93 as ASCII values 33-126
# It is not compatable with the Illumina fastq format.
#
use Getopt::Std;
getopt("q");
$usage = <<END;
-q [0] quality score cutoff
*** EDITED BY TINA 12.03.09
END
die $usage unless (defined $opt_q);
if ($opt_q > 0 && $opt_q <= 93) {
$opt_q += 33;
}
else {
$opt_q = 0;
}
while(<>) {
if ( /^@(\S+)/ ) { ### TINA
$id = $1;
$seq = <>;
chomp $seq;
<>;
$qual = <>;
chomp $qual;
#assert( length($seq) == length($qual) );
if ( $opt_q ) {
for ($i = 0; $i < length($qual); $i++) {
if ( ord(substr($qual, $i, 1)) < $opt_q ) {
substr($seq, $i, 1) = "N";
}
}
}
if ( $opt_m ) {
foreach ( @{ $masks{$id} } ) {
substr($seq, $_->[0]+1, $_->[1]-$_->[0]+1) = "N" x ($_->[1]-$_->[0]+1);
}
}
print ">$id\n" . &p2q_print_str(\$seq); ### TINA
}
}
exit;
sub p2q_print_str {
my ($s) = @_;
my $printout = '';
my $l = length($$s);
for (my $i = 0; $i < $l; $i += 60) {
$printout .= substr($$s, $i, 60);
$printout .= "\n";
}
return $printout;
}