diff --git a/bin/flatfile-to-json.pl b/bin/flatfile-to-json.pl index 1d065d3691..58f58233e8 100755 --- a/bin/flatfile-to-json.pl +++ b/bin/flatfile-to-json.pl @@ -15,7 +15,9 @@ my ($gff, $gff2, $bed, $trackLabel, $key, - $urlTemplate, $subfeatureClasses, $arrowheadClass, $types); + $urlTemplate, $subfeatureClasses, $arrowheadClass, $clientConfig, + $thinType, $thickType, + $types); my $autocomplete = "none"; my $outdir = "data"; my $cssClass = "feature"; @@ -35,12 +37,15 @@ "urltemplate=s" => \$urlTemplate, "arrowheadClass=s" => \$arrowheadClass, "subfeatureClasses=s" => \$subfeatureClasses, + "clientConfig=s" => \$clientConfig, + "thinType=s" => \$thinType, + "thicktype=s" => \$thickType, "type=s@" => \$types); my $trackDir = "$outdir/tracks"; if (!(defined($gff) || defined($gff2) || defined($bed))) { print < | --gff2 | --bed ] [--out ] --tracklabel --key [--cssclass ] [--autocomplete none|label|alias|all] [--type] [--phase] [--subs] [--featlabel] [--urltemplate "http://example.com/idlookup?id={id}"] [--subfeatureClasses ] +USAGE: $0 [--gff | --gff2 | --bed ] [--out ] --tracklabel --key [--cssclass ] [--autocomplete none|label|alias|all] [--getType] [--getPhase] [--getSubs] [--getLabel] [--urltemplate "http://example.com/idlookup?id={id}"] [--subfeatureClasses ] [--clientConfig ] --out: defaults to "data" --cssclass: defaults to "feature" @@ -51,8 +56,10 @@ --getLabel: include a label for the features in the json --urltemplate: template for a URL that clicking on a feature will navigate to --arrowheadClass: CSS class for arrowheads - --subfeatureClasses: CSS classes for each subfeature type, in JSON syntax. + --subfeatureClasses: CSS classes for each subfeature type, in JSON syntax e.g. '{"CDS": "transcript-CDS", "exon": "transcript-exon"}' + --clientConfig: extra configuration for the client, in JSON syntax + e.g. '{"css": "background-color: black;", "histScale": 5}' --type: only process features of the given type USAGE exit(1); @@ -81,7 +88,9 @@ $db = Bio::DB::GFF->new(-adaptor => 'memory', -gff => $gff2); } elsif ($bed) { - $stream = Bio::FeatureIO->new(-format => 'bed', -file => $bed); + $stream = Bio::FeatureIO->new(-format => 'bed', -file => $bed, + ($thinType ? ("-thin_type" => $thinType) : ()), + ($thickType ? ("-thick_type" => $thickType) : ()) ); $streaming = 1; $labelSub = sub { #label sub for features returned by Bio::FeatureIO::bed @@ -102,11 +111,15 @@ "label" => $getLabel ? $labelSub : 0, "key" => defined($key) ? $key : $trackLabel, "urlTemplate" => $urlTemplate, - "arrowheadClass" => $arrowheadClass); + "arrowheadClass" => $arrowheadClass, + "clientConfig" => $clientConfig); $style{subfeature_classes} = JSON::from_json($subfeatureClasses) if defined($subfeatureClasses); +$style{clientConfig} = JSON::from_json($clientConfig) + if defined($clientConfig); + my %perChromGens; foreach my $seqInfo (@refSeqs) { $perChromGens{$seqInfo->{"name"}} = JsonGenerator->new($trackLabel, @@ -125,21 +138,17 @@ next unless $jsonGen; $jsonGen->addFeature($feat); - - #use Data::Dumper; - #print Dumper($feat); - #die; } } foreach my $seqInfo (@refSeqs) { my $seqName = $seqInfo->{"name"}; - print "\nworking on seq $seqName\n"; mkdir("$trackDir/$seqName") unless (-d "$trackDir/$seqName"); my $jsonGen = $perChromGens{$seqName}; - + unless ($streaming) { + print "\nworking on seq $seqName\n"; my $segment = $db->segment("-name" => $seqName); my @queryArgs; if (defined($types)) { @@ -147,14 +156,14 @@ } my @features = $segment->features(@queryArgs); - print "got ", @features+0, " features\n"; - #if (!defined($trackLabel)) { $trackLabel = $features[0]->primary_tag }; $jsonGen->addFeature($_) foreach (@features); } + next if $jsonGen->featureCount == 0; + + print $seqName . "\t" . $jsonGen->featureCount . "\n"; - $jsonGen->generateTrack("$trackDir/$seqName/$trackLabel/", 5000) - if $jsonGen->hasFeatures; + $jsonGen->generateTrack("$trackDir/$seqName/$trackLabel/", 5000); } JsonGenerator::modifyJSFile("$outdir/trackInfo.js", "trackInfo",