Skip to content

Commit

Permalink
Add error checking when shelling out (#15)
Browse files Browse the repository at this point in the history
  • Loading branch information
adthrasher authored May 27, 2020
1 parent 57485b9 commit d469af3
Show file tree
Hide file tree
Showing 5 changed files with 99 additions and 11 deletions.
15 changes: 12 additions & 3 deletions src/bin/Cicero.pl
Original file line number Diff line number Diff line change
Expand Up @@ -166,9 +166,18 @@

my $sam_d = Bio::DB::Sam->new( -bam => $input_bam, -fasta => $ref_genome);

system("touch $out_dir/unfiltered.fusion.txt");
system("touch $out_dir/unfiltered.internal.txt");

my $ret = system("touch $out_dir/unfiltered.fusion.txt");
if ($ret){
my $err = $!;
print STDERR "Error sorting blat output: $err\n";
exit $err;
}
$ret = system("touch $out_dir/unfiltered.internal.txt");
if ($ret){
my $err = $!;
print STDERR "Error sorting blat output: $err\n";
exit $err;
}
# the softclip file is sorted, so no need to re-sort it
open my $SCLIP, "<$sclip_file" or croak "can't open $sclip_file:$OS_ERROR";
while( my $line = <$SCLIP> ) {
Expand Down
51 changes: 47 additions & 4 deletions src/bin/annotate.pl
Original file line number Diff line number Diff line change
Expand Up @@ -156,10 +156,24 @@
my $unfiltered_file = "$out_dir/unfiltered.fusion.txt";
if($internal) {
$unfiltered_file = "$out_dir/unfiltered.internal.txt";
`cat $out_dir/*/unfiltered.internal.txt > $unfiltered_file` unless(-s $unfiltered_file);
unless (-s $unfiltered_file){
`cat $out_dir/*/unfiltered.internal.txt > $unfiltered_file`;
if ($?){
my $err = $!;
print STDERR "Error combining internal events: $err\n";
exit $err;
}
}
}
else{
`cat $out_dir/*/unfiltered.fusion.txt > $unfiltered_file` unless(-s $unfiltered_file);
unless (-s $unfiltered_file){
`cat $out_dir/*/unfiltered.fusion.txt > $unfiltered_file`;
if ($?){
my $err = $!;
print STDERR "Error combining fusion events: $err\n";
exit $err;
}
}
}
print "Unfiltered fusions file: $unfiltered_file\n";

Expand Down Expand Up @@ -561,8 +575,18 @@ sub is_bad_fusion{

print STDERR "out file is: $out_file\nnumber of SVs: ", scalar @raw_SVs, "\n" if($debug);
`mkdir -p $out_dir/tmp_anno`;
if ($?){
my $err = $!;
print STDERR "Error creating annotation directory: $err\n";
exit $err;
}
my $annotation_dir = tempdir(DIR => "$out_dir/tmp_anno");
`mkdir -p $annotation_dir`;
if ($?){
my $err = $!;
print STDERR "Error creating temp directory for annotation: $err\n";
exit $err;
}
print STDERR "Annotation Dir: $annotation_dir\n" if($debug);

print STDERR "Reading cover files\n";
Expand Down Expand Up @@ -1222,6 +1246,11 @@ sub quantification {
$arg .= " $fa_file2 " if (-f $fa_file2 && -s $fa_file2);
if ($arg ne ""){
`cat $arg >> $fa_file`;
if ($?){
my $err = $!;
print STDERR "Error creating fasta file: $err\n";
exit $err;
}
}
#`cat $fa_file1 >> $fa_file` if(-f $fa_file1 && -s $fa_file1);
#`cat $fa_file2 >> $fa_file` if(-f $fa_file2 && -s $fa_file2);
Expand Down Expand Up @@ -1283,8 +1312,22 @@ sub quantification {
my ($psl_file1, $psl_file2) = ("$anno_dir/bp1.psl", "$anno_dir/bp2.psl",);

unlink $psl_file1 if(-f $psl_file1); unlink $psl_file2 if(-f $psl_file2);
`blat -noHead -maxIntron=5 $tmp_ctg_file $fa_file1 $psl_file1` if(-s $fa_file1);
`blat -noHead -maxIntron=5 $tmp_ctg_file $fa_file2 $psl_file2` if(-s $fa_file2);
if (-s $fa_file1){
`blat -noHead -maxIntron=5 $tmp_ctg_file $fa_file1 $psl_file1`;
if ($?){
my $err = $!;
print STDERR "Error running blat: $err\n";
exit $err;
}
}
if (-s $fa_file2){
`blat -noHead -maxIntron=5 $tmp_ctg_file $fa_file2 $psl_file2`;
if ($?){
my $err = $!;
print STDERR "Error running blat: $err\n";
exit $err;
}
}
my ($readsA, $areaA, $readsB, $areaB) = (0,1,0,1);
my $shift_bases = 5;
if($chrA eq $bp1->{tname} && abs($bp1->{tpos} - $tposA)<50 &&
Expand Down
5 changes: 5 additions & 0 deletions src/bin/get_geneInfo.pl
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,11 @@
$sample=$bam_file[0] unless (defined $sample);

`mkdir -p $out_dir`;
if ($?){
my $err = $!;
print STDERR "Error creating output directory: $err\n";
exit $err;
}

my %blacklist = ();
if($blacklist_file && -s $blacklist_file){
Expand Down
7 changes: 7 additions & 0 deletions src/bin/prepareCiceroInput.pl
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,14 @@
close $GI;

my $SC_file = "$out_dir/$out_prefix.SC.txt";

`ls $out_dir/$out_prefix*.cover | xargs cat > $SC_file`;
if ($?){
my $err = $!;
print STDERR "Error combining cover files: $err\n";
exit $err;
}

print STDERR $SC_file, "\n";
open my $SCI, "$SC_file";

Expand Down
32 changes: 28 additions & 4 deletions src/perllib/CiceroExtTools.pm
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,12 @@ sub run {
print STDERR "$file is of size 0";
return;
}
system(join(" ", ($self->{PRG}, $file, $self->{OPTIONS})));
my $ret = system(join(" ", ($self->{PRG}, $file, $self->{OPTIONS})));
if ($ret){
my $err = $!;
print STDERR "Error running assembler: $err\n";
exit $err;
}
my( $r_count, $r_reads ) = _count_reads("$file.cap.ace");
return ("$file.cap.contigs", $r_count, $r_reads, "$file.cap.singlets");
}
Expand Down Expand Up @@ -152,6 +157,11 @@ sub run {
print STDERR "\ntest=$test\t", join(" ", ($self->{PRG}, $self->{BIT2_DIR}, $param{-QUERY}, $unsorted_psl, $options)), "\n" if($debug);
# Sort the output PSL file from BLAT.
`sort -k 11,11nr -k 10,10d -k 14,14d -k 1,1nr $unsorted_psl -o $psl_file`;
if ($?){
my $err = $!;
print STDERR "Error sorting blat output: $err\n";
exit $err;
}

# Instantiate a parser and load the results into an array to pass to subroutines for checks.
# A "result" is everything for a given query
Expand Down Expand Up @@ -952,6 +962,11 @@ sub overhang_remapping {

return unless(-s $unsorted_psl);
`sort -k 10,10d -k 14,14d -k 1,1nr $unsorted_psl -o $psl_file`;
if ($?){
my $err = $!;
print STDERR "Error sorting blat output: $err\n";
exit $err;
}

#print "sc site is $scSite\n";
my ($max_length, $max_percent, $total_matches) = (0, 0);
Expand Down Expand Up @@ -1640,17 +1655,26 @@ sub run {
croak "Missing QUERY parameter for $self->{PRG}" if(!$param{-QUERY});
my $output = $param{-OUTPUT} || $param{-QUERY} . ".psl";
my $opt = $self->{OPTIONS} . " -maxIntron=1 ";
system( join(" ", ($self->{PRG}, $param{-TARGET}, $param{-QUERY}, $output, $opt)));
my $ret = system( join(" ", ($self->{PRG}, $param{-TARGET}, $param{-QUERY}, $output, $opt)));
if ($ret){
my $err = $!;
print STDERR "Error running aligner: $err\n";
exit $err;
}
my $rtn = _find_best_hit($output);
if( scalar(keys(%{$rtn})) > 0) {
return $output if($param{-FILE});
return $rtn;
}
$opt = $self->{OPTIONS} . " -fastMap ";
system( join(" ", ($self->{PRG}, $param{-TARGET}, $param{-QUERY}, $output, $opt)));
my $ret = system( join(" ", ($self->{PRG}, $param{-TARGET}, $param{-QUERY}, $output, $opt)));
if ($ret){
my $err = $!;
print STDERR "Error running aligner: $err\n";
exit $err;
}
return $output if($param{-FILE});
return _find_best_hit($output);

}

sub _find_best_hit {
Expand Down

0 comments on commit d469af3

Please sign in to comment.