-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path08.parse_ssu.pl
More file actions
69 lines (65 loc) · 1.42 KB
/
Copy path08.parse_ssu.pl
File metadata and controls
69 lines (65 loc) · 1.42 KB
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
#!/usr/bin/perl -w
my %tax = ();
open IN, "Bin_tax.list";
while (<IN>){
chomp;
my @tmp = split (/\t/,$_);
$tax{$tmp[0]} = $tmp[1];
}
close IN;
%out = ();
open IN, "ls checkm_result/ssu_finder/*/ssu_summary.tsv | ";
while (<IN>){
chomp;
my ($fa) = $_ =~ /ssu_finder\/(.+?)\_result/;
my $dir = $_; $dir =~ s/\/ssu_summary\.tsv//g;
my %hit = ();
open INN, "$_";
OUTTER1: while (<INN>){
chomp;
if (!/^Bin/){
my @tmp = split (/\t/,$_) or last OUTTER1;
if (uc ($tmp[2]) eq uc($tax{$fa}) and !exists $hit{$fa} ){
$hit{$fa}[0] = $tmp[1]; #scaffold id
$hit{$fa}[1] = $tmp[6]; # 16S hit length
}elsif(uc ($tmp[2]) eq uc($tax{$fa}) and exists $hit{$fa}){
if ($tmp[6] > $hit{$fa}[1]){
$hit{$fa}[0] = $tmp[1];
$hit{$fa}[1] = $tmp[6];
}
}
}
}
close INN;
if (%hit){
#Store ssu.fna
my %ssu = ();my $head = "";
open _IN, "$dir/ssu.fna" or die ;
while (<_IN>){
chomp;
if (/>/){
$head = $_;
$ssu{$head} = "";
}else{
$ssu{$head} .= $_;
}
}
close _IN;
#filter %ssu, print hit into OUT
foreach my $key (sort keys %ssu){
#print "$key\n";
my $key_new = $key;
$key_new =~ s/>//g;$key_new =~ s/$fa//;$key_new =~ s/\&\&//g;
#print "$key_new\n";
if ($key_new eq $hit{$fa}[0] and length ($ssu{$key}) >= 300){
$out{">".$fa} = $ssu{$key};
}
}
}
}
close IN;
open OUT, ">Bin_ssu.fa";
foreach my $key (sort keys %out){
print OUT "$key\n$out{$key}\n";
}
close OUT;