1 # -*-Perl-*- Test Harness script for Bioperl
9 test_begin(-tests => 100);
11 use_ok('Bio::SeqIO::embl');
14 my $verbose = test_debug();
16 my $ast = Bio::SeqIO->new( -format => 'embl',
18 -file => test_input_file('roa1.dat'));
19 $ast->verbose($verbose);
20 my $as = $ast->next_seq();
22 is($as->display_id, 'HSHNCPA1');
23 is($as->accession_number, 'X79536');
24 is($as->seq_version, 1);
26 is($as->desc, 'H.sapiens mRNA for hnRNPcore protein A1');
27 is($as->molecule, 'RNA');
28 is($as->alphabet, 'rna');
29 is(scalar $as->all_SeqFeatures(), 4);
30 is($as->length, 1198);
31 is($as->species->binomial(), 'Homo sapiens');
33 # EMBL Release 87 changes (8-17-06)
35 $ast = Bio::SeqIO->new( -format => 'embl',
37 -file => test_input_file('roa1_v2.dat'));
38 $ast->verbose($verbose);
39 $as = $ast->next_seq();
41 # accession # same as display name now
42 is($as->display_id, 'X79536');
43 is($as->accession_number, 'X79536');
44 is($as->seq_version, 1);
46 is($as->desc, 'H.sapiens mRNA for hnRNPcore protein A1');
48 is($as->molecule, 'mRNA');
49 is($as->alphabet, 'rna');
50 is(scalar $as->all_SeqFeatures(), 4);
51 is($as->length, 1198);
52 is($as->species->binomial(), 'Homo sapiens');
54 my $ent = Bio::SeqIO->new( -file => test_input_file('test.embl'),
56 my $seq = $ent->next_seq();
58 is(defined $seq->seq(), 1,
59 'success reading Embl with ^ location and badly split double quotes');
60 is(scalar $seq->annotation->get_Annotations('reference'), 3);
62 my $out_file = test_output_file();
63 my $out = Bio::SeqIO->new(-file=> ">$out_file",
65 is($out->write_seq($seq),1,
66 'success writing Embl format with ^ < and > locations');
69 $ent = Bio::SeqIO->new( -file => test_input_file('test.embl'),
71 $seq = $ent->next_seq();
74 is(lc($seq->subseq(1,10)),'gatcagtaga');
75 is($seq->length, 4870);
78 my $noFH = Bio::SeqIO->new( -file => test_input_file('no_FH.embl'),
80 is(scalar($noFH->next_seq->get_SeqFeatures), 4);
83 $ent = Bio::SeqIO->new( -format => 'embl',
84 -file => test_input_file('test.embl2sq'));
85 is($ent->next_seq->length,4877);
88 $ent = Bio::SeqIO->new(-file => test_input_file('BEL16-LTR_AG.embl'), -format => 'embl');
89 $seq = $ent->next_seq;
90 is($seq->display_id,'BEL16-LTR_AG');
92 # test secondary accessions in EMBL (bug #1332)
93 my $seqio = Bio::SeqIO->new( -format => 'embl',
94 -file => test_input_file('ECAPAH02.embl'));
95 $seq = $seqio->next_seq;
96 is($seq->accession_number, 'D10483');
97 is($seq->seq_version, 2);
98 my @accs = $seq->get_secondary_accessions();
99 is($accs[0], 'J01597');
100 is($accs[-1], 'X56742');
102 ### TPA TESTS - Thanks to Richard Adams ###
103 # test Third Party Annotation entries in EMBL/Gb format
104 # to ensure compatability with parsers.
105 my $str = Bio::SeqIO->new( -format =>'embl',
106 -file => test_input_file('BN000066-tpa.embl'));
107 $seq = $str->next_seq;
109 is($seq->accession_number, 'BN000066');
110 is($seq->alphabet, 'dna');
111 is($seq->display_id, 'AGA000066');
112 is($seq->length, 5195);
113 is($seq->division, 'INV');
114 is($seq->get_dates, 2);
115 is($seq->keywords, 'acetylcholinesterase; achE1 gene; Third Party Annotation; TPA.');
116 is($seq->seq_version, 1);
117 is($seq->feature_count, 15);
119 my $spec_obj = $seq->species;
120 is ($spec_obj->common_name, 'African malaria mosquito');
121 is ($spec_obj->species, 'gambiae');
122 is ($spec_obj->genus, 'Anopheles');
123 is ($spec_obj->binomial, 'Anopheles gambiae');
125 my $ac = $seq->annotation;
126 my $reference = ($ac->get_Annotations('reference') )[1];
127 is ($reference->title,'"A novel acetylcholinesterase gene in mosquitoes codes for the insecticide target and is non-homologous to the ace gene in Drosophila"');
128 is ($reference->authors,'Weill M., Fort P., Berthomi eu A., Dubois M.P., Pasteur N., Raymond M.');
129 my $cmmnt = ($ac->get_Annotations('comment') )[0];
130 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) ');
133 $ent = Bio::SeqIO->new( -file => test_input_file('test.embl'),
135 $ent->verbose($verbose);
136 $seq = $ent->next_seq();
137 my $species = $seq->species();
138 my @cl = $species->classification();
139 is( $cl[3] ne $species->genus(), 1, 'genus duplication test');
143 ## read-write - test embl writing of a PrimarySeq
145 my $primaryseq = Bio::PrimarySeq->new( -seq => 'AGAGAGAGATA',
149 -accession_number => 'myaccession');
153 $verbose = -1 unless $ENV{'BIOPERLDEBUG'}; # silence warnings unless we are debuggin
155 my $embl = Bio::SeqIO->new(-format => 'embl',
156 -verbose => $verbose,
157 -file => ">$out_file");
159 ok($embl->write_seq($primaryseq));
161 # this should generate a warning
164 $embl->write_seq($scalar);
169 # (which have nonstandard 'PA' and 'OX' tags)
170 # see http://bioperl.org/pipermail/bioperl-l/2009-February/029252.html
171 # and the rest of that thread
172 my $cds_file = Bio::SeqIO->new(-format =>'embl',
173 -file => test_input_file('cds_sample.embl'));
174 my $cds_seq = $cds_file->next_seq;
175 ok(defined $cds_seq);
176 is($cds_seq->display_id, 'EAL24309');
177 is($cds_seq->accession_number, 'CH236947.1', 'CDS - accession on PA line');
178 is($cds_seq->alphabet, 'dna');
179 is($cds_seq->length, 192);
180 is($cds_seq->species->binomial(), 'Homo sapiens');
181 is($cds_seq->seq_version, 1);
182 is($cds_seq->feature_count, 2);
183 my $cds_annot = $cds_seq->annotation;
184 ok(defined $cds_annot);
185 my $cds_dblink = ($cds_annot->get_Annotations('dblink'))[0];
186 ok(defined $cds_dblink);
187 is($cds_dblink->tagname, 'dblink', 'CDS - OX tagname');
188 is($cds_dblink->database, 'NCBI_TaxID', 'CDS - OX database');
189 is($cds_dblink->primary_id, '9606', 'CDS - OX primary_id');
191 #bug 2982 - parsing contig descriptions sans sequence data
193 ok( $embl = Bio::SeqIO->new( -file => test_input_file('bug2982.embl'),
194 -format => 'embl') );
196 for ($i=0; my $seq = $embl->next_seq; $i++) {
198 ok ( my $ann = ($seq->annotation->get_Annotations('contig'))[0] );
199 like $ann->value, qr/join\(/;
204 # bug 3086 - parsing long lines correctly
206 ok( $embl = Bio::SeqIO->new(-file => test_input_file('bug3086.embl'),
208 -verbose => '$verbose') );
209 $seq = $embl->next_seq;
210 foreach my $feature ($seq->top_SeqFeatures) {
211 if ($feature->has_tag('product')) {
212 my ($product) = $feature->get_tag_values('product');
214 'bifunctional phosphoribosylaminoimidazolecarboxamide formyltransferase/IMP cyclohydrolase',
215 'Check if product was parsed correctly');
219 # long labels handled
222 # Create sequence with feature with a long label qualifier
223 my $seq=Bio::Seq->new(-seq=>'actg');
224 my $feature=Bio::SeqFeature::Generic->new(-primary=>'CDS', -start=>1, -end=>4);
225 $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');
226 $seq->add_SeqFeature($feature);
230 open my $str_fh, '>', \$string or skip("Could not write string, skipping", 2);
232 my $out=Bio::SeqIO->new(-format=>'embl', -fh => $str_fh);
233 $out->write_seq($seq);
236 my $in=Bio::SeqIO->new(-format=>'embl', -string => $string);
237 my $ret=eval { my $embl=$in->next_seq };
239 $error=$@ if (!$ret);
240 ok($ret, 'Parse long qualifier');
244 # NCBI TaxIDs should roundtrip
246 my $seq=Bio::Seq->new(-seq=>'actg');
247 my $species = Bio::Species->new(-ncbi_taxid => 7165, -classification=>
248 [ 'Anopheles gambiae', 'Anopheles', 'Culicoidea',
249 'Nematocera', 'Diptera', 'Endopterygota',
250 'Neoptera', 'Pterygota', 'Insecta', 'Hexapoda',
251 'Arthropoda', 'Metazoa', 'Eukaryota' ]);
253 $seq->species($species);
254 is($seq->species->ncbi_taxid, 7165, 'TaxID set correctly');
258 open my $str_fh, '>', \$string or skip("Could not write string, skipping", 2);
260 my $out=Bio::SeqIO->new(-format=>'embl', -fh => $str_fh);
261 $out->write_seq($seq);
264 my $in=Bio::SeqIO->new(-format=>'embl', -string => $string);
266 my $ret=eval { $embl_seq=$in->next_seq };
268 $error=$@ if (!$ret);
270 # Check that TaxID has roundtripped
271 my $embl_species = $embl_seq->species;
272 ok(defined $embl_species, "The read sequence has a species object");
273 is($embl_species->ncbi_taxid, 7165, "NCBI TaxID has roundtripped");
274 is($embl_species->binomial(), 'Anopheles gambiae', "Name has roundtripped");
277 # a taxon db_xref on a source feature should override an OX line
279 my $seq=Bio::Seq->new(-seq=>'actg');
280 my $species = Bio::Species->new(-ncbi_taxid => 7165, -classification=>
281 [ 'Anopheles gambiae', 'Anopheles', 'Culicoidea',
282 'Nematocera', 'Diptera', 'Endopterygota',
283 'Neoptera', 'Pterygota', 'Insecta', 'Hexapoda',
284 'Arthropoda', 'Metazoa', 'Eukaryota' ]);
286 $seq->species($species);
287 is($seq->species->ncbi_taxid, 7165, 'TaxID set correctly');
289 my $seq_feature = Bio::SeqFeature::Generic->new(-primary=>'source',
291 -end=> length($seq->seq));
293 $seq_feature->add_tag_value('db_xref', 'taxon:9606');
294 $seq->add_SeqFeature($seq_feature);
298 open my $str_fh, '>', \$string or skip("Could not write string, skipping", 2);
300 my $out=Bio::SeqIO->new(-format=>'embl', -fh => $str_fh);
301 $out->write_seq($seq);
304 my $in=Bio::SeqIO->new(-format=>'embl', -string => $string);
306 my $ret=eval { $embl_seq=$in->next_seq };
308 $error=$@ if (!$ret);
310 # Check that TaxID has roundtripped
311 my $embl_species = $embl_seq->species;
312 ok(defined $embl_species, "The read sequence has a species object");
313 is($embl_species->ncbi_taxid, 9606, "The taxid of the source feature overrides that of the OX line");
314 is($embl_species->binomial(), 'Anopheles gambiae', "Name has roundtripped");
317 # Handle Seq objects that only define an ID, not an accession number
319 my $seq = Bio::Seq->new(-seq=>'actg', -id=>'test_id');
322 open my $str_fh, '>', \$string or skip("Could not write string, skipping", 1);
324 my $out = Bio::SeqIO->new(-format=>'embl', -fh=>$str_fh);
325 $out->write_seq($seq);
327 ok($string =~ m/ID test_id;/, "The ID field was written correctly");
330 # Test lenient handling of space after '=' sign in qualifiers:
332 my $ent = Bio::SeqIO->new( -file => test_input_file('test_space.embl'),
335 eval { $seq = $ent->next_seq(); };
337 is($error, '', 'EMBL format with space after equal sign parses');
339 my ($feature)=$seq->all_SeqFeatures;
340 is($feature->primary_tag, 'CDS', 'CDS read');
342 ok($feature->has_tag('product'), '/product found');
344 my ($value)=$feature->get_tag_values('product');
345 is($value, 'somewordandt extthatisquite lon gandthereforewraps', 'Qualifier /product value matches');