1 # -*-Perl-*- Test Harness script for Bioperl
10 test_begin(-tests => 9);
13 use_ok('Bio::SeqFeature::Tools::Unflattener');
16 my $verbosity = test_debug();
19 my $unflattener = Bio::SeqFeature::Tools::Unflattener->new();
22 my @path = ("AE003644_Adh-genomic.gb");
25 is ($seq->accession_number, 'AE003644');
26 my @topsfs = $seq->get_SeqFeatures;
27 if( $verbosity > 0 ) {
28 warn sprintf "TOP:%d\n", scalar(@topsfs);
33 $unflattener->verbose($verbosity);
34 @sfs = $unflattener->unflatten_seq(-seq=>$seq,
35 -group_tag=>'locus_tag');
36 if( $verbosity > 0 ) {
37 warn "\n\nPOST PROCESSING:\n";
39 warn sprintf "PROCESSED:%d\n", scalar(@sfs);
44 # now try again, using a custom subroutine to link together features
45 $seq = getseq("AE003644_Adh-genomic.gb");
46 @sfs = $unflattener->unflatten_seq
48 -group_tag=>'locus_tag',
52 my ($sf, @candidate_container_sfs) = @_;
53 if ($sf->has_tag('note')) {
54 my @notes = $sf->get_tag_values('note');
55 my @trnames = map {/from transcript\s+(.*)/;
57 @trnames = grep {$_} @trnames;
60 $self->throw("UNRESOLVABLE");
62 elsif (@trnames == 1) {
63 $trname = $trnames[0];
66 $self->throw("AMBIGUOUS: @trnames");
71 $_->has_tag('product') ?
72 $_->get_tag_values('product') :
75 } @candidate_container_sfs;
76 if (@container_sfs == 0) {
77 $self->throw("UNRESOLVABLE");
79 elsif (@container_sfs == 1) {
81 return ($container_sfs[0]=>0);
84 $self->throw("AMBIGUOUS");
88 $unflattener->feature_from_splitloc(-seq=>$seq);
89 if( $verbosity > 0 ) {
90 warn "\n\nPOST PROCESSING:\n";
92 warn sprintf "PROCESSED2:%d\n", scalar(@sfs);
96 # try again; different sequence
97 # this is an E-Coli seq with no mRNA features;
98 # we just want to link all features directly with gene
100 $seq = getseq("D10483.gbk");
103 @sfs = $unflattener->unflatten_seq(-seq=>$seq,
104 -partonomy=>{'*'=>'gene'},
106 if( $verbosity > 0 ) {
107 warn "\n\nPOST PROCESSING:\n";
109 warn sprintf "PROCESSED:%d\n", scalar(@sfs);
113 # this sequence has no locus_tag or or gene tags
114 $seq = getseq("AY763288.gb");
117 @sfs = $unflattener->unflatten_seq(-seq=>$seq,
120 if( $verbosity > 0 ) {
121 warn "\n\nPOST PROCESSING:\n";
123 warn sprintf "PROCESSED:%d\n", scalar(@sfs);
128 # try again; different sequence - dicistronic gene, mRNA record
130 $seq = getseq("X98338_Adh-mRNA.gb");
133 @sfs = $unflattener->unflatten_seq(-seq=>$seq,
134 -partonomy=>{'*'=>'gene'},
136 if( $verbosity > 0 ) {
137 warn "\n\nPOST PROCESSING:\n";
139 warn sprintf "PROCESSED:%d\n", scalar(@sfs);
143 # try again; this sequence has no CDSs but rRNA present
145 $seq = getseq("no_cds_example.gb");
148 @sfs = $unflattener->unflatten_seq(-seq=>$seq,
151 if( $verbosity > 0 ) {
152 warn "\n\nPOST PROCESSING:\n";
154 warn sprintf "PROCESSED:%d\n", scalar(@sfs);
157 my @all_sfs = $seq->get_all_SeqFeatures;
159 my @exons = grep { $_-> primary_tag eq 'exon' } @all_sfs ;
167 _write_hier(0, @sfs);
173 foreach my $sf (@sfs) {
175 if ($sf->has_tag('product')) {
176 ($label) = $sf->get_tag_values('product');
178 warn sprintf "%s%s $label\n", ' ' x $indent, $sf->primary_tag;
179 my @sub_sfs = $sf->sub_SeqFeature;
180 _write_hier($indent+1, @sub_sfs);
187 Bio::SeqIO->new('-file'=> test_input_file(@path),
188 '-format' => 'GenBank');
189 $seqio->verbose($verbosity);
191 my $seq = $seqio->next_seq();