7 test_begin( -tests=>44,
8 -requires_modules => [qw(Bio::Phylo)]);
9 use_ok( 'Bio::PrimarySeq' );
10 use_ok('Bio::SeqIO::nexml'); # checks that your module is there and loads ok
14 ok( my $SeqStream = Bio::SeqIO->new(-file => test_input_file("characters.nexml.xml"), -format => 'nexml'), 'stream ok');
16 #checking first sequence object
17 ok( my $seq_obj = $SeqStream->next_seq(), 'seq obj' );
18 isa_ok($seq_obj, 'Bio::Seq');
19 is( $seq_obj->alphabet, 'dna', "alphabet" );
20 is( $seq_obj->primary_id, 'DNA sequences.seq_1', "primary_id");
21 is( $seq_obj->display_id, 'DNA sequences.seq_1', "display_id");
22 is( $seq_obj->seq, 'ACGCTCGCATCGCATC', "sequence");
24 my %expected_taxa = ('Homo sapiens' => 1, 'Pan paniscus' => 1, 'Pan troglodytes' => 1, 'Gorilla gorilla' => 1, 'Pongo pygmaeus' => 1);
25 my $feat = ($seq_obj->get_SeqFeatures())[0];
26 is( ($feat->get_tag_values('taxa_id'))[0], 'taxa1', 'taxa id');
27 is( ($feat->get_tag_values('taxa_label'))[0], 'Primary taxa block', 'taxa label');
28 is( ($feat->get_tag_values('my_taxon'))[0], 'Homo sapiens', "taxon ok" );
29 my @taxa = $feat->get_tag_values('taxon');
30 is( @taxa, 5, 'number of taxa');
31 foreach my $taxon (@taxa) {
32 ok( $expected_taxa{$taxon}, 'taxon ok')
35 #checking second sequence object
36 ok( $seq_obj = $SeqStream->next_seq() );
37 is( $seq_obj->alphabet, 'dna', "alphabet" );
38 is( $seq_obj->primary_id, 'DNA sequences.seq_2', "primary_id");
39 is( $seq_obj->display_id, 'DNA sequences.seq_2', "display_id");
40 is( $seq_obj->seq, 'ACGCTCGCATCGCATC', "sequence");
41 $SeqStream->next_seq();
42 $SeqStream->next_seq();
44 #checking fifth sequence object
45 ok( $seq_obj = $SeqStream->next_seq() );
46 is( $seq_obj->alphabet, 'rna', "alphabet" );
47 is( $seq_obj->primary_id, 'RNA sequences.seq_2', "primary_id");
48 is( $seq_obj->display_id, 'RNA sequences.seq_2', "display_id defaults to primary");
49 is( $seq_obj->seq, 'ACGCUCGCAUCGCAUC', "sequence");
53 diag('Begin tests for writing seq files');
54 my $outdata = test_output_file();
55 ok( my $outSeqStream = Bio::SeqIO->new(-file => ">$outdata", -format => 'nexml'), 'out stream ok');
56 ok( $outSeqStream->write_seq($seq_obj), 'write nexml seq');
59 #Read in the out file to test roundtrip
60 my $inSeqStream = Bio::SeqIO->new(-file => $outdata, -format => 'nexml');
62 #checking fifth sequence object
63 ok( my $seq_obj2 = $inSeqStream->next_seq() );
64 is( $seq_obj2->alphabet, 'rna', "alphabet" );
65 is( $seq_obj2->primary_id, 'RNA sequences.seq_2', "primary_id");
66 is( $seq_obj2->display_id, 'RNA sequences.seq_2', "display_id defaults to primary");
67 is( $seq_obj2->seq, 'ACGCUCGCAUCGCAUC', "sequence");
70 my $feat1 = ($seq_obj2->get_SeqFeatures())[0];
71 is( ($feat1->get_tag_values('taxa_id'))[0], 'taxa1', 'taxa id');
72 is( ($feat1->get_tag_values('taxa_label'))[0], 'Primary taxa block', 'taxa label');
73 is( ($feat1->get_tag_values('my_taxon'))[0], 'Pan paniscus', "taxon ok" );
74 my @taxa2 = $feat1->get_tag_values('taxon');
75 is( @taxa2, 5, 'number of taxa');
76 foreach my $taxon (@taxa2) {
77 ok( $expected_taxa{$taxon}, 'taxon ok')