Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister

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.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://998927]
[Discipulus]: marioroy did you know zentara is back to themonastery? he was used to be one of the best parallel programming monks
[makita]: sign_types parameter in XML::Compile::WSS ::Signature Does have anybody experience how to use it?
[makita]: Need to sign more elements but all types I put in array are ignored. And is always signed only the body
[Discipulus]: no makita sorry. i see in the synopsis of the module: "WARNING: Only limited real-life experience" might be better compose a SOPW with some code example and data
[Discipulus]: ..or inspect the source code of the module

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (10)
As of 2017-03-23 08:41 GMT
Find Nodes?
    Voting Booth?
    Should Pluto Get Its Planethood Back?

    Results (285 votes). Check out past polls.