Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow generate-names.pl to index utf8 trackLabels #1477

Open
wants to merge 2 commits into
base: dev
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions src/perl5/Bio/JBrowse/Cmd/IndexNames.pm
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ use Storable ();
use File::Path ();
use File::Temp ();
use List::Util ();
use Encode qw(decode encode);

use GenomeDB ();
use Bio::GFF3::LowLevel qw/gff3_parse_feature/;
Expand Down Expand Up @@ -195,8 +196,8 @@ sub _mergeIndexEntries {

sub make_file_record {
my ( $self, $track, $file ) = @_;
-f $file or die "$file not found\n";
-r $file or die "$file not readable\n";
-f decode('UTF-8',$file) or die "$file not found\n";
-r decode('UTF-8',$file) or die "$file not readable\n";
my $gzipped = $file =~ /\.(txt|json|g)z(\.\d+)?$/;
my $type = $file =~ /\.txtz?$/ ? 'txt' :
$file =~ /\.jsonz?$/ ? 'json' :
Expand Down Expand Up @@ -364,7 +365,7 @@ sub find_names_files {
# read either names.txt or names.json files
my $name_records_iterator;
my $names_txt = File::Spec->catfile( $dir, 'names.txt' );
if( -f $names_txt ) {
if( -e decode('UTF-8',$names_txt) ) {
push @files, $self->make_file_record( $track, $names_txt );
}
else {
Expand Down Expand Up @@ -436,8 +437,8 @@ sub make_operation_stream {
#print "sizes: $self->{stats}{total_namerec_bytes}, buffered: $namerecs_buffered, b/rec: ".$total_namerec_sizes/$namerecs_buffered."\n";
$self->{stats}{avg_record_text_bytes} = $self->{stats}{total_namerec_bytes}/($self->{stats}{namerecs_buffered}||1);
$self->{stats}{total_input_bytes} = List::Util::sum(
map { my $s = -s $_->{fullpath};
$s *= 8 if $_->{fullpath} =~ /\.(g|txt|json)z$/;
map { my $s = -s decode('UTF-8',$_->{fullpath});
$s *= 8 if decode('UTF-8',$_->{fullpath}) =~ /\.(g|txt|json)z$/;
$s;
} @$names_files ) || 0;
$self->{stats}{record_stream_estimated_count} = int( $self->{stats}{total_input_bytes} / ($self->{stats}{avg_record_text_bytes}||1));;
Expand Down Expand Up @@ -710,7 +711,7 @@ sub open_names_file {
}
}
else {
open my $fh, '<', $infile or die "$! reading $infile";
open my $fh, '<', decode('UTF-8',$infile) or die "$! reading $infile";
return $fh;
}
}
Expand Down