-
Notifications
You must be signed in to change notification settings - Fork 2
/
fqFormater.pl
executable file
·77 lines (71 loc) · 1.95 KB
/
fqFormater.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
68
69
70
71
72
73
74
75
76
77
#!/bin/env perl
=hey
Author: Shijian Sky Zhang
E-mail: [email protected]
=cut
use strict;
use 5.010;
use Getopt::Long;
use File::Basename;
use lib (fileparse($0))[1];
use pm::common;
my ($tab, $fastq, $keyword, $piece);
my ($width)=(100);
sub usage{
my $scriptName = basename $0;
print <<HELP;
Usage: perl $scriptName -t INPUT.fq(.gz) >OUTPUT.tsv
perl $scriptName -f INPUT.tsv >OUTPUT.fq
if INPUT not specified, input from STDIN
-t --tab Transform the fasta format to tab format (name, title, seq in each column)
-f --fastq Transform the tab format to fastq format
-k --keyword STR Extract sequence with title containing --keyword
-p --piece STR Extract sequence with --piece as sub-sequence
-h --help Print this help information
HELP
exit(-1);
}
GetOptions(
't|tab' => \$tab,
'f|fastq' => \$fastq,
'k|keyword=s' => \$keyword,
'p|piece=s' => \$piece,
'h|help' => sub{\&usage()}
)||usage();
if(defined $ARGV[0]){
if(`file -L $ARGV[0]` =~ /gzip/){
open IN,"gzip -dc $ARGV[0]|" or die "Can't open $ARGV[0]: $!";
}else{
open IN,"$ARGV[0]" or die "Can't open $ARGV[0]: $!";
}
}else{
open IN, "-";
}
if(defined $tab){
while(<IN>){
chomp;
my $title = $_;
chomp(my $seq = <IN>);
<IN>;
chomp(my $qual = <IN>);
if (defined $keyword && $title !~ /$keyword/ || defined $piece && $seq !~ /$piece/){
next;
}
my $name = $title;
$name =~ s/^@//;
say join "\t",($name, $title, $seq, $qual);
}
}
if(defined $fastq){
while(<IN>){
chomp;
my ($name, $title, $seq, $qual) = split "\t";
if (defined $keyword && $title !~ /$keyword/ || defined $piece && $seq !~ /$piece/){
next;
}
say $title;
say $seq;
say "+";
say $qual;
}
}