annotate Perl/get_data.pl @ 6:35d71348e81e draft

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