-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathClusterRemover.pl
62 lines (47 loc) · 1.32 KB
/
ClusterRemover.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
#This is a perl script that results in a file of .fasta sequences of orthologous cluster determined by OrthoMCL.
#The script matches names of sequences in a cluster in the OrthoMCL output file (.end) with your original sequence file (.fa),
# and makes a new file with the .fasta sequences of those in a cluster.
#HOW TO RUN: perl ClusterRemover.pl endfile.end fasta.fa
use Data::Dumper;
#reads in the Table
open(TABLE, $ARGV[0])||die "No Table\n";
while($line = <TABLE>){
chomp $line;
($file_name, $rest) = split ":", $line, 2;
# print "$rest\n";
@array = split " ", $rest;
foreach $i (0..$#array){
$HASH{$file_name}[$i] = $array[$i];
}
}
#print Dumper(\%HASH);
$count = 0;
open(FASTA, $ARGV[1])||die "No Fasta\n";
while ($line = <FASTA>){
chomp $line;
if ($line =~ /^>/){
if ($count != 0){
$seq_hash{$gi} = $seq;
}
#print "$line\n";
$gi = ($line =~ m/gi\|(.*?)\|.*/)[0];
#print "$gi\n";
$seq = "";
}else{
$seq .= $line;
}
$count++;
}
$seq_hash{$gi} = $seq;
foreach $key (keys %HASH){
open(out, ">>$key\_file\.to_remove");
#print "$HASH{$key}[1]\n";
foreach $i (0..$#{$HASH{$key}}){
$gi = ($HASH{$key}[$i] =~ m/gi\|(.*?)\|.*/)[0];
if (exists $seq_hash{$gi}){
print out ">$HASH{$key}[$i]\n$seq_hash{$gi}\n";
}
}
}
# comment
Kindly written by Joe Walker (contributed here by Jill Myers)