-
Notifications
You must be signed in to change notification settings - Fork 0
/
Silva_merger.pl
72 lines (72 loc) · 1.8 KB
/
Silva_merger.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
####Created by karamveer, PhD student, Pondicherry University on 12/11/2022############
##This program can generate a consolidated output table by compiling individual sample OTU tables generated by SilvaNGS##
#read the file with all samples spepecies
#input_folder should contain only otu count tables
if($#ARGV<1){
die "Usage: perl Silva_merger.pl input_folder output_file.csv\n";
}
$inputfile=@ARGV[0];
$outpath=@ARGV[1];
system(`cat $inputfile/* > all_new.csv`);
$filename='all_new.csv';
open(FILE,$filename);
@file=<FILE>;
foreach $file(@file){
@line=split('\t',$file);
#extract the taxonomy column
push(@array,$line[5]);
}
#print"@array";
#create an hash table with the array
%hash=@array;
@Key_array = keys %hash;
unshift(@Key_array,"Taxonomy\n \n");
#print"@Key_array";
open(KEY, '>', 'key.txt');
print KEY "@Key_array";
#$dir='input1';
@files = glob( $inputfile . '/*' );
foreach $filename1(@files){
#print "***$filename1***";
@sample=split('---|/',$filename1);
$sampleName=$sample[1];
#print "$sampleName";
$sampleName1=uc($sampleName);
@out_array=();
push(@out_array,"$sampleName1\n");
open(FILE1,$filename1);
@file1=<FILE1>;
shift(@file1);
my %hash1;
foreach $line1(@file1){
@line2=split('\t',$line1);
$key=$line2[5];
chomp($key);
$value=$line2[0];
#print $value;
$hash1{$key} = $value;
}
foreach $key1(@Key_array){
chomp($key1);
if(exists($hash1{$key1})){
push(@out_array,"$hash1{$key1}\n");
}
else{
push(@out_array,"0\n");
}
}
$out_file="$sampleName.txt";
#print "$out_file";
open(OUT, '>', $out_file);
print OUT "@out_array";
#close OUT;
}
#open(OUT, '>', 'out1.tsv');
#print OUT "@out_array";
$key2='key.txt';
$patt=lc(substr($sampleName1,0,3));
#print $patt;
$pattern="$patt*";
#$out2='consolidated.csv';
system(`paste -d "," $key2 $pattern > $outpath`);
system(`rm $pattern`);