Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Re^3: hash with both values and keys unique to each other

by perlkhan77 (Acolyte)
on Jul 12, 2012 at 17:15 UTC ( #981450=note: print w/ replies, xml ) Need Help??


in reply to Re^2: hash with both values and keys unique to each other
in thread hash with both values and keys unique to each other

Following is the real code :

use strict; use Time::HiRes; my $start_time = [Time::HiRes::gettimeofday()]; my (@coordinates,%hash_chr,%HOA,%HOH,%hash_line) = (); open FILE,"GmGm.recent.gff"; while(my $line=<FILE>){ chomp $line; my %seen = (); if($line=~/^(Gm\d{1,})\trecent_duplication\tsyntenic_region\t(\d{1,})\ +t(\d{1,})\t.*\tID\=\w{1,}_Gm\d{1,}\.(Gm\d{1,}.*)\;median_Ks=(.*)\;mat +ches\=(Gm\d{1,}\:\d{1,}\.\.\d{1,})/) { my $chr1 = "$1:$2..$3"; my $ks_val = $5; my $chr2 = $6; if ((exists $hash_chr{$chr2})&&($ks_val > 0.4)){ next; } else{ $hash_chr{$chr1}=$chr2; } } } close FILE;

And this is how the file looks like

Gm01 recent_duplication syntenic_region 170877 269340 1 +79 - . ID=A_Gm01.Gm08.2.-;median_Ks=0.1101;matches=Gm08:4628 +8465..46349001 Gm08 recent_duplication syntenic_region 46288465 46349001 + 179 - . ID=B_Gm01.Gm08.2.-;median_Ks=0.1101;matches=Gm01: +170877..269340


Comment on Re^3: hash with both values and keys unique to each other
Select or Download Code
Re^4: hash with both values and keys unique to each other
by hbm (Hermit) on Jul 12, 2012 at 19:38 UTC

    As a side note, you can clean up that regex quite a bit by using + instead of {1,}, and not escaping colons, semi-colons, and equals:

    #if($line=~/^(Gm\d{1,})\trecent_duplication\tsyntenic_region\t(\d{1 +,})\t(\d{1,})\t.*\tID\=\w{1,}_Gm\d{1,}\.(Gm\d{1,}.*)\;median_Ks=(.*)\ +;matches\=(Gm\d{1,}\:\d{1,}\.\.\d{1,})/) if($line=~/^(Gm\d+)\trecent_duplication\tsyntenic_region\t(\d+)\t(\ +d+)\t.*\tID=\w+_Gm\d+\.(Gm\d+.*);median_Ks=(.*);matches=(Gm\d+:\d+\.\ +.\d+)/)

      You could clean it up quite a bit more by splitting the line on tabs and parsing each of the columns individually...

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (8)
As of 2014-11-23 08:54 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My preferred Perl binaries come from:














    Results (129 votes), past polls