Skip to content

Commit

Permalink
add better tests for --type filtering argument to flatfile-to-json.pl
Browse files Browse the repository at this point in the history
  • Loading branch information
rbuels committed Mar 7, 2012
1 parent ac9613d commit 6200533
Showing 1 changed file with 102 additions and 66 deletions.
168 changes: 102 additions & 66 deletions tests/perl_tests/flatfile-to-json.pl.t
Original file line number Diff line number Diff line change
Expand Up @@ -4,75 +4,111 @@ use warnings;
use Test::More;

use File::Spec::Functions 'catfile';
use File::Temp;
use File::Temp ();
use File::Copy::Recursive 'dircopy';

use JsonGenerator;

my $tempdir = File::Temp->newdir( CLEANUP => $ENV{KEEP_ALL} ? 0 : 1 );
diag "using temp dir $tempdir";
my $read_json = sub { JsonGenerator::readJSON( catfile( $tempdir, @_ ) ) };
dircopy( 'tests/data/volvox_formatted_refseqs', $tempdir );

system $^X, 'bin/flatfile-to-json.pl', (
'--out' => $tempdir,
'--bed' => 'sample_data/raw/volvox/volvox-remark.bed',
'--trackLabel' => 'ExampleFeatures',
'--key' => 'Example Features',
'--autocomplete' => 'all',
'--cssClass' => 'feature2',
'--clientConfig' => '{"featureCss": "height: 8px;", "histScale": 2}',
);

ok( ! $?, 'flatfile-to-json.pl ran ok on the volvox bed' );

system $^X, 'bin/flatfile-to-json.pl', (
'--out' => $tempdir,
'--gff' => 'sample_data/raw/volvox/volvox.gff3',
'--trackLabel' => 'CDS',
'--key' => 'Predicted genes',
'--type' => 'CDS:predicted,mRNA:exonerate,mRNA:predicted',
'--autocomplete' => 'all',
'--cssClass' => 'cds',
'--getPhase',
'--getSubfeatures',
);

ok( ! $?, 'flatfile-to-json.pl ran ok on the volvox gff3' );

my $hist_output = $read_json->(qw( tracks ExampleFeatures ctgA hist-10000-0.json ));
is_deeply( $hist_output, [4,3,4,3,4,1], 'got right histogram output' ) or diag explain( $hist_output );

my $names_output = $read_json->(qw( tracks ExampleFeatures ctgA names.json ));
is_deeply( $names_output->[3],
[
[
'f05'
],
'ExampleFeatures',
'f05',
'ctgA',
4715,
5968,
undef
],
'got the right names output'
) or diag explain $names_output;

my $cds_trackdata = $read_json->(qw( tracks CDS ctgA trackData.json ));
is( $cds_trackdata->{featureCount}, 3, 'got right feature count' ) or diag explain $cds_trackdata;
is( ref $cds_trackdata->{intervals}{nclist}[2][9], 'ARRAY', 'exonerate mRNA has its subfeatures' )
or diag explain $cds_trackdata;
is( scalar @{$cds_trackdata->{intervals}{nclist}[2][9]}, 5, 'exonerate mRNA has 5 subfeatures' );

is_deeply( $read_json->('trackList.json')->{tracks}[1]{config}{style},
{ featureCss => 'height: 8px;',
histScale => 2,
className => 'feature2',
},
'--clientConfig option seems to work'
) or diag explain $read_json->('trackList.json');

#system "find $tempdir";
sub run_with(@) {
system $^X, 'bin/flatfile-to-json.pl', @_;
ok( ! $?, 'flatfile-to-json.pl ran ok' );
}

sub tempdir {
my $tempdir = File::Temp->newdir( CLEANUP => $ENV{KEEP_ALL} ? 0 : 1 );
#diag "using temp dir $tempdir";
return $tempdir;
}

{ #diag "running on volvox";

my $tempdir = tempdir();
my $read_json = sub { JsonGenerator::readJSON( catfile( $tempdir, @_ ) ) };
dircopy( 'tests/data/volvox_formatted_refseqs', $tempdir );

run_with (
'--out' => $tempdir,
'--bed' => 'sample_data/raw/volvox/volvox-remark.bed',
'--trackLabel' => 'ExampleFeatures',
'--key' => 'Example Features',
'--autocomplete' => 'all',
'--cssClass' => 'feature2',
'--clientConfig' => '{"featureCss": "height: 8px;", "histScale": 2}',
);

run_with (
'--out' => $tempdir,
'--gff' => 'sample_data/raw/volvox/volvox.gff3',
'--trackLabel' => 'CDS',
'--key' => 'Predicted genes',
'--type' => 'CDS:predicted,mRNA:exonerate,mRNA:predicted',
'--autocomplete' => 'all',
'--cssClass' => 'cds',
'--getPhase',
'--getSubfeatures',
);

my $hist_output = $read_json->(qw( tracks ExampleFeatures ctgA hist-10000-0.json ));
is_deeply( $hist_output, [4,3,4,3,4,1], 'got right histogram output' ) or diag explain( $hist_output );

my $names_output = $read_json->(qw( tracks ExampleFeatures ctgA names.json ));
is_deeply( $names_output->[3],
[
[
'f05'
],
'ExampleFeatures',
'f05',
'ctgA',
4715,
5968,
undef
],
'got the right names output'
) or diag explain $names_output;

my $cds_trackdata = $read_json->(qw( tracks CDS ctgA trackData.json ));
is( $cds_trackdata->{featureCount}, 3, 'got right feature count' ) or diag explain $cds_trackdata;
is( ref $cds_trackdata->{intervals}{nclist}[2][9], 'ARRAY', 'exonerate mRNA has its subfeatures' )
or diag explain $cds_trackdata;
is( scalar @{$cds_trackdata->{intervals}{nclist}[2][9]}, 5, 'exonerate mRNA has 5 subfeatures' );

is_deeply( $read_json->('trackList.json')->{tracks}[1]{config}{style},
{ featureCss => 'height: 8px;',
histScale => 2,
className => 'feature2',
},
'--clientConfig option seems to work'
) or diag explain $read_json->('trackList.json');

#system "find $tempdir";
}

{# diag "running on single_au9_gene.gff3, testing --type filtering";

my $tempdir = tempdir();
dircopy( 'tests/data/AU9', $tempdir );

run_with (
'--out' => $tempdir,
'--gff' => "tests/data/AU9/single_au9_gene.gff3",
'--trackLabel' => 'AU_mRNA',
'--key' => 'AU mRNA',
'--type' => 'mRNA',
'--autocomplete' => 'all',
'--cssClass' => 'transcript',
'--getPhase',
'--getSubfeatures',
);

#system "find $tempdir";

my $read_json = sub { JsonGenerator::readJSON( catfile( $tempdir, @_ ) ) };
my $cds_trackdata = $read_json->(qw( tracks AU_mRNA Group1.33 trackData.json ));
is( $cds_trackdata->{featureCount}, 1, 'got right feature count' ) or diag explain $cds_trackdata;
is( ref $cds_trackdata->{intervals}{nclist}[0][9], 'ARRAY', 'mRNA has its subfeatures' )
or diag explain $cds_trackdata;
is( scalar @{$cds_trackdata->{intervals}{nclist}[0][9]}, 7, 'mRNA has 7 subfeatures' );
}

done_testing;

0 comments on commit 6200533

Please sign in to comment.