Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Re: Population of HoAoA based on file contents

by aaron_baugher (Curate)
on May 09, 2012 at 22:10 UTC ( [id://969711]=note: print w/replies, xml ) Need Help??


in reply to Population of HoAoA based on file contents

One quick note: since you only have one header line, and you know it's the first line, there's no need to check for it every time through your loop. Read the header line, process it, and then start your loop on the second line.

I'll assume that you really do want a HoAoA, despite the large empty areas it may have within it. In that case, I'd start by reading that header line and making an array of two-element arrays, the first element containing the first part (here 162), and the second element containing the remainder (87215 for the first one). Then as you go through the rest of the lines, you can easily step through this array to get the indexes you'll need for your HoAoA. When you start having indexes within indexes, that's when it gets mind-stretching, but fun. Something like this:

#!/usr/bin/env perl use Modern::Perl; my %data; # HoAoA holding final data structure my @indexes; # array of indexes into %data based on coord +inates my $header_line = <DATA>; # some of these steps could be combined; chomp $header_line; # including them for clarity my @headers = split ',', $header_line; shift @headers; # throw away SAMPLE for my $n (@headers){ my $x = $n/100_000; my $y = $n % 100_000; push @indexes, [ $x, $y ]; } while(<DATA>){ chomp; my( $id, @bits ) = split ','; for my $i (0..@bits-1){ $data{$id}[$indexes[$i][0]][$indexes[$i][1]] = $bits[$i]; } } say "Expecting 0 0: ", $data{HG00553}[162][87365]; say "Expecting 1 1: ", $data{HG00638}[162][87851]; __DATA__ SAMPLE,16287215,16287226,16287365,16287649,16287784,16287851,16287912 HG00553,0 0,0 0,0 0,0 0,0 0,0 0,0 0 HG00554,0 0,0 0,0 0,0 0,0 0,0 0,0 0 HG00637,0 0,0 0,0 0,0 0,0 0,0 0,0 0 HG00638,0 0,0 0,0 0,0 0,0 0,1 1,0 0 HG00640,0 0,0 0,0 0,0 0,0 0,1 1,0 0

Aaron B.
Available for small or large Perl jobs; see my home node.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://969711]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others scrutinizing the Monastery: (7)
As of 2024-03-28 12:37 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found