-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path05exractingCSTsFastaSeq20220407.pl
66 lines (66 loc) · 1.57 KB
/
05exractingCSTsFastaSeq20220407.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
#!/usr/bin/perl -w
use strict;
##
##
##
## extracting CSTs(cummunity state taxons) from combined OTUs table in fasta format
##
##
my $ftable = '/home/thsti/metagenomicsAnalysis/01BDasSir/16sRNA_Balabhgharh_analysis/16sRNA_Balabhgharh_OTUftable_combined_filtered.tsv';
my $CSTsfolder = '/home/thsti/metagenomicsAnalysis/01BDasSir/16sRNA_Balabhgharh_analysis/16sRNA_Balabhgharh_OTUftable_combined_filtered_CSTs2';
##
##
##
my %CSTids;
my $otuCol;
my $seqCol;
print '...reading the table......',"\n";
open(TABLE, $ftable) or die "could not open file $ftable, $!";
while(my $ln =<TABLE>)
{
if($ln =~ /^\#/)
{
if($ln =~ /^\#CST/)
{
#print $ln;
$ln =~ s/^\s+|\s+$//;
my @lnA = split(/\t/, $ln);
for(my $a = 0; $a<scalar(@lnA); $a++)
{
if($lnA[$a] eq '#OTU ID')
{
$otuCol = $a;
}
if($lnA[$a] eq 'sequence')
{
$seqCol = $a;
}
}
undef(@lnA);
}
next;
}
else
{
$ln =~ s/^\s+|\s+$//;
my @lnA = split(/\t/, $ln);
my $key = $lnA[0];
my $value = join("\n", $lnA[$otuCol], $lnA[$seqCol]);
push(@{$CSTids{$key}},$value);
undef(@lnA);
}
}
close(TABLE);
print '..segregating OTUs according to Cummunity State Taxs(CSTs)...',"\n";
foreach my $eachCSTs (keys%CSTids)
{
my $CSTsfile = $CSTsfolder.'/'.$eachCSTs.'.fasta';
open(OUT,">$CSTsfile") or die "could not open file $CSTsfile, $!";
foreach my $eachln (@{$CSTids{$eachCSTs}})
{
print OUT '>'.$eachCSTs.'_'.$eachln,"\n";
}
close(OUT);
delete($CSTids{$eachCSTs});
}
undef(%CSTids);