Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Re: Hash making

by friedo (Prior)
on Sep 21, 2008 at 04:40 UTC ( #712801=note: print w/ replies, xml ) Need Help??


in reply to Hash making

my $snp_covered{$mismatch}= $snp_chip_covered; ...doesn't make sense.

You'll need to declare your hash as a lexical (my) variable outside the loop, so it won't get clobbered each time through. Then you can add keys to it in the normal way.

However, I don't quite understand what you're trying to do with %snp_covered. You're using the same key each time ($mismatch, which is 3) and overwriting the previous value each time there's a match. If you just want to keep track of the total number of matches, you can use a plain scalar and just increment it each time:

my $count; while(<INPUT2>){ chomp; my @current_line = split /\t/; my $mismatch =3; next unless $current_line[5] == 1 && $current_line[14] >= $mismatch; $count++; }


Comment on Re: Hash making
Select or Download Code
Re^2: Hash making
by sesemin (Beadle) on Sep 21, 2008 at 04:52 UTC
    Thanks Friedo,

    I think was not clear enough. I just put $mismatch = 3 to test if I can create a loop. So at each $mismatch, I will have a series of line extracted let's say 1000000 for $mismatch =1.

    Then when mismatch changes to 2, another set of lines will be extracted. let's say 700000.

    The goal is to have has with keys = different $mismatches and values number of lines extracted.

    Any further help is appreciated.

      So at each $mismatch

      I don't understand "being at a variable".

      I will have a series of line extracted let's say 1000000 for $mismatch =1.

      How do you determine how many lines to extract?

      Then when mismatch changes to 2, another set of lines will be extracted. let's say 700000.

      What causes $mismatch to change?

      I will have a series of line extracted

      I don't understand "extracting a line". Do you mean "reading a line"? What do with the lines you've extracted?

        Let's look at the following code. Up to counter1++ and forget the rest for now. with the conditions set (unless), I am taking those lines that are qualified. Counter1 gives me the number of counts for those lines (value for a hash). If I can iterate through $current_line14 >= and change the value of 3 (which is fixed here) I will get different counts. Therefore by each change at value of current_line14 >= you will get a different count. So your hash keys become your loop values from 3..30 for example and values will be the number of lines extracted. If I want to change "3" manually I have to perform the while loop 20 - 30 times for each key in order to get the counts.
        while(<INPUT2>){ chomp; my @current_line = split /\t/; # eliminate unqualified lines early next unless $current_line[5] == 1 && $current_line[14] >= 3; $counter1++; if ($file1{ $current_line[1]}) { my ($from, $to) = @{ $file1{ $current_line[1] } }; for ($from <= $current_line[2] && $current_line[2] <= $to) { print join("\t", $current_line[1],$current_line[5],$current_line[14 +], "***",$current_line[2]), "\n"; $lines++; } } }

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (5)
As of 2014-12-21 21:10 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (108 votes), past polls