Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Re^4: Find overlap

by Kenosis (Priest)
on Oct 14, 2012 at 07:53 UTC ( #998927=note: print w/ replies, xml ) Need Help??


in reply to Re^3: Find overlap
in thread Find overlap

Your solution is an excellent use of a HoH! Here are a few items to consider within your foreach:

foreach (@ARGV) { open my $fh, '<', $_ or die $!; while ( my $line = <$fh> ) { next unless my @p = $line =~ /^(chr.+?)\t+(\d+)\t+(\d+)/; $minmax{ $p[0] }{min} //= $p[1]; $minmax{ $p[0] }{max} //= $p[2]; if ( $p[1] < $minmax{ $p[0] }{min} ) { $minmax{ $p[0] }{min} = $p[1]; } if ( $p[2] > $minmax{ $p[0] }{max} ) { $minmax{ $p[0] }{max} = $p[2]; } } close $fh; }
  • A three-argument open is used
  • A lexically-scoped variable is used for the file handle
  • or die $! checks for open errors
  • The regex line:
    • Skips possible comment and track definition lines in the BED files
    • And then makes using chomp and split unnecessary
  • Uses defined-or-equals (//=) to replace the !exists

Hope this is helpful.


Comment on Re^4: Find overlap
Select or Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (8)
As of 2015-07-07 09:15 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (88 votes), past polls