Skip to content

Commit

Permalink
added tests/code to set type in features/subfeatures in parsed Genban…
Browse files Browse the repository at this point in the history
…k JSON
  • Loading branch information
justaddcoffee committed Jul 16, 2013
1 parent 7e0dc62 commit 5be9582
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
12 changes: 8 additions & 4 deletions src/perl5/Bio/JBrowse/FeatureStream/Genbank.pm
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ sub _aggregate_features_from_gbk_record {
my $startStop = _extractStartStopFromJoinToken( $f->{FEATURES}->[$indexTopLevel] );
$f->{'start'} = $startStop->[0] + $offset + 1;
$f->{'end'} = $startStop->[1] + $offset;
$f->{'type'} = $f->{FEATURES}->[$indexTopLevel]->{'name'};

# add subfeatures
$f->{'subfeatures'} = ();
Expand All @@ -55,10 +56,13 @@ sub _aggregate_features_from_gbk_record {
$startStop->[0] += $offset;
$startStop->[1] += $offset;
$startStop->[0]++;
my $newFeature = {'start' => $startStop->[0] || 0,
'end' => $startStop->[1] || 0,
'foo' => 'null','foo1' => 'null','foo2' => 'null','foo3' => 'null','foo4' => 'null','foo5' => 'null','foo6' => 'null','foo7' => 'null','foo8' => 'null','foo9' => 'null','foo10' => 'null','foo11' => 'null','foo12' => 'null','foo13' => 'null','foo14' => 'null',
};
my $newFeature = {'start' => $startStop->[0] || 0,
'end' => $startStop->[1] || 0,
'type' => $f->{FEATURES}->[$i]->{'name'} || 'null',
'foo1' => 'null','foo2' => 'null','foo3' => 'null','foo4' => 'null','foo5' => 'null','foo6' => 'null','foo7' => 'null',
'foo8' => 'null','foo9' => 'null','foo10' => 'null','foo11' => 'null','foo12' => 'null','foo13' => 'null','foo14' => 'null',
'foo14' => 'null'
};
push @{$f->{'subfeatures'}}, $newFeature;
}
}
Expand Down
8 changes: 5 additions & 3 deletions tests/perl_tests/flatfile-to-json.pl.t
Original file line number Diff line number Diff line change
Expand Up @@ -348,10 +348,11 @@ for my $testfile ( "tests/data/au9_scaffold_subset.gff3", "tests/data/au9_scaffo
# test start/stop of parent feature (full record)
ok( $trackdata->{'trackData.json'}->{'intervals'}->{'nclist'}->[0]->[1] == 5001, "got right start coordinate (full record)" );
ok( $trackdata->{'trackData.json'}->{'intervals'}->{'nclist'}->[0]->[2] == 10950, "got right stop coordinate (full record)" );
ok( $trackdata->{'trackData.json'}->{'intervals'}->{'nclist'}->[0]->[17] eq 'mRNA', "got right type in parent feature (full record)" );

# test that the right attributes are present
is_deeply( [sort(@{$trackdata->{'trackData.json'}->{'intervals'}->{'classes'}->[0]->{'attributes'}})],
[sort(@{[ 'Start', 'End', 'Strand', 'COMMENT', 'DEFINITION', 'CLASSIFICATION', 'LOCUS', 'FEATURES', 'KEYWORDS', 'SEQUENCE', 'ACCESSION', 'Seq_id', 'NCBI_TAXON_ID', 'MOL_TYPE', 'ORIGIN', 'ORGANISM', 'VERSION', 'SOURCE', 'Subfeatures']})],
[sort(@{[ 'Start', 'End', 'Strand', 'COMMENT', 'DEFINITION', 'CLASSIFICATION', 'LOCUS', 'FEATURES', 'KEYWORDS', 'SEQUENCE', 'ACCESSION', 'Seq_id', 'NCBI_TAXON_ID', 'MOL_TYPE', 'ORIGIN', 'ORGANISM', 'Type', 'VERSION', 'SOURCE', 'Subfeatures']})],
'got the right attributes in trackData.json')
or diag $trackdata->{'trackData.json'}->{'intervals'}->{'classes'}->[0]->{'attributes'};

Expand All @@ -369,12 +370,13 @@ for my $testfile ( "tests/data/au9_scaffold_subset.gff3", "tests/data/au9_scaffo

my $subfeatures = $trackdata->{'trackData.json'}->{'intervals'}->{'nclist'}->[0]->[$actualSubFeatureIndex];
ok ( scalar @{$subfeatures} == 15, "got the right number of subfeatures");
ok ( scalar(@{$subfeatures->[0]}) == scalar(@{$trackdata->{'trackData.json'}->{'intervals'}->{'classes'}->[0]->{'attributes'}}),
"subfeature array is same length as attribute array");
ok ( scalar(@{$subfeatures->[0]}) + 1 == scalar(@{$trackdata->{'trackData.json'}->{'intervals'}->{'classes'}->[0]->{'attributes'}}),
"subfeature array is the right length (length of attribute array + 1)");
# test first subfeature completely
ok ( exists $subfeatures->[0]->[0] && $subfeatures->[0]->[0] == 1, "first item set correctly in subfeature");
ok ( exists $subfeatures->[0]->[1] && $subfeatures->[0]->[1] == 5001, "start set correctly in subfeature") || diag $subfeatures->[0]->[1];
ok ( exists $subfeatures->[0]->[2] && $subfeatures->[0]->[2] == 5114, "end set correctly in subfeature") || diag $subfeatures->[0]->[2];
ok ( exists $subfeatures->[0]->[2] && $subfeatures->[0]->[17] eq 'exon', "type set correctly in subfeature") || diag $subfeatures->[0]->[2];
undef;

}
Expand Down

0 comments on commit 5be9582

Please sign in to comment.