-
Notifications
You must be signed in to change notification settings - Fork 15
/
fastm2fastx.pl
executable file
·58 lines (53 loc) · 1.08 KB
/
fastm2fastx.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
#!/usr/bin/perl
use warnings;
use strict;
my $fastqMode = 0; # false
my $inQual = 0;
my $inSeq = 0;
my $seqID = "";
my $seq = "";
my $qual = "";
while(<>){
if(/^#seq(:(.*$))?/){
my $newSeqID = $2;
$inQual = 0; # false
$inSeq = 1; # true
if($seqID){
if($fastqMode){
printf("@%s\n%s+\n%s", $seqID, $seq, $qual);
} else {
printf(">%s\n%s", $seqID, $seq);
}
}
$seqID = $newSeqID;
$seq = "";
} elsif(/^#qual(:(.*$))?/){
my $newSeqID = $2;
if($newSeqID && ($newSeqID ne $seqID)){
warn(sprintf("Quality ID [%s] and sequence ID [%s] do not match.".
" Setting ID to sequence ID [%s]",
$newSeqID, $seqID, $seqID));
}
$fastqMode = 1;
$inSeq = 0; # false
$inQual = 1; # true
} elsif(/^#/){ # some other unknown tag
$inSeq = 0; # false
$inQual = 0; # false
}
if(/^ (.*$)/){
if($inSeq){
$seq .= $1 . "\n";
}
if($inQual){
$qual .= $1 . "\n";
}
}
}
if($seqID){
if($fastqMode){
printf("@%s\n%s+\n%s", $seqID, $seq, $qual);
} else {
printf(">%s\n%s", $seqID, $seq);
}
}