/
check_split_BX.pl
57 lines (50 loc) · 1.49 KB
/
check_split_BX.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
#!/usr/bin/perl -w
use strict;
my $usage='
perl script <run folder>
<sample dir> = full path of the folder holding files for this sample
without last "/"
';
die $usage unless scalar @ARGV == 1;
my ( $dir ) = @ARGV;
if ($dir =~/(.+)\/$/) {
$dir = $1;
}
my $sample_name = (split(/\//,$dir))[-1];
#print $sample_name,"\n";
my $finished = &check_split_output($dir);
#print $finished;
exit ($finished);
########################################################################
sub check_split_output {
my ( $dir ) = @_;
my $tot_in_seq=0;
my $tot_out_seq = 0;
my $BNfiltered_File = $dir."/".$sample_name."_BLASTN_NT_Filtered.fa";
$tot_in_seq = `grep \">\" $BNfiltered_File |wc -l`;
my $BLASTX_dir = $dir."/".$sample_name."_BLASTX_NR";
opendir(DH, $BLASTX_dir) or return 10;
foreach my $file (readdir DH) {
if ($file =~ /\.fasta$/ ) {
my $faFile = $BLASTX_dir."/".$file;
my $temp = `grep \">\" $faFile |wc -l`;
$tot_out_seq += $temp;
}
}
close DH;
print "total input sequence: $tot_in_seq\n";
print "total output sequence : $tot_out_seq\n";
if($tot_in_seq==$tot_out_seq) { return 0; } # use 0 to make it consistent with Linux convention
else { # remove content of BLASTX directory, to rerun split
opendir(DH, $BLASTX_dir) or return 10;
foreach my $file (readdir DH) {
if (!($file eq ".") && !($file eq "..")) {
my $faFile = $BLASTX_dir."/".$file;
# print "$faFile\n";
unlink $faFile;
}
}
close DH;
return 10;
}
}