1 # -*-Perl-*- Test Harness script for Bioperl
10 test_begin(-tests => 100);
12 use_ok('Bio::SeqIO::embl');
15 my $verbose = test_debug();
17 my $ast = Bio::SeqIO->new( -format => 'embl',
19 -file => test_input_file('roa1.dat'));
20 $ast->verbose($verbose);
21 my $as = $ast->next_seq();
23 is($as->display_id, 'HSHNCPA1');
24 is($as->accession_number, 'X79536');
25 is($as->seq_version, 1);
27 is($as->desc, 'H.sapiens mRNA for hnRNPcore protein A1');
28 is($as->molecule, 'RNA');
29 is($as->alphabet, 'rna');
30 is(scalar $as->all_SeqFeatures(), 4);
31 is($as->length, 1198);
32 is($as->species->binomial(), 'Homo sapiens');
34 # EMBL Release 87 changes (8-17-06)
36 $ast = Bio::SeqIO->new( -format => 'embl',
38 -file => test_input_file('roa1_v2.dat'));
39 $ast->verbose($verbose);
40 $as = $ast->next_seq();
42 # accession # same as display name now
43 is($as->display_id, 'X79536');
44 is($as->accession_number, 'X79536');
45 is($as->seq_version, 1);
47 is($as->desc, 'H.sapiens mRNA for hnRNPcore protein A1');
49 is($as->molecule, 'mRNA');
50 is($as->alphabet, 'rna');
51 is(scalar $as->all_SeqFeatures(), 4);
52 is($as->length, 1198);
53 is($as->species->binomial(), 'Homo sapiens');
55 my $ent = Bio::SeqIO->new( -file => test_input_file('test.embl'),
57 my $seq = $ent->next_seq();
59 is(defined $seq->seq(), 1,
60 'success reading Embl with ^ location and badly split double quotes');
61 is(scalar $seq->annotation->get_Annotations('reference'), 3);
63 my $out_file = test_output_file();
64 my $out = Bio::SeqIO->new(-file=> ">$out_file",
66 is($out->write_seq($seq),1,
67 'success writing Embl format with ^ < and > locations');
70 $ent = Bio::SeqIO->new( -file => test_input_file('test.embl'),
72 $seq = $ent->next_seq();
75 is(lc($seq->subseq(1,10)),'gatcagtaga');
76 is($seq->length, 4870);
79 my $noFH = Bio::SeqIO->new( -file => test_input_file('no_FH.embl'),
81 is(scalar($noFH->next_seq->get_SeqFeatures), 4);
84 $ent = Bio::SeqIO->new( -format => 'embl',
85 -file => test_input_file('test.embl2sq'));
86 is($ent->next_seq->length,4877);
89 $ent = Bio::SeqIO->new(-file => test_input_file('BEL16-LTR_AG.embl'), -format => 'embl');
90 $seq = $ent->next_seq;
91 is($seq->display_id,'BEL16-LTR_AG');
93 # test secondary accessions in EMBL (bug #1332)
94 my $seqio = Bio::SeqIO->new( -format => 'embl',
95 -file => test_input_file('ECAPAH02.embl'));
96 $seq = $seqio->next_seq;
97 is($seq->accession_number, 'D10483');
98 is($seq->seq_version, 2);
99 my @accs = $seq->get_secondary_accessions();
100 is($accs[0], 'J01597');
101 is($accs[-1], 'X56742');
103 ### TPA TESTS - Thanks to Richard Adams ###
104 # test Third Party Annotation entries in EMBL/Gb format
105 # to ensure compatability with parsers.
106 my $str = Bio::SeqIO->new( -format =>'embl',
107 -file => test_input_file('BN000066-tpa.embl'));
108 $seq = $str->next_seq;
110 is($seq->accession_number, 'BN000066');
111 is($seq->alphabet, 'dna');
112 is($seq->display_id, 'AGA000066');
113 is($seq->length, 5195);
114 is($seq->division, 'INV');
115 is($seq->get_dates, 2);
116 is($seq->keywords, 'acetylcholinesterase; achE1 gene; Third Party Annotation; TPA.');
117 is($seq->seq_version, 1);
118 is($seq->feature_count, 15);
120 my $spec_obj = $seq->species;
121 is ($spec_obj->common_name, 'African malaria mosquito');
122 is ($spec_obj->species, 'gambiae');
123 is ($spec_obj->genus, 'Anopheles');
124 is ($spec_obj->binomial, 'Anopheles gambiae');
126 my $ac = $seq->annotation;
127 my $reference = ($ac->get_Annotations('reference') )[1];
128 is ($reference->title,'"A novel acetylcholinesterase gene in mosquitoes codes for the insecticide target and is non-homologous to the ace gene in Drosophila"');
129 is ($reference->authors,'Weill M., Fort P., Berthomi eu A., Dubois M.P., Pasteur N., Raymond M.');
130 my $cmmnt = ($ac->get_Annotations('comment') )[0];
131 is($cmmnt->text, 'see also AJ488492 for achE-1 from Kisumu strain Third Party Annotation Database: This TPA record uses Anopheles gambiae trace archive data (http://trace.ensembl.org) ');
134 $ent = Bio::SeqIO->new( -file => test_input_file('test.embl'),
136 $ent->verbose($verbose);
137 $seq = $ent->next_seq();
138 my $species = $seq->species();
139 my @cl = $species->classification();
140 is( $cl[3] ne $species->genus(), 1, 'genus duplication test');
144 ## read-write - test embl writing of a PrimarySeq
146 my $primaryseq = Bio::PrimarySeq->new( -seq => 'AGAGAGAGATA',
150 -accession_number => 'myaccession');
154 $verbose = -1 unless $ENV{'BIOPERLDEBUG'}; # silence warnings unless we are debuggin
156 my $embl = Bio::SeqIO->new(-format => 'embl',
157 -verbose => $verbose,
158 -file => ">$out_file");
160 ok($embl->write_seq($primaryseq));
162 # this should generate a warning
165 $embl->write_seq($scalar);
170 # (which have nonstandard 'PA' and 'OX' tags)
171 # see http://bioperl.org/pipermail/bioperl-l/2009-February/029252.html
172 # and the rest of that thread
173 my $cds_file = Bio::SeqIO->new(-format =>'embl',
174 -file => test_input_file('cds_sample.embl'));
175 my $cds_seq = $cds_file->next_seq;
176 ok(defined $cds_seq);
177 is($cds_seq->display_id, 'EAL24309');
178 is($cds_seq->accession_number, 'CH236947.1', 'CDS - accession on PA line');
179 is($cds_seq->alphabet, 'dna');
180 is($cds_seq->length, 192);
181 is($cds_seq->species->binomial(), 'Homo sapiens');
182 is($cds_seq->seq_version, 1);
183 is($cds_seq->feature_count, 2);
184 my $cds_annot = $cds_seq->annotation;
185 ok(defined $cds_annot);
186 my $cds_dblink = ($cds_annot->get_Annotations('dblink'))[0];
187 ok(defined $cds_dblink);
188 is($cds_dblink->tagname, 'dblink', 'CDS - OX tagname');
189 is($cds_dblink->database, 'NCBI_TaxID', 'CDS - OX database');
190 is($cds_dblink->primary_id, '9606', 'CDS - OX primary_id');
192 #bug 2982 - parsing contig descriptions sans sequence data
194 ok( $embl = Bio::SeqIO->new( -file => test_input_file('bug2982.embl'),
195 -format => 'embl') );
197 for ($i=0; my $seq = $embl->next_seq; $i++) {
199 ok ( my $ann = ($seq->annotation->get_Annotations('contig'))[0] );
200 like $ann->value, qr/join\(/;
205 # bug 3086 - parsing long lines correctly
207 ok( $embl = Bio::SeqIO->new(-file => test_input_file('bug3086.embl'),
209 -verbose => '$verbose') );
210 $seq = $embl->next_seq;
211 foreach my $feature ($seq->top_SeqFeatures) {
212 if ($feature->has_tag('product')) {
213 my ($product) = $feature->get_tag_values('product');
215 'bifunctional phosphoribosylaminoimidazolecarboxamide formyltransferase/IMP cyclohydrolase',
216 'Check if product was parsed correctly');
220 # long labels handled
223 # Create sequence with feature with a long label qualifier
224 my $seq=Bio::Seq->new(-seq=>'actg');
225 my $feature=Bio::SeqFeature::Generic->new(-primary=>'CDS', -start=>1, -end=>4);
226 $feature->add_tag_value(label=>'1 2 3 4 5 6 7 8 9 a b c d e f g h i j k l m n o p q r');
227 $seq->add_SeqFeature($feature);
231 open my $str_fh, '>', \$string or skip("Could not write string, skipping", 2);
233 my $out=Bio::SeqIO->new(-format=>'embl', -fh => $str_fh);
234 $out->write_seq($seq);
237 my $in=Bio::SeqIO->new(-format=>'embl', -string => $string);
238 my $ret=eval { my $embl=$in->next_seq };
240 $error=$@ if (!$ret);
241 ok($ret, 'Parse long qualifier');
245 # NCBI TaxIDs should roundtrip
247 my $seq=Bio::Seq->new(-seq=>'actg');
248 my $species = Bio::Species->new(-ncbi_taxid => 7165, -classification=>
249 [ 'Anopheles gambiae', 'Anopheles', 'Culicoidea',
250 'Nematocera', 'Diptera', 'Endopterygota',
251 'Neoptera', 'Pterygota', 'Insecta', 'Hexapoda',
252 'Arthropoda', 'Metazoa', 'Eukaryota' ]);
254 $seq->species($species);
255 is($seq->species->ncbi_taxid, 7165, 'TaxID set correctly');
259 open my $str_fh, '>', \$string or skip("Could not write string, skipping", 2);
261 my $out=Bio::SeqIO->new(-format=>'embl', -fh => $str_fh);
262 $out->write_seq($seq);
265 my $in=Bio::SeqIO->new(-format=>'embl', -string => $string);
267 my $ret=eval { $embl_seq=$in->next_seq };
269 $error=$@ if (!$ret);
271 # Check that TaxID has roundtripped
272 my $embl_species = $embl_seq->species;
273 ok(defined $embl_species, "The read sequence has a species object");
274 is($embl_species->ncbi_taxid, 7165, "NCBI TaxID has roundtripped");
275 is($embl_species->binomial(), 'Anopheles gambiae', "Name has roundtripped");
278 # a taxon db_xref on a source feature should override an OX line
280 my $seq=Bio::Seq->new(-seq=>'actg');
281 my $species = Bio::Species->new(-ncbi_taxid => 7165, -classification=>
282 [ 'Anopheles gambiae', 'Anopheles', 'Culicoidea',
283 'Nematocera', 'Diptera', 'Endopterygota',
284 'Neoptera', 'Pterygota', 'Insecta', 'Hexapoda',
285 'Arthropoda', 'Metazoa', 'Eukaryota' ]);
287 $seq->species($species);
288 is($seq->species->ncbi_taxid, 7165, 'TaxID set correctly');
290 my $seq_feature = Bio::SeqFeature::Generic->new(-primary=>'source',
292 -end=> length($seq->seq));
294 $seq_feature->add_tag_value('db_xref', 'taxon:9606');
295 $seq->add_SeqFeature($seq_feature);
299 open my $str_fh, '>', \$string or skip("Could not write string, skipping", 2);
301 my $out=Bio::SeqIO->new(-format=>'embl', -fh => $str_fh);
302 $out->write_seq($seq);
305 my $in=Bio::SeqIO->new(-format=>'embl', -string => $string);
307 my $ret=eval { $embl_seq=$in->next_seq };
309 $error=$@ if (!$ret);
311 # Check that TaxID has roundtripped
312 my $embl_species = $embl_seq->species;
313 ok(defined $embl_species, "The read sequence has a species object");
314 is($embl_species->ncbi_taxid, 9606, "The taxid of the source feature overrides that of the OX line");
315 is($embl_species->binomial(), 'Anopheles gambiae', "Name has roundtripped");
318 # Handle Seq objects that only define an ID, not an accession number
320 my $seq = Bio::Seq->new(-seq=>'actg', -id=>'test_id');
323 open my $str_fh, '>', \$string or skip("Could not write string, skipping", 1);
325 my $out = Bio::SeqIO->new(-format=>'embl', -fh=>$str_fh);
326 $out->write_seq($seq);
328 ok($string =~ m/ID test_id;/, "The ID field was written correctly");
331 # Test lenient handling of space after '=' sign in qualifiers:
333 my $ent = Bio::SeqIO->new( -file => test_input_file('test_space.embl'),
336 eval { $seq = $ent->next_seq(); };
338 is($error, '', 'EMBL format with space after equal sign parses');
340 my ($feature)=$seq->all_SeqFeatures;
341 is($feature->primary_tag, 'CDS', 'CDS read');
343 ok($feature->has_tag('product'), '/product found');
345 my ($value)=$feature->get_tag_values('product');
346 is($value, 'somewordandt extthatisquite lon gandthereforewraps', 'Qualifier /product value matches');