-
Notifications
You must be signed in to change notification settings - Fork 2
/
SearchAminoacidsFromCore.pl
134 lines (133 loc) · 3.76 KB
/
SearchAminoacidsFromCore.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
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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
use lib './';
use Getopt::Long;
use globals2;
use experimental 'smartmatch';
#####################################
#requirements:
#-genomes list
#-pairedB LAST e.g. 1vs2 2vs3 3vs 4 .../
#- fasta aminocids for each genome
#AUTOR: Christian Eduardo Martinez G.
#latest version modified by Pablo Cruz-Morales June 2020
#####################################
#!/usr/bin/perl
# $dir Global variable from globals
my $infile="$NAME2"; ##will make a folder
my $outdir="$dir2/$infile";
my $lista="lista.$NUM2";
my $listaname="$NUM2.lista";
my $DesiredGenes="Core";
#-----------------------------------------
system "mkdir $outdir";
system "mkdir $outdir/FASTAINTERporORG/";
system "mkdir $outdir/FASTAINTER/";
### read all mini BGC candidates
my %MINIS=ReadFasta($dir2,$listaname);#INPUT the .bbh OUTPUT= intersection of all at inter.todos
foreach my $PegId(keys %MINIS){
}
## makes a hash with the id of each ortholog
## print a fasta with the IDs sorted by orthology
## pront list otho all
byOrthologues($DesiredGenes,\%MINIS,$outdir);
## makes a hash with the id of each gene in the core of each genome
## prints a fasta wih the ids sorted by genome
byOrganism($DesiredGenes,\%MINIS,$outdir);
print "Done!\n";
####################################
##makes a fasta of the intersections (CORES)
####################################
sub ReadFasta{
my $dir=shift;
my $listaname=shift;
my %hashFastaH;
open (FAA, "$dir/$listaname") or die $!;
my $headerFasta="";
while(my $linea=<FAA>){
chomp($linea);
######### Get file number
my $fnumber=$linea;
$fnumber=~s/\.faa//;
####### fills hash with a header-sequence#####
open (CU, "$dir/MINI/$linea") or die $linea;
while(<CU>){
if($_ =~ />/){
chomp;
$headerFasta=$_."|$fnumber";
}
else{
$_ =~ s/\*//g;
$hashFastaH{$headerFasta}= $hashFastaH{$headerFasta}.$_;
}
}#end while CU
}#end while FAA ############# finishes filling hash with a header-sequence
close CU;
close FAA;
return %hashFastaH;
}
#_______________________________________________________________________
sub byOrthologues{
my $DesiredGenes=shift;
my $refMINIS=shift;
my $outdir=shift;
open (ALL, "$dir/$DesiredGenes") or die $!;
my $count=1;
foreach my $linea(<ALL>){
open (FASTAINTER, ">$outdir/FASTAINTER/$count.interFastatodos") or die "Couldnt open file $count interFastatodos $!";
open (LISTA, ">>$outdir/lista.ORTHOall") or die "Lista ortho all $!";
print LISTA "$count.interFastatodos \n";
chomp $linea;
my @sp=split (/\t/,$linea);
foreach my $gen (@sp){
$gen=">$gen";
if(exists $refMINIS->{$gen}){
print FASTAINTER "$gen\n$refMINIS->{$gen}";
}
else{
}
}
close FASTAINTER;
close LISTA;
$count++;
}
close ALL;
}
#_______________________________________________________________________
sub byOrganism{
my $DesiredGenes=shift;
my $refMINIS=shift;
my $outdir=shift;
open (ALL, "$dir/$DesiredGenes") or die $!;
my %Orgs;
my $count=1;
foreach my $linea(<ALL>){ ##for each line in the core
chomp $linea;
my @sp=split (/\t/,$linea);
$count ++;
foreach my $gen (@sp){ ## grabs the gene in order
$gen=">$gen";
if ($gen=~/\>fig\|\d*.\d*\.peg\.\d*\|(\d*\_\d*)$/){
if (!exists $Orgs{$1}){
$Orgs{$1}=[];
}
push(@{$Orgs{$1}},$gen);
}
}
}
close ALL;
foreach my $orgNumber(keys %Orgs){
open (FASTAINTERORG, ">$outdir/FASTAINTERporORG/$orgNumber.interFastatodos") or die "Couldn't open orthologues file $orgNumber $!";
if(exists $Orgs{$orgNumber}){
foreach my $gen (@{$Orgs{$orgNumber}}){
if(exists $MINIS{$gen}){
print FASTAINTERORG "$gen\n$MINIS{$gen}";
}
else{
}
}
}
else{
}
close FASTAINTERORG;
}#end while foreach
}