-
Notifications
You must be signed in to change notification settings - Fork 1
/
bam2sortBam.pl
58 lines (52 loc) · 1.73 KB
/
bam2sortBam.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 -w
# Bam to sort Bam with samtools in TSCC
# Run the script to the Bam directory
# Contact: Shicheng Guo
# Version 1.3
# Update: 2016-01-19
use strict;
use Cwd;
die USAGE() if scalar(@ARGV)<1;
my $dir=getcwd;
my $sort=shift @ARGV;
my $submit=shift @ARGV;
my @file=glob("$dir/*.bam");
mkdir "../sortBam" if ! -e "../sortBam";
my $ppn=6;
my $walltime="168:00:00";
my $queue="hotel"; # hotel
foreach my $file (@file){
my @tmp=split /\//,$file;
my ($sample,undef)=split /.bam/,$tmp[$#tmp];
my $job_file_name = $sample.".job";
my $status_file = $sample.".status";
my $hapInfo_file = $sample.".hapInfo.txt";
my $curr_dir = $dir;
open(OUT, ">$job_file_name") || die("Error in opening file $job_file_name.\n");
print OUT "#!/bin/csh\n";
print OUT "#PBS -N $job_file_name\n";
print OUT "#PBS -q $queue\n";
print OUT "#PBS -l nodes=1:ppn=$ppn\n";
print OUT "#PBS -l walltime=$walltime\n";
print OUT "#PBS -o ".$sample.".log\n";
print OUT "#PBS -e ".$sample.".err\n";
print OUT "#PBS -V\n";
print OUT "#PBS -M shicheng.guo\@gmail.com \n";
print OUT "#PBS -m abe\n";
print OUT "#PBS -A k4zhang-group\n";
print OUT "cd $curr_dir\n";
if($sort eq 'sortc'){
print OUT "samtools sort -@ 6 -o ../sortBam/$sample.sortc.bam $file\n";
print OUT "samtools index ../sortBam/$sample.sortc.bam\n";
}elsif($sort eq 'sortn'){
print OUT "samtools sort -n -@ 6 -o ../sortBam/$sample.sortn.bam $file\n";
print OUT "samtools index ../sortBam/$sample.sortn.bam\n";
}
if($submit eq 'submit'){
system("qsub $job_file_name");
}
}
sub USAGE{
print "\nUSAGE: perl $0 sortc|sortn submit\n\n";
print "Example: perl $0 /media/LTS/shg047/bam sortc submit\n";
}