-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path05exractingCSTsFastaSeq.pl
65 lines (63 loc) · 1.62 KB
/
05exractingCSTsFastaSeq.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
#!/usr/bin/perl -w
use strict;
##
##
##
## extracting CSTs(cummunity state taxons) from combined OTUs table in fasta format
##
##
my $ftable = '/home/thsti/metagenomicsAnalysis/16sRNA_Obese/sample_cleaned_trimmed_Qiime2Analysis/P40obese_sample_cleaned_trimmed_rename_OTUfeature-table_q17len100_filtered.tsv';
my $CSTsfolder = '/home/thsti/metagenomicsAnalysis/16sRNA_Obese/sample_cleaned_trimmed_Qiime2Analysis/P40obese_sample_cleaned_trimmed_rename_OTUfeature-table_q17len100_filtered_CSTs';
##
##
##
my %CSTids;
open(TABLE, $ftable) or die "could not open file $ftable, $!";
while(my $ln =<TABLE>)
{
if($ln =~ /^\#/)
{
next;
}
else
{
$ln =~ s/^\s+|\s+$//;
my @lnA = split(/\t/, $ln);
$CSTids{$lnA[0]} += 1;
undef(@lnA);
}
}
close(TABLE);
foreach my $eachCSTs (keys%CSTids)
{
my $count = 1;
my $CSTsfile = $CSTsfolder.'/'.$eachCSTs.'.fasta';
#my $CSTsRname = $CSTsfolder.'/'.$eachCSTs.'_namelist';
open(TABLE1, $ftable) or die "could not open file $ftable, $!";
open(OUT,">$CSTsfile") or die "could not open file $CSTsfile, $!";
#open(RNAME, ">$CSTsRname") or die "could not open file $CSTsRname, $!";
while(my $ln =<TABLE1>)
{
if($ln =~ /^\#/)
{
next;
}
else
{
$ln =~ s/^\s+|\s+$//;
my @lnA = split(/\t/, $ln);
if($lnA[0] eq $eachCSTs)
{
print $CSTsfile,"\t",$lnA[1],"\n";
#print RNAME $eachCSTs.'_OTU_'.$count,"\t",$lnA[1],"\n";
print OUT '>'.$eachCSTs.'_'.$lnA[1],"\n";
print OUT $lnA[$#lnA],"\n";
$count++;
}
undef(@lnA);
}
}
close(TABLE1);
close(OUT);
}
undef(%CSTids);