annotate PanExplorer_workflow/Perl/wget.pl @ 1:032f6b3806a3 draft

Uploaded
author dereeper
date Thu, 30 May 2024 11:16:08 +0000
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
1 #!/usr/bin/perl
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
2
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
3 use strict;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
4
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
5 use File::Basename;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
6 my $dirname = dirname(__FILE__);
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
7
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
8 system("wget https://ftp.ncbi.nlm.nih.gov/genomes/GENOME_REPORTS/prokaryotes.txt");
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
9 system("wget https://ftp.ncbi.nlm.nih.gov/genomes/GENOME_REPORTS/eukaryotes.txt");
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
10
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
11 my %continents;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
12 open(F,"countries.txt");
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
13 <F>;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
14 while(my $line =<F>){
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
15 chomp($line);
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
16 my ($continent,$country) = split(/,/,$line);
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
17 $continents{$country} = $continent;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
18 }
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
19 close(F);
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
20
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
21 my $input = $ARGV[0];
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
22 my $outdir = $ARGV[1];
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
23 my $private_genomes = $ARGV[2];
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
24
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
25 system("cat $input $private_genomes >$outdir/list.txt");
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
26
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
27 my $concat = "";
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
28 open(O2,">$outdir/genbanks.txt");
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
29 open(O,">$outdir/strains.txt");
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
30 open(GENES,">$outdir/genes.txt");
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
31 open(L,">$outdir/list_genomes.txt");
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
32 open(L2,">$outdir/list_genomes2.txt");
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
33 open(L3,">$outdir/genomes.txt");
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
34 open(L4,">$outdir/genomes2.txt");
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
35 open(SEQFILE,">$outdir/seqfile");
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
36 open(PanSN,">$outdir/all_genomes.fa");
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
37 open(METADATA,">$outdir/metadata_strains.txt");
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
38
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
39 open(F,"$outdir/list.txt");
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
40 #open(TEST,">$outdir/test");
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
41 while(my $line =<F>){
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
42 chomp($line);
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
43 my $genbank = $line;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
44 if (!-e "$genbank"){
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
45 my $grep = `grep '$line' prokaryotes.txt`;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
46 #print "$genbank $line aaa $grep\n";exit;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
47 my @infos = split(/\t/,$grep);
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
48 my $status = $infos[15];
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
49 if ($status !~/Complete Genome/ && $status !~/Chromosome/){
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
50 #next;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
51 }
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
52 my $ftp_path = $infos[$#infos -2];
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
53
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
54 $ftp_path =~s/ftp:/http:/g;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
55 my @table = split(/\//,$ftp_path);
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
56 my $name = $table[$#table];
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
57 my $prot_file = "$ftp_path/$name"."_protein.faa.gz";
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
58 my $gbff = "$ftp_path/$name"."_genomic.gbff.gz";
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
59 my $gff = "$ftp_path/$name"."_genomic.gff.gz";
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
60 my $genome_fasta = "$ftp_path/$name"."_genomic.fna.gz";
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
61 my @particules = split(/_/,$name);
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
62
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
63 `wget -O $outdir/$genbank.fasta.gz $genome_fasta`;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
64 `gunzip $outdir/$genbank.fasta.gz`;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
65 `wget -O $outdir/$genbank.gb.gz $gbff`;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
66 system("gunzip $outdir/$genbank.gb.gz");
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
67
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
68
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
69 ################################################################
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
70 # for eukaryotes
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
71 ################################################################
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
72 if (!$grep){
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
73 $grep = `grep '$line' eukaryotes.txt`;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
74 my @infos = split(/\t/,$grep);
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
75 my $gca = $infos[8];
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
76 if ($gca =~/GCA_(\d\d\d)(\d\d\d)(\d\d\d)/){
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
77 my $part1 = $1;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
78 $ftp_path = "https://ftp.ncbi.nlm.nih.gov/genomes/all/GCA/$1/$2/$3";
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
79 `wget -O $outdir/$gca.index.html $ftp_path`;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
80 my $grep_name = `grep '$gca' $outdir/$gca.index.html`;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
81 unlink("$outdir/$gca.index.html");
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
82 my $name;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
83 if ($grep_name =~/href=\"(.*)\"/){
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
84 $name = $1;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
85 $name=~s/\///g;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
86 }
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
87 $ftp_path = $ftp_path."/$name";
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
88 my $prot_file = "$ftp_path/$name"."_protein.faa.gz";
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
89 my $gbff = "$ftp_path/$name"."_genomic.gbff.gz";
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
90 my $gff = "$ftp_path/$name"."_genomic.gff.gz";
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
91 my $genome_fasta = "$ftp_path/$name"."_genomic.fna.gz";
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
92 my @particules = split(/_/,$name);
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
93
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
94 `wget -O $outdir/$genbank.fasta.gz $genome_fasta`;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
95 `gunzip $outdir/$genbank.fasta.gz`;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
96 `wget -O $outdir/$genbank.gb.gz $gbff`;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
97 `wget -O $outdir/$genbank.faa.gz $prot_file`;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
98 system("gunzip $outdir/$genbank.gb.gz");
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
99 system("gunzip $outdir/$genbank.faa.gz");
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
100
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
101 }
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
102 }
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
103 }
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
104 else{
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
105 my $genbank_file = $genbank;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
106 my $grep = `grep 'LOCUS' $genbank_file`;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
107 $genbank = "unknown";
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
108 if ($grep =~/LOCUS\s+([\-\:\w]+)/){$genbank = $1;}
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
109
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
110 #$genbank =~s/\:/_/g;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
111
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
112 my $cmd = "cp -rf $genbank_file $outdir/$genbank.gb";
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
113 system($cmd);
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
114
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
115 my %genome_seqs;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
116 my $current_chr;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
117 my $go = 0;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
118 open(G,"$outdir/$genbank.gb");
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
119 while(<G>){
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
120 if ($go == 1 && /(\d+) (.*)$/){
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
121 my $line = $2;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
122 $line =~s/ //g;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
123 $genome_seqs{$current_chr}.=$line;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
124 }
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
125 if (/LOCUS ([^\s]+)/){
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
126 $current_chr = $1;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
127 }
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
128 if (/ORIGIN/){$go = 1;}
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
129 if (/^\/\//){$go = 0;}
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
130 }
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
131 close(G);
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
132
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
133 open(FASTA,">$outdir/$genbank.fasta");
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
134 foreach my $ch(keys(%genome_seqs)){
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
135 print FASTA ">$ch\n";
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
136 my $seq = $genome_seqs{$ch};
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
137 print FASTA "$seq\n";
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
138 }
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
139 close(FASTA);
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
140 }
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
141 #my $get_organism_line = `head -10 $outdir/$genbank.gb | grep DEFINITION `;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
142 my $get_organism_line = `head -10 $outdir/$genbank.gb | grep -A 1 DEFINITION `;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
143
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
144 # if several lines for DEFINITION, concatenate the lines
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
145 my @lines_organism = split(/\n/,$get_organism_line);
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
146 my $first_line = $lines_organism[0];
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
147 my $second_line = $lines_organism[1];
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
148 if ($second_line =~/^ (.*)/){
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
149 $get_organism_line = $first_line. " ".$1;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
150 }
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
151 else{
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
152 $get_organism_line = $first_line;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
153 }
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
154
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
155 my $strain;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
156 my $genus;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
157 if ($get_organism_line =~/DEFINITION (.*)$/){
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
158 $strain = $1;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
159 ($genus) = split(/\s/,$strain);
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
160 }
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
161 my $country = `head -100 $outdir/$genbank.gb | grep country `;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
162 $country =~s/^\s+//g;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
163 $country =~s/\/country=//g;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
164 $country =~s/\"//g;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
165 $country =~s/\n//g;$country =~s/\r//g;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
166 if ($country =~/:/){
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
167 my $city;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
168 ($country,$city) = split(/:/,$country);
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
169 }
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
170 if ($country eq ""){$country = "unresolved";}
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
171 my $continent = "unresolved";
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
172 if ($continents{$country}){
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
173 $continent = $continents{$country};
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
174 }
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
175 $strain =~s/\.//g;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
176 my ($info1,$info2 ) = split(",",$strain);
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
177 $strain = $info1;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
178 $strain =~s/ /_/g;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
179 $strain =~s/strain_//g;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
180 $strain =~s/_chromosome//g;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
181 $strain =~s/_genome//g;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
182 $strain =~s/_str_/_/g;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
183 $strain =~s/[^\w\-\_]//g;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
184 $strain =~s/\-/_/g;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
185
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
186 print O "$genbank $strain\n";
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
187 $concat .= "$genbank,";
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
188 print L "$genbank $outdir/$genbank.gb\n";
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
189 print L2 "$genbank\n";
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
190 print L3 "$outdir/$genbank.fasta\n";
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
191 print L4 "$outdir/$genbank.fasta $strain\n";
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
192 print SEQFILE "$genbank $outdir/$genbank.fasta\n";
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
193 print METADATA "$strain\t$genus\t$country\t$continent\n";
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
194
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
195
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
196 my %genome_sequences;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
197 my $genome = "";
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
198 my $seqid = "";
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
199 open(GENOME,"$outdir/$genbank.fasta");
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
200 while(<GENOME>){
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
201 if (!/^>/){
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
202 my $line = $_;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
203 $line =~s/\n//g;$line =~s/\r//g;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
204 $genome_sequences{$seqid} .= $line;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
205 $genome .= $line;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
206 print PanSN $_;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
207 }
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
208 elsif (/>([^\s]+)/){
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
209 $seqid = $1;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
210 $seqid =~s/\.\d+$//g;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
211 print PanSN ">$strain#$seqid\n";
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
212 }
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
213 }
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
214 close(GENOME);
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
215
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
216
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
217 open(N,">$outdir/$genbank.nuc");
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
218 open(P,">$outdir/$genbank.pep");
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
219 open(FUNC,">$outdir/$genbank.func");
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
220 my $go = 0;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
221 my $start;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
222 my $end;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
223 my $product;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
224 my $complement = 0;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
225 my $end_gene = "no";
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
226 my $protein = "";
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
227
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
228 #`sed -i "s/'//g" $outdir/$genbank.gb`;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
229
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
230 my $has_translation = `grep -c 'translation=' $outdir/$genbank.gb`;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
231 $has_translation =~s/\n//g;$has_translation =~s/\r//g;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
232 open(G,"$outdir/$genbank.gb");
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
233 my $current_gene;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
234 my $current_chrom;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
235 while(<G>){
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
236 if (/^\s+ORGANISM\s+(.*)$/){
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
237 }
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
238 if (/protein_id=\"(.*)\"/){
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
239 $current_gene = $1;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
240 }
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
241 if (/LOCUS ([^\s]+)/){
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
242 $current_chrom = $1;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
243 }
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
244 if (/locus_tag=\"(.*)\"/){
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
245 $current_gene = $1;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
246 }
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
247 if ($go == 1){
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
248 my $line = $_;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
249 $line =~s/ //g;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
250 $line =~s/\n//g;$line =~s/\r//g;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
251 $protein .= $line;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
252 if (/\"$/){
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
253 $protein =~s/\"//g;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
254 $end_gene = "yes";
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
255
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
256 }
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
257 }
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
258 if (/\/translation=\"(.*)/ or ($has_translation == 0 && /protein_id=/)){
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
259 $go = 1;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
260 $protein .= $1;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
261 print P ">$current_gene\n";
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
262 print N ">$current_gene\n";
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
263 print GENES "$current_gene $product [$strain]\n";
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
264
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
265 if ($protein =~/\"$/){
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
266 $end_gene = "yes";
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
267 }
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
268 if ($has_translation == 0){$end_gene = "yes";}
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
269 }
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
270 if ($end_gene eq "yes"){
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
271 $protein =~s/\"//g;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
272 print P "$protein\n";
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
273 $protein = "";
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
274 my $length = $end - $start + 1;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
275
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
276 #print "okkkk $current_chrom\n";
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
277 #my $geneseq = substr($genome,$start-1,$length);
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
278 my $geneseq = substr($genome_sequences{$current_chrom},$start-1,$length);
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
279
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
280
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
281 if ($complement){
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
282 my $revcomp = reverse $geneseq;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
283 $revcomp =~ tr/ATGCatgc/TACGtacg/;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
284 $geneseq = $revcomp;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
285 }
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
286 print N "$geneseq\n";
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
287 print FUNC "$current_gene - $product\n";
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
288 $go = 0;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
289 $end_gene = "no";
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
290 }
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
291 if (/\/product=\"(.*)\"/){
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
292 $product = $1;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
293 }
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
294 if (/^\s+CDS\s+(\d+)\.\.(\d+)\s*$/){
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
295 $start = $1;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
296 $end = $2;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
297 $complement = 0;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
298 }
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
299 if (/^\s+CDS\s+complement\((\d+)\.\.(\d+)\)\s*$/){
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
300 $start = $1;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
301 $end = $2;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
302 $complement = 1;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
303 }
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
304 }
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
305 close(G);
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
306 close(P);
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
307 close(N);
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
308 close(FUNC);
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
309
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
310 if ($has_translation == 0){
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
311 system("perl $dirname/translate.pl $outdir/$genbank.nuc $outdir/$genbank.pep");
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
312 }
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
313
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
314 my $prot_num = 0;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
315 open(PRT,">$outdir/$genbank.prt");
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
316 open(P,"$outdir/$genbank.pep");
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
317 while(<P>){
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
318 if (/>(.*)/){
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
319 my $prot_id = $1;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
320 $prot_num++;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
321 my $new_id = "$strain"."_".$prot_num;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
322 print PRT ">$new_id\n";
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
323 }
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
324 else{
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
325 print PRT $_;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
326 }
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
327 }
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
328 close(P);
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
329 close(PRT);
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
330 }
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
331 close(F);
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
332 close(O);
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
333 close(METADATA);
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
334 chop($concat);
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
335 print O2 $concat;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
336 close(O2);
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
337 close(L);
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
338 close(L2);
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
339 close(L3);
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
340 close(L4);
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
341 close(GENES);
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
342 close(SEQFILE);
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
343 close(PanSN);
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
344 #close(TEST);
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
345
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
346 unlink("prokaryotes.txt");
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
347 unlink("eukaryotes.txt");