-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcat_fq_shell.pl
executable file
·60 lines (48 loc) · 2.17 KB
/
cat_fq_shell.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
#!/usr/bin/perl -w
use strict;
use File::Spec;
#combines all the fq files in one directory
#provide the direcotry name
## for multiple directories try this:
## for i in `ls` ; do cat_fq_shell.pl $i prefix; done
## updated 03/31/2012: changed the output files from _1.fq to _p1.fq and _2.fq to _p2.fq
if (!defined @ARGV){
die "run command like this: for i in `ls` ; do cat_fq_shell.pl \$i prefix [/tmp_dir default:/sractch] [clean 1|0 default:1]; done\n";
}
my $dir = shift;
my $prefix = shift;
my $tempDir = shift;
my $clean = shift;
$prefix = !defined $prefix ? '' : $prefix . '.';
$clean = !defined $clean ? 1 : 0;
my $dir_path = File::Spec->rel2abs($dir);
$tempDir = defined $tempDir ? $tempDir : '/scratch';
my $current = File::Spec->curdir();
my $current_dir = File::Spec->rel2abs($current);
my @dirs = split '/' , $dir_path;
my $lowest_dir = pop @dirs;
my $one_up = join '/' , @dirs;
open SH, ">$current_dir/$lowest_dir.cat_fq.sh";
print SH "#!/bin/bash\n\n";
print SH "echo mktemp\n";
print SH "tmp_dir=`mktemp --tmpdir=$tempDir -d`\n";
print SH "echo \"tmp_dir=\$tmp_dir\"\n";
print SH "cd \$tmp_dir\n";
my $mate_1 = "$lowest_dir"."_p1.fq" ;
my $mate_2 = "$lowest_dir"."_p2.fq" ;
my $unpaired = "$lowest_dir".".unPaired.fq";
print SH "cat $dir_path/*_p1.fq > \$tmp_dir/$mate_1\n";
print SH "cat $dir_path/*_p2.fq > \$tmp_dir/$mate_2\n";
print SH "if [ -s $dir_path/$unpaired ] ; then cat $dir_path/*unPaired.fq > \$tmp_dir/$unpaired.tmp ; fi\n";
#print SH "cat $dir_path/*unPaired.fq > \$tmp_dir/$unpaired.tmp\n";
if ($clean){
print SH "clean_pairs.pl -1 \$tmp_dir/$mate_1 -2 \$tmp_dir/$mate_2 > \$tmp_dir/$unpaired.tmp2\n";
print SH "if [ -e \$tmp_dir/$unpaired.tmp ] ; then cat \$tmp_dir/$unpaired.tmp \$tmp_dir/$unpaired.tmp2 > \$tmp_dir/$unpaired ; else mv \$tmp_dir/$unpaired.tmp2 \$tmp_dir/$unpaired ; fi\n";
$mate_1 = "$lowest_dir"."_p1.matched.fq";
$mate_2 = "$lowest_dir"."_p2.matched.fq";
}
print SH "cp \$tmp_dir/$mate_1 $one_up/$prefix$mate_1\n";
print SH "cp \$tmp_dir/$mate_2 $one_up/$prefix$mate_2\n";
print SH "if [ -s \$tmp_dir/$unpaired ] ; then cp \$tmp_dir/$unpaired $one_up/$prefix$unpaired ; fi\n";
print SH "cd $current_dir\n";
print SH "rm -rf \$tmp_dir\n";