File: Typical.pl

package info (click to toggle)
ampliconnoise 1.29-10
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 6,040 kB
  • sloc: ansic: 18,080; sh: 2,899; perl: 2,089; makefile: 235
file content (97 lines) | stat: -rwxr-xr-x 1,747 bytes parent folder | download | duplicates (8)
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
#!/usr/bin/perl

use strict;

my $d         = $ARGV[0];
my $fastaFile = $ARGV[1];
my $listFile  = $ARGV[2];

my @ids     = ();
my @seqs    = ();
my @weights = ();
my @cWeights = ();
my %hashID = {};

open(FILE, $fastaFile) or die "Can't open $fastaFile\n";

my $count = 0;
while(my $line = <FILE>){
    if($line =~ />(.*)/){
	my $name = $1;
	$ids[$count] = $name;
	$ids[$count] =~ /^.*_\d+_(\d+)/;
	#print "$1\n";
	$weights[$count] = $1;
	$hashID{$name} = $count;
	$count++;
    }
    else{
	chomp($line);
	if($seqs[$count - 1] ne undef){
	    $seqs[$count - 1] = $seqs[$count - 1] . $line;
	}
	else{
	    $seqs[$count - 1] = $line;
	}
    }
}

close(FILE);

#for(my $i = 0; $i < $count; $i++){
 #   print "$i $ids[$i] $weights[$i]\n";
#}

my @consensus = ();

open(FILE, $listFile) or die "Can't open $listFile\n";


while(my $line = <FILE>){
    my @tokens = split(/ /,$line);

    my $dLocal = shift(@tokens);
    
    my $N = shift(@tokens);

    if($d == $dLocal){
	for(my $i = 0; $i < $N; $i++){
	    my $clust = shift(@tokens);

	    my @cluster = split(/,/,$clust);
	    my $cSize = scalar(@cluster);

	    my $otuWeight = $weights[$hashID{$cluster[0]}];

	    my $bestWeight = $weights[$hashID{$cluster[0]}];
	    my $bestJ      = $hashID{$cluster[0]};

	    for(my $j = 1; $j < $cSize; $j++){
		if($weights[$hashID{$cluster[$j]}] > $bestWeight){
		    $bestJ = $hashID{$cluster[$j]};
		    $bestWeight = $weights[$hashID{$cluster[$j]}];
		}

		$otuWeight += $weights[$hashID{$cluster[$j]}];
	    } 
	    
	    $consensus[$i] = $seqs[$bestJ];
	    $cWeights[$i] = $otuWeight;
	    

	    #print "$i $consensus[$i]\n";
	}

	for(my $i = 0; $i < $N; $i++){
	    print ">C${i}\n";

	    print "$consensus[$i]\n";
	}


    }

}

close(FILE);