forked from ding-lab/VirusScan
-
Notifications
You must be signed in to change notification settings - Fork 0
/
check_split_BN.pl
77 lines (72 loc) · 1.76 KB
/
check_split_BN.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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#!/usr/bin/perl -w
use strict;
my $usage='
perl script <sample dir>
<sample dir> = full path of the folder holding files for this sample
without last "/"
';
die $usage unless scalar @ARGV == 1;
my ( $dir ) = @ARGV;
my $finished = &check_split_output($dir);
#print $finished;
exit ($finished);
##############################################################
sub check_split_output {
my ( $dir ) = @_;
my $tot_BN_seq=0;
my $tot_seq = 0;
opendir(DH, $dir) or return 10;
foreach my $name (readdir DH) {
if ($name =~/\.RefGfiltered\.fa$/) {
my $RefGFile = $dir."/".$name;
open (IN, $RefGFile) or return 10;
while (my $line = <IN>){
if ($line =~ ">") {
$tot_BN_seq++;
}
}
close IN;
}
if ($name =~ /\.RefGfiltered_BLASTN$/) { # BLASTN directory
my $full_path = $dir."/".$name;
opendir(SubDH, $full_path) or return 10;
foreach my $file (readdir SubDH) {
if ($file =~ /\.fa$/ && !($file=~/\.BNfiltered\.fa/)) {
my $faFile = $full_path."/".$file;
my $count = 0;
open (IN, $faFile) or return 10;
while (my $line = <IN>){
if ($line =~ ">") {
$count++;
}
}
close IN;
$tot_seq += $count;
}
}
close SubDH;
}
}
close DH;
# print "$tot_BN_seq\n";
# print "$tot_seq\n";
if($tot_BN_seq==$tot_seq) { return 1; }
else {
opendir(DH, $dir) or return 10;
foreach my $name (readdir DH) {
# print "$name\n";
if ($name =~ /\.RefGfiltered_BLASTN$/) {
my $full_path = $dir."/".$name;
opendir(SubDH, $full_path) or return 10;
foreach my $file (readdir SubDH) {
my $faFile = $full_path."/".$file;
# print "$faFile\n";
unlink $faFile;
}
close SubDH;
}
}
close DH;
return 10;
}
}