Skip to content

Commit

Permalink
Add arbitrary field indexing on gff3tabix tracks ref #1115
Browse files Browse the repository at this point in the history
  • Loading branch information
cmdcolin committed Oct 4, 2018
1 parent 1d08d01 commit 3c89c55
Showing 1 changed file with 17 additions and 9 deletions.
26 changes: 17 additions & 9 deletions src/perl5/Bio/JBrowse/Cmd/IndexNames.pm
Original file line number Diff line number Diff line change
Expand Up @@ -203,10 +203,10 @@ sub make_file_record {
$file =~ /\.vcf(\.gz)?$/ ? 'vcf' :
$file =~ /\.gff3?(\.gz)?(\.\d+)?$/ ? 'gff' :
undef;

if( $type ) {
return {
gzipped => $gzipped,
nameAttributes => $track->{nameAttributes},
fullpath => $file,
type => $type,
trackName => $track->{label}
Expand Down Expand Up @@ -374,9 +374,8 @@ sub find_names_files {
}

# try to detect VCF tracks and index their VCF files
if( $track->{storeClass}
&& ( $track->{urlTemplate} && $track->{urlTemplate} =~ /\.vcf\.gz/
|| $track->{storeClass} =~ /VCFTabix$/ )
if( $track->{urlTemplate} && $track->{urlTemplate} =~ /\.vcf\.gz/
|| ($track->{storeClass}||'') =~ /VCFTabix$/
) {
my $path = File::Spec->catfile( $self->opt('dir'), $track->{urlTemplate} );
if( -r $path ) {
Expand All @@ -388,9 +387,8 @@ sub find_names_files {
}

# try to detect GFF3 tracks and index their GFF3 files
if( $track->{storeClass}
&& ( $track->{urlTemplate} && $track->{urlTemplate} =~ /\.gff3?\.gz(\.\d+)?/
|| $track->{storeClass} =~ /GFF3Tabix$/ )
if( $track->{urlTemplate} && $track->{urlTemplate} =~ /\.gff3?\.gz(\.\d+)?/
|| ($track->{storeClass}||'') =~ /GFF3Tabix$/
) {
my $path = File::Spec->catfile( $self->opt('dir'), $track->{urlTemplate} );
if( -r $path ) {
Expand Down Expand Up @@ -594,7 +592,6 @@ sub make_names_iterator {
my $input_fh = $self->open_names_file( $file_record );
no warnings 'uninitialized';
return sub {

# find the next feature in the file that has a name
my $line;
my $feature;
Expand All @@ -605,7 +602,18 @@ sub make_names_iterator {
$feature = gff3_parse_feature($line);
my $Name = $feature->{attributes}{Name} || [];
my $ID = $feature->{attributes}{ID} || [];
@names = $Name->[0] ? (@$Name, @$ID) : @$ID;
my $Alias = $feature->{attributes}{Alias} || [];
my @fields;
my @computedFields;
if(ref(\$file_record->{nameAttributes}) eq 'ARRAY') {
@fields = $file_record->{nameAttributes}
} elsif(ref(\$file_record->{nameAttributes}) eq 'SCALAR') {
@fields = split /\s*,\s*/, $file_record->{nameAttributes};
}
if(@fields) {
@computedFields = map { $feature->{attributes}{$_} || [] } @fields;
}
@names = @fields ? @computedFields : $Name->[0] ? (@$Name, @$ID) : @$ID;
last if scalar @names;
}
}
Expand Down

0 comments on commit 3c89c55

Please sign in to comment.