in reply to How to make a hash to evaluate columns between large datasets
Hi rambosauce and welcome to the monastery.
I'm a perl noviceI wouldn't have guessed that, your code is quite well written.
To answer your question, here is something you can do:
(Edit: untested for lack of input data)my %transcripts; { open(my $transcripts_fh, "<", $transcripts_qfn) or die("Can't open \"$transcripts_qfn\": $!\n"); while (<$transcripts_fh>) { chomp; my @refs = split(/\t/, $_); my ($ref_chr, $ref_strand) = @refs[0, 6]; $transcripts{$ref_chr}{$ref_strand} = {start => $refs[3], end => + $refs[4], info => $refs[8]}; } }
That's assuming that $ref_chr and $ref_strand are a unique pair. If you can have several start/end/info values for a given chr-strand pair, you'll have to use an intermediate array (I didn't want to give the more complex solution if the simple one is enough).my $transcript = $transcripts{$chr}{$strand}; my $start = $transcript->{start}; my $end = $transcript->{end}; my $info = $transcript->{info};
FYI, for debugging you can easer have something like:
oruse Data::Dump "pp"; ... say pp \%transcripts; # debug the content of %transcripts
The first looks nicer, but Data::Dumper doesn't require an installation.use Data::Dumper; ... say Dumper \%transcripts;
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: How to make a hash to evaluate columns between large datasets
by rambosauce (Novice) on Aug 23, 2018 at 13:08 UTC | |
by Eily (Monsignor) on Aug 23, 2018 at 13:15 UTC | |
by rambosauce (Novice) on Aug 23, 2018 at 21:17 UTC | |
by FreeBeerReekingMonk (Deacon) on Aug 25, 2018 at 00:30 UTC | |
by rambosauce (Novice) on Aug 23, 2018 at 13:50 UTC |