[BUG] bug 2598
[bioperl-live.git] / t / Assembly.t
blobbd665088e6993ea6d2270043eb131e2af0799f84
1 # -*-Perl-*- Test Harness script for Bioperl
2 # $Id$
4 use strict;
6 BEGIN {
7     use lib 't/lib';
8     use BioperlTest;
9     
10     test_begin(-tests => 35,
11         -requires_module => 'DB_File');
12         
13         use_ok('Bio::Assembly::IO');
17 # Testing IO
21 my $in = Bio::Assembly::IO->new
22         (-file => test_input_file("consed_project","edit_dir","test_project.phrap.out"));
24 isa_ok($in, 'Bio::Assembly::IO');
26 my $sc = $in->next_assembly;
27 isa_ok($sc, 'Bio::Assembly::Scaffold');
30 # Testing Scaffold
34 is $sc->id, "NoName";
35 is $sc->id('test'), "test";
37 isa_ok($sc->annotation, 'Bio::AnnotationCollectionI');
38 is $sc->annotation->get_all_annotation_keys, 0,"no annotations in Annotation collection?";
39 is $sc->get_nof_contigs, 1;
40 is $sc->get_nof_sequences_in_contigs, 2;
42 TODO: {
43         local $TODO = "get_nof_singlets() should return a number";
44         is($sc->get_nof_singlets, 1, "get_nof_singlets");
46 is($sc->get_seq_ids, 2, "get_seq_ids");
47 is($sc->get_contig_ids, 1, "get_contig_ids");
48 TODO: {
49         local $TODO = "get_singlet_ids() should return a list";
50         isnt $sc->get_singlet_ids, 0;
52         
54 # Testing Contig
58 # Testing ContigAnalysis
62 # Testing Ace 
65 my $aio = Bio::Assembly::IO->new(
66         -file=>test_input_file("consed_project","edit_dir","test_project.fasta.screen.ace.2"),
67         -format=>'ace',
70 my $assembly = $aio->next_assembly();
71 my @contigs = $assembly->all_contigs();
73 my $direction = $contigs[0]->strand;
74 is $direction, 1;
76 my $features =  $contigs[0]->get_features_collection;
77 my @contig_features = $features->get_all_features;
78 is @contig_features, 8;
80 my @annotations = grep {$_->primary_tag eq 'Annotation'} @contig_features;
81 is @annotations, 2;
82 my $had_tag = 0;
83 foreach my $an (@annotations) {
84         if ($an->has_tag('extra_info')) {
85                 $had_tag++;
86                 is (($an->get_tag_values('extra_info'))[0], "contig extra\ninfo\n");
87         }
88         elsif ($an->has_tag('comment')){
89                 $had_tag++;
90                 is (($an->get_tag_values('comment'))[0], "contig tag\ncomment\n");
91         }
93 is $had_tag, 2;
96 # Testing TIGR format
99 # Importing an assembly
101 my $asm_in = Bio::Assembly::IO->new(
102     -file => test_input_file("sample_dataset.tasm "),
103     -format=>'tigr'
105 my $scaf_in = $asm_in->next_assembly;
107 isa_ok($scaf_in, 'Bio::Assembly::Scaffold');
108 is($scaf_in->id, 'NoName');
109 is($scaf_in->get_nof_contigs, 13);
110 is($scaf_in->get_nof_sequences_in_contigs, 36);
111 is($scaf_in->get_nof_singlets, 0);
112 my @seqids = sort qw(sdsu|SDSU1_RFPERU_001_A09.x01.phd.1
113 sdsu|SDSU1_RFPERU_001_B03.x01.phd.1 sdsu|SDSU1_RFPERU_001_B04.x01.phd.1
114 sdsu|SDSU1_RFPERU_001_E04.x01.phd.1 sdsu|SDSU_RFPERU_002_A01.x01.phd.1
115 sdsu|SDSU_RFPERU_002_B07.x01.phd.1 sdsu|SDSU_RFPERU_002_C12.x01.phd.1
116 sdsu|SDSU_RFPERU_002_D08.x01.phd.1 sdsu|SDSU_RFPERU_002_H12.x01.phd.1
117 sdsu|SDSU_RFPERU_003_G09.x01.phd.1 sdsu|SDSU_RFPERU_004_H12.x01.phd.1
118 sdsu|SDSU_RFPERU_005_F02.x01.phd.1 sdsu|SDSU_RFPERU_006_D03.x01.phd.1
119 sdsu|SDSU_RFPERU_006_E04.x01.phd.1 sdsu|SDSU_RFPERU_006_E05.x01.phd.1
120 sdsu|SDSU_RFPERU_006_H08.x01.phd.1 sdsu|SDSU_RFPERU_007_E09.x01.phd.1
121 sdsu|SDSU_RFPERU_007_F06.x01.phd.1 sdsu|SDSU_RFPERU_008_B02.x01.phd.1
122 sdsu|SDSU_RFPERU_009_E07.x01.phd.1 sdsu|SDSU_RFPERU_010_B05.x01.phd.1
123 sdsu|SDSU_RFPERU_010_B06.x01.phd.1 sdsu|SDSU_RFPERU_010_C09.x01.phd.1
124 sdsu|SDSU_RFPERU_010_D10.x01.phd.1 sdsu|SDSU_RFPERU_012_H02.x01.phd.1
125 sdsu|SDSU_RFPERU_013_B05.x01.phd.1 sdsu|SDSU_RFPERU_013_C07.x01.phd.1
126 sdsu|SDSU_RFPERU_013_C08.x01.phd.1 sdsu|SDSU_RFPERU_013_G10.x01.phd.1
127 sdsu|SDSU_RFPERU_013_H05.x01.phd.1 sdsu|SDSU_RFPERU_014_H06.x01.phd.1
128 sdsu|SDSU_RFPERU_015_A05.x01.phd.1 sdsu|SDSU_RFPERU_015_C06.x01.phd.1
129 sdsu|SDSU_RFPERU_015_E04.x01.phd.1 sdsu|SDSU_RFPERU_015_G04.x01.phd.1
130 sdsu|SDSU_RFPERU_015_H03.x01.phd.1);
131 my @contigids = sort qw(106 144 148 17 185 2 210 36 453 500 613 668 93);
132 is_deeply([sort $scaf_in->get_seq_ids], \@seqids);
133 is_deeply([sort $scaf_in->get_contig_ids], \@contigids);
134 is_deeply([$scaf_in->get_singlet_ids], []);
135 isa_ok($scaf_in->get_seq_by_id('sdsu|SDSU1_RFPERU_001_A09.x01.phd.1'),'Bio::LocatableSeq');
136 my $contig = $scaf_in->get_contig_by_id('106');
137 isa_ok($contig,'Bio::Assembly::Contig');
138 # check Contig object SeqFeature::Collection
139 # should add more specific Contig tests...
140 my @sfs = $contig->get_features_collection->get_all_features;
141 is(scalar(@sfs), 5);
142 my %primary_tags = map { $_->primary_tag => 1 } @sfs;
143 ok exists $primary_tags{'_aligned_coord:sdsu|SDSU_RFPERU_006_E04.x01.phd.1'};
144 is($sfs[1]->seq_id(), undef); # should this be undef?
146 isa_ok($scaf_in->annotation, 'Bio::AnnotationCollectionI');
147 is($scaf_in->annotation->get_all_annotation_keys, 0,"no annotations in Annotation collection?");
149 # Exporting an assembly
151 my $asm_outfile = test_output_file();
152 my $asm_out = Bio::Assembly::IO->new(
153     -file=> ">$asm_outfile",
154     -format=>'tigr'
157 ok $asm_out->write_assembly( -scaffold => $scaf_in);