-
Notifications
You must be signed in to change notification settings - Fork 0
/
sra2fq.pl
52 lines (45 loc) · 1.14 KB
/
sra2fq.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
#!/usr/bin/perl -w
use warnings;
use strict;
use Getopt::Long;
use Cwd 'abs_path';
my $cwd = abs_path;
my ($file, $dir, $prefix);
GetOptions(
"f|file:s" => \$file,
"d|dir:s" => \$dir,
"p|prefix:s" => \$prefix
);
print &usage && exit if(!defined $prefix);
system "mkdir -p -m 755 $dir" unless (-d $dir);
open(IN, &OpenM($file)) or die "can't open $file\n";
open(OUT, "> $cwd/$prefix\.sh") or die "can't open outfile\n";
<IN>;
while(<IN>){
chomp;
my @tmp = split("\t", $_);
if(-e $tmp[2]){
if ($tmp[1] eq "PAIRED") {
print OUT "fastq-dump $tmp[2] -O $dir --gzip --defline-seq '\@\$sn\[_\$rn\]/\$ri' --split-files\n";
} else {
print OUT "fastq-dump $tmp[2] -O $dir --gzip --defline-seq '\@\$sn\[_\$rn\]/\$ri'\n";
}
}
}
close(IN);
close(OUT);
sub OpenM {
$_=shift;
return(($_=~/\.gz$/)?"gzip -dc $_|":"$_")
}
sub usage{
print <<USAGE;
usage:
perl $0 -f <input> -d <dir> -p <prefix>
options:
-f|file :sample path file (SampleID|mode|fqPath).
-d|outdir :output directory path. Conatins the dir.
-p|prefix :prefix of shell script.
USAGE
exit;
};