-
Notifications
You must be signed in to change notification settings - Fork 0
/
06addingBlast2OTUtable.pl
73 lines (72 loc) · 2.41 KB
/
06addingBlast2OTUtable.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
#!/usr/bin/perl -w
use strict;
##
##
## combing metadata.tsv and feature-table.tsv
## to make new table with seq taxonomy hirarchy and frequency table
##
##
my $ftable = '/home/thsti/metagenomicsAnalysis/16sRNA_Obese/sample_cleaned_trimmed_Qiime2Analysis/P40obese_sample_cleaned_trimmed_rename_OTUfeature-table_q17len100_filtered.tsv';
my $be2addfolder = '/home/thsti/metagenomicsAnalysis/16sRNA_Obese/sample_cleaned_trimmed_Qiime2Analysis/P40obese_sample_cleaned_trimmed_rename_OTUfeature-table_q17len100_filtered_CSTs_blastn';
my $newtable = '/home/thsti/metagenomicsAnalysis/16sRNA_Obese/sample_cleaned_trimmed_Qiime2Analysis/P40obese_sample_cleaned_trimmed_rename_OTUfeature-table_q17len100_filtered_besthit.tsv';
##
##
open(TABLE, $ftable) or die "could not open the input file $ftable, $!";
open(OUT, ">$newtable") or die "could not open the output file $newtable, $!";
while(my $ln =<TABLE>)
{
if($ln =~ /^#/)
{
if($ln =~ m/^#CST/)
{
$ln =~ s/^\s+|\s+$//;
#print $ln,"\t",'species_name',"\t",'%identity',"\t",'%queryCov',"\t",'eValue',"\n";
print OUT $ln,"\t",'species_name',"\t",'%identity',"\t",'%queryCov',"\t",'eValue',"\n";
}
}
else
{
$ln =~ s/^\s+|\s+$//;
my @lnA = split(/\t/, $ln);
my $ftureID = $lnA[0].'_'.$lnA[1];
my ($sps, $idperc, $qcovperc, $eval) = &ParsingFolder($lnA[0], $ftureID, $be2addfolder);
#print $ln,"\t",$sps,"\t",$idperc,"\t",$qcovperc,"\t",$eval,"\n";
print OUT $ln,"\t",$sps,"\t",$idperc,"\t",$qcovperc,"\t",$eval,"\n";
undef(@lnA);
}
}
close(TABLE);
close(OUT);
##
## ****************************ParsingMetaData****************************************
sub ParsingFolder
{
my($cstid, $fid, $folder) = @_;
#print $cstid,"\t",$fid,"\t",$folder,"\n";
my $sp = 'NA';
my $idper = 'NA';
my $qcv = 'NA';
my $eval = 'NA';
my $fileName = $folder.'/'.$cstid.'_blastn_besthit1';
#print $fileName, "\n";
open(FILE, $fileName) or die "could not open the input file $fileName, $!";
while(my $l = <FILE>)
{
$l =~ s/^\s+|\s+$//;
#print $l,"\n";
my @al = split(/\t/, $l);
print $al[0],"\t",$fid,"\n";
if($al[0] eq $fid)
{
$idper = $al[2];
$eval = $al[10];
$qcv = $al[12];
my @spsName = split(/ /, $al[13]);
$sp = 'g__'.$spsName[0].'; '.'s__'.$spsName[1]
}
undef(@al);
}
print $sp,"\t",$idper,"\t",$qcv,"\t",$eval,"\n";
return($sp, $idper, $qcv, $eval);
close(FILE);
}