Skip to content

Commit

Permalink
add client config and BED type parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
Mitch Skinner committed Jun 12, 2009
1 parent ee9501f commit f64a330
Showing 1 changed file with 24 additions and 15 deletions.
39 changes: 24 additions & 15 deletions bin/flatfile-to-json.pl
Original file line number Diff line number Diff line change
@@ -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 <<USAGE;
USAGE: $0 [--gff <gff3 file> | --gff2 <gff2 file> | --bed <bed file>] [--out <output directory>] --tracklabel <track identifier> --key <human-readable track name> [--cssclass <CSS class for displaying features>] [--autocomplete none|label|alias|all] [--type] [--phase] [--subs] [--featlabel] [--urltemplate "http://example.com/idlookup?id={id}"] [--subfeatureClasses <JSON-syntax subfeature class map>]
USAGE: $0 [--gff <gff3 file> | --gff2 <gff2 file> | --bed <bed file>] [--out <output directory>] --tracklabel <track identifier> --key <human-readable track name> [--cssclass <CSS class for displaying features>] [--autocomplete none|label|alias|all] [--getType] [--getPhase] [--getSubs] [--getLabel] [--urltemplate "http://example.com/idlookup?id={id}"] [--subfeatureClasses <JSON-syntax subfeature class map>] [--clientConfig <JSON-syntax extra configuration for FeatureTrack>]
--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,36 +138,32 @@
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)) {
@queryArgs = ("-types" => $types);
}

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",

0 comments on commit f64a330

Please sign in to comment.