annotate PanExplorer_workflow/Perl/get_data.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 YAML qw(LoadFile);
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
6 use Data::Dumper qw(Dumper);
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
7 use File::Basename;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
8 my $dirname = dirname(__FILE__);
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
9
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_yml = $ARGV[0];
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
22 my $outdir = $ARGV[1];
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
23
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
24 open(LIST,">$outdir/list.txt");
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
25 my $data = LoadFile($input_yml);
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
26 my %hashtable = %$data;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
27
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
28 if ($hashtable{"ids"}){
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
29 my $ref_ids = $hashtable{"ids"};
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
30 my @ids = @$ref_ids;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
31 foreach my $id(@ids){
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
32 print LIST "$id\n";
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
33 }
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
34 }
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
35 if ($hashtable{"input_genbanks"}){
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
36 my $ref_gbs = $hashtable{"input_genbanks"};
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
37 my @gbs = @$ref_gbs;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
38 foreach my $gb(@gbs){
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
39 print LIST "$gb\n";
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
40 }
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
41 }
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
42 close(LIST);
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
43
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
44
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
45
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
46 my $concat = "";
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
47 open(O2,">$outdir/genbanks.txt");
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
48 open(O,">$outdir/strains.txt");
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
49 open(GENES,">$outdir/genes.txt");
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
50 open(L,">$outdir/list_genomes.txt");
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
51 open(L2,">$outdir/list_genomes2.txt");
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
52 open(L3,">$outdir/genomes.txt");
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
53 open(L4,">$outdir/genomes2.txt");
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
54 open(SEQFILE,">$outdir/seqfile");
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
55 open(PanSN,">$outdir/all_genomes.fa");
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
56 open(METADATA,">$outdir/metadata_strains.txt");
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
57
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
58 open(F,"$outdir/list.txt");
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
59 #open(TEST,">$outdir/test");
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
60 while(my $line =<F>){
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
61 chomp($line);
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
62 my $genbank = $line;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
63 if (!-e "$genbank"){
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
64
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
65 my $assembly_accession = $genbank;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
66 system("datasets download genome accession --include-gbff --filename $outdir/$assembly_accession.zip $assembly_accession");
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
67 system("unzip -o $outdir/$assembly_accession.zip");
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
68 system("cp -rf ncbi_dataset/data/$assembly_accession/$assembly_accession*genomic.fna $outdir/$genbank.fasta");
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
69 system("cp -rf ncbi_dataset/data/$assembly_accession/genomic.gbff $outdir/$genbank.gb");
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
70
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
71
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
72 }
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
73 else{
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
74 my $genbank_file = $genbank;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
75 my $grep = `grep 'LOCUS' $genbank_file`;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
76 $genbank = "unknown";
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
77 if ($grep =~/LOCUS\s+([\-\:\w]+)/){$genbank = $1;}
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
78
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
79 #$genbank =~s/\:/_/g;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
80
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
81 my $cmd = "cp -rf $genbank_file $outdir/$genbank.gb";
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
82 system($cmd);
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
83
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
84 my %genome_seqs;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
85 my $current_chr;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
86 my $go = 0;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
87 open(G,"$outdir/$genbank.gb");
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
88 while(<G>){
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
89 if ($go == 1 && /(\d+) (.*)$/){
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
90 my $line = $2;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
91 $line =~s/ //g;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
92 $genome_seqs{$current_chr}.=$line;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
93 }
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
94 if (/LOCUS ([^\s]+)/){
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
95 $current_chr = $1;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
96 }
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
97 if (/ORIGIN/){$go = 1;}
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
98 if (/^\/\//){$go = 0;}
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
99 }
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
100 close(G);
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
101
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
102 open(FASTA,">$outdir/$genbank.fasta");
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
103 foreach my $ch(keys(%genome_seqs)){
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
104 print FASTA ">$ch\n";
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
105 my $seq = $genome_seqs{$ch};
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
106 print FASTA "$seq\n";
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
107 }
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
108 close(FASTA);
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
109 }
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
110 #my $get_organism_line = `head -10 $outdir/$genbank.gb | grep DEFINITION `;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
111
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
112 # remove single quote in genbank file
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
113 `sed -i "s/'//g" $outdir/$genbank.gb`;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
114 my $get_organism_line = `head -10 $outdir/$genbank.gb | grep -A 1 DEFINITION `;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
115
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
116 # if several lines for DEFINITION, concatenate the lines
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
117 my @lines_organism = split(/\n/,$get_organism_line);
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
118 my $first_line = $lines_organism[0];
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
119 my $second_line = $lines_organism[1];
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
120 if ($second_line =~/^ (.*)/){
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
121 $get_organism_line = $first_line. " ".$1;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
122 }
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
123 else{
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
124 $get_organism_line = $first_line;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
125 }
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
126
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
127 my $strain;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
128 my $genus;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
129 if ($get_organism_line =~/DEFINITION (.*)$/){
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
130 $strain = $1;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
131 ($genus) = split(/\s/,$strain);
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
132 }
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
133 my $country = `head -100 $outdir/$genbank.gb | grep country `;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
134 $country =~s/^\s+//g;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
135 $country =~s/\/country=//g;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
136 $country =~s/\"//g;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
137 $country =~s/\n//g;$country =~s/\r//g;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
138 if ($country =~/:/){
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
139 my $city;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
140 ($country,$city) = split(/:/,$country);
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
141 }
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
142 if ($country eq ""){$country = "unresolved";}
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
143 my $continent = "unresolved";
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
144 if ($continents{$country}){
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
145 $continent = $continents{$country};
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
146 }
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
147 $strain =~s/\.//g;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
148 my ($info1,$info2 ) = split(",",$strain);
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
149 $strain = $info1;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
150 $strain =~s/ /_/g;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
151 $strain =~s/strain_//g;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
152 $strain =~s/_chromosome//g;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
153 $strain =~s/_genome//g;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
154 $strain =~s/_str_/_/g;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
155 $strain =~s/[^\w\-\_]//g;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
156 $strain =~s/\-/_/g;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
157
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
158 print O "$genbank $strain\n";
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
159 $concat .= "$genbank,";
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
160 print L "$genbank $outdir/$genbank.gb\n";
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
161 print L2 "$genbank\n";
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
162 print L3 "$outdir/$genbank.fasta\n";
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
163 print L4 "$outdir/$genbank.fasta $strain\n";
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
164 print SEQFILE "$genbank $outdir/$genbank.fasta\n";
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
165 print METADATA "$strain\t$genus\t$country\t$continent\n";
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
166
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
167
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
168 my %genome_sequences;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
169 my $genome = "";
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
170 my $seqid = "";
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
171 open(GENOME,"$outdir/$genbank.fasta");
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
172 while(<GENOME>){
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
173 if (!/^>/){
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
174 my $line = $_;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
175 $line =~s/\n//g;$line =~s/\r//g;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
176 $genome_sequences{$seqid} .= $line;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
177 $genome .= $line;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
178 print PanSN $_;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
179 }
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
180 elsif (/>([^\s]+)/){
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
181 $seqid = $1;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
182 $seqid =~s/\.\d+$//g;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
183 print PanSN ">$strain#$seqid\n";
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
184 }
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
185 }
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
186 close(GENOME);
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
187
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
188
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
189 open(N,">$outdir/$genbank.nuc");
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
190 open(P,">$outdir/$genbank.pep");
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
191 open(FUNC,">$outdir/$genbank.func");
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
192 my $go = 0;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
193 my $start;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
194 my $end;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
195 my $product;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
196 my $complement = 0;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
197 my $end_gene = "no";
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
198 my $protein = "";
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
199 my $has_translation = `grep -c 'translation=' $outdir/$genbank.gb`;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
200 $has_translation =~s/\n//g;$has_translation =~s/\r//g;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
201 open(G,"$outdir/$genbank.gb");
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
202 my $current_gene;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
203 my $current_chrom;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
204 while(<G>){
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
205 if (/^\s+ORGANISM\s+(.*)$/){
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
206 }
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
207 if (/protein_id=\"(.*)\"/){
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
208 $current_gene = $1;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
209 }
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
210 if (/LOCUS ([^\s]+)/){
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
211 $current_chrom = $1;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
212 }
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
213 if (/locus_tag=\"(.*)\"/){
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
214 $current_gene = $1;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
215 }
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
216 if ($go == 1){
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
217 my $line = $_;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
218 $line =~s/ //g;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
219 $line =~s/\n//g;$line =~s/\r//g;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
220 $protein .= $line;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
221 if (/\"$/){
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
222 $protein =~s/\"//g;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
223 $end_gene = "yes";
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
224
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
225 }
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
226 }
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
227 if (/\/translation=\"(.*)/ or ($has_translation == 0 && /protein_id=/)){
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
228 $go = 1;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
229 $protein .= $1;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
230 print P ">$current_gene\n";
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
231 print N ">$current_gene\n";
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
232 print GENES "$current_gene $product [$strain]\n";
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
233
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
234 if ($protein =~/\"$/){
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
235 $end_gene = "yes";
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
236 }
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
237 if ($has_translation == 0){$end_gene = "yes";}
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
238 }
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
239 if ($end_gene eq "yes"){
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
240 $protein =~s/\"//g;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
241 print P "$protein\n";
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
242 $protein = "";
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
243 my $length = $end - $start + 1;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
244
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
245 #print "okkkk $current_chrom\n";
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
246 #my $geneseq = substr($genome,$start-1,$length);
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
247 my $geneseq = substr($genome_sequences{$current_chrom},$start-1,$length);
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
248
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
249
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
250 if ($complement){
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
251 my $revcomp = reverse $geneseq;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
252 $revcomp =~ tr/ATGCatgc/TACGtacg/;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
253 $geneseq = $revcomp;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
254 }
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
255 print N "$geneseq\n";
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
256 print FUNC "$current_gene - $product\n";
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
257 $go = 0;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
258 $end_gene = "no";
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
259 }
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
260 if (/\/product=\"(.*)\"/){
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
261 $product = $1;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
262 }
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
263 if (/^\s+CDS\s+(\d+)\.\.(\d+)\s*$/){
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
264 $start = $1;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
265 $end = $2;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
266 $complement = 0;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
267 }
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
268 if (/^\s+CDS\s+complement\((\d+)\.\.(\d+)\)\s*$/){
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
269 $start = $1;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
270 $end = $2;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
271 $complement = 1;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
272 }
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
273 }
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
274 close(G);
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
275 close(P);
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
276 close(N);
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
277 close(FUNC);
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
278
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
279 if ($has_translation == 0){
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
280 system("perl $dirname/translate.pl $outdir/$genbank.nuc $outdir/$genbank.pep");
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
281 }
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
282
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
283 my $prot_num = 0;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
284 open(PRT,">$outdir/$genbank.prt");
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
285 open(P,"$outdir/$genbank.pep");
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
286 while(<P>){
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
287 if (/>(.*)/){
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
288 my $prot_id = $1;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
289 $prot_num++;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
290 my $new_id = "$strain"."_".$prot_num;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
291 print PRT ">$new_id\n";
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
292 }
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
293 else{
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
294 print PRT $_;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
295 }
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
296 }
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
297 close(P);
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
298 close(PRT);
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
299 }
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
300 close(F);
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
301 close(O);
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
302 close(METADATA);
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
303 chop($concat);
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
304 print O2 $concat;
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
305 close(O2);
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
306 close(L);
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
307 close(L2);
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
308 close(L3);
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
309 close(L4);
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
310 close(GENES);
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
311 close(SEQFILE);
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
312 close(PanSN);
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
313 #close(TEST);
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
314
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
315 unlink("prokaryotes.txt");
032f6b3806a3 Uploaded
dereeper
parents:
diff changeset
316 unlink("eukaryotes.txt");