Skip to content

Commit 7558abf

Browse files
Shriram BhosleShriram Bhosle
authored andcommitted
Merge branch 'release/2.2.0'
2 parents 0aafca4 + 9320d2b commit 7558abf

File tree

2 files changed

+31
-17
lines changed

2 files changed

+31
-17
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
### 2.2.0
2+
* Added option to include mapped reads whose mate is unmapped, removes tmp folder
13
### 2.1.0
24
* Added generic PathogenDetection wrapper for GOTTCHA
35

runPathogenDetection.pl

Lines changed: 29 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
##########LICENCE##############################################################
2222
BEGIN {
2323
use Cwd qw(abs_path);
24-
use File::Basename;
2524
$SIG{__WARN__} = sub {warn $_[0] unless(( $_[0] =~ m/^Subroutine Tabix.* redefined/) || ($_[0] =~ m/^Use of uninitialized value \$buf/))};
2625
};
2726

@@ -31,7 +30,7 @@ BEGIN
3130
use Const::Fast qw(const);
3231
use Getopt::Long;
3332
use Try::Tiny qw(try catch finally);
34-
use File::Path qw(mkpath);
33+
use File::Path qw(mkpath remove_tree);
3534
use Capture::Tiny qw(:all);
3635

3736
const my $gottcha_path => qw(/software/CGP/external-apps/GOTTCHA/bin);
@@ -43,24 +42,28 @@ BEGIN
4342
try {
4443
my ($options) = option_builder();
4544
my $cmd=undef;
46-
47-
if(defined $options->{'i'} && lc($options->{'i'}) eq 'y' ) {
45+
my $unapped_fastq="$options->{'o'}/tmp/unmapped.fastq";
46+
if(defined $options->{'i'} && lc($options->{'i'}) eq 'y' && !defined $options->{'u'}) {
4847
print "Feteching all unmapped reads and their mates ......\n";
4948
#unmapped read whose mate is mapped
50-
$cmd="samtools view -f 4 -F264 $options->{'bam'} | awk \'$awk_cmd\' >$options->{'o'}/tmp/unmapped.fastq";
49+
$cmd="samtools view -f 4 -F264 $options->{'bam'} | awk \'$awk_cmd\' >$unapped_fastq";
5150
_run_cmd($cmd);
5251
#mapped read whose mate is unmapped
53-
$cmd="samtools view -f 8 -F260 $options->{'bam'} | awk \'$awk_cmd\' >>$options->{'o'}/tmp/unmapped.fastq";
52+
$cmd="samtools view -f 8 -F260 $options->{'bam'} | awk \'$awk_cmd\' >>$unapped_fastq";
5453
_run_cmd($cmd);
5554
#Both reads unmapped
56-
my $cmd="samtools view -f 12 -F256 $options->{'bam'} | awk \'$awk_cmd\' >>$options->{'o'}/tmp/unmapped.fastq";
55+
my $cmd="samtools view -f 12 -F256 $options->{'bam'} | awk \'$awk_cmd\' >>$unapped_fastq";
5756
_run_cmd($cmd);
58-
}else {
57+
}elsif(!defined $options->{'i'} && !defined $options->{'u'}) {
5958
print "Feteching only unmapped reads ......\n";
6059
$cmd="samtools view -f 4 $options->{'bam'} | awk \'$awk_cmd\' >$options->{'o'}/tmp/unmapped.fastq";
6160
_run_cmd($cmd);
6261
}
63-
print "Running detection for : $options->{'t'} .....\n";
62+
else{
63+
$unapped_fastq=$options->{'u'};
64+
}
65+
print "Running detection for : $options->{'t'} .....\n" if(!defined $options->{'d'});
66+
6467
my $gottcha_db = $VIRUSES;
6568
if($options->{'t'} eq 'BACTERIA'){
6669
$gottcha_db=$BACTERIA;
@@ -71,13 +74,13 @@ BEGIN
7174
}
7275

7376
$cmd = "$gottcha_path/gottcha.pl --threads $options->{'n'} --mode summary --minQ 10 --outdir $options->{'o'} ".
74-
" --input $options->{'o'}/tmp/unmapped.fastq".
77+
" --input $unapped_fastq".
7578
" --noPlasmidHit ".
7679
" --database $gottcha_db";
7780
# run command
7881
_run_cmd($cmd) if(defined $cmd);
79-
80-
print "\nCompleted virus detection using GOTTCHA.....\nCheck result file unmapped.gottcha.tsv .... \n";
82+
print "\nCompleted virus detection using GOTTCHA.....\nCheck result file <unmapped_file_name>.gottcha.tsv .... \n";
83+
remove_tree("$options->{'o'}/tmp") if($options->{'r'} && -d "$options->{'o'}/tmp" );
8184
}
8285
catch {
8386
print "$_";
@@ -93,7 +96,9 @@ sub option_builder {
9396
'i|includeMate=s' => \$opts{'i'},
9497
't|analysisType=s' => \$opts{'t'},
9598
'd|userDb=s' => \$opts{'d'},
99+
'u|unmappedFastq=s' => \$opts{'u'},
96100
'n|numCpu=i' => \$opts{'n'},
101+
'r|removeTmp=i' => \$opts{'r'},
97102
'o|outdir=s' => \$opts{'o'},
98103
);
99104

@@ -103,14 +108,17 @@ sub option_builder {
103108
}
104109
if(!defined $opts{'n'}) {
105110
$opts{'n'}=1;
111+
}
112+
if(!defined $opts{'r'}) {
113+
$opts{'r'}=1;
106114
}
107115
if(uc($opts{'t'}) ne 'VIRUSES' && uc($opts{'t'}) ne 'BACTERIA') {
108116
print "\nAnalysis type doesn't match with VIRUS or BACTERIA\n";
109117
}
110118
if(defined $opts{'o'}) {
111119
mkpath("$opts{'o'}/tmp");
112120
}
113-
pod2usage(q{'-bam' bam file must be specified.}) unless(defined $opts{'bam'}) ;
121+
pod2usage(q{'-bam' bam or (-u) fastq file must be specified.}) unless(defined $opts{'bam'} || defined $opts{'u'}) ;
114122
pod2usage(q{'-t' analysis type[VIRUSES,BACTERIA:default VIRUSES].}) unless(defined $opts{'t'});
115123
pod2usage(q{'-n' number of threads }) unless(defined $opts{'n'});
116124
pod2usage(q{'-o' output location must be specified}) unless(defined $opts{'o'});
@@ -144,19 +152,23 @@ =head1 NAME
144152
145153
=head1 SYNOPSIS
146154
147-
runPathogenDetection.pl -bam -o [-i -t -d -n -h ]
155+
runPathogenDetection.pl -bam -o [-i -t -d -u -n -h ]
148156
149157
Required Options (bam and outdir must be defined):
150158
151-
--sampleBam (-bam) sample bam file
159+
--sampleBam (-bam) sample bam file [Optional if unmappedFastq file is provided]
160+
--unmappedFastq (-u) User defined unmapped fastq reads file [Optional if bam file is provided].
152161
--outdir (-o) outdir [ Path to output directory ]
153162
Optional:
154163
155-
--includeMate (-i) include mate sequence of unmapped read [Y,N:default N], an option to include/exclude mapped mate of an unmapped read, takes more time to fetch the reads
164+
--includeMate (-i) include mate sequence of unmapped read [Y,N:default N],
165+
an option to include/exclude mapped mate of an unmapped read,
166+
more sensitive with mapped mate included
156167
--databaseType (-t) databaseType [VIRUSES,BACTERIA:default VIRUSES]
157168
--userDb (-d) The path of signature database. The database can be
158169
in FASTA format or BWA index (5 files).
159-
--numCpu (-n) fasta reference genome file
170+
--removeTmp (-r) remove tmp folder [1,0:default 1]
171+
--numCpu (-n) number of cpu
160172
--help (-h) This message
161173
Example:
162174
perl runPathogenDetection.pl -bam test.bam -o testdir

0 commit comments

Comments
 (0)