Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??

Enlightened Monks, I have recently taken up Perl programming and i am falling in love with it. I am learning new things every day and having a blast;).

Today i am writing in order to obtain some wisdom on my current topic. My task is to write a fairly simple Perl program that 1) Opens a large 1000 genome file. 2) Opens 75 different Files each with 50 IDentifiers 3) In a loop...Starting with File 1 Identifier 1 if (File 1 ID 1 matches 2nd column of the 1000 genome file) extract the whole line from the 1000 genome file and store it in an output that is labeled File1_out. Lastly increase the ID to the 2nd element of 50. Do this for all the identifier in File 1, then after 50th ID open File2 and do the same thing again. Basically do this for all of the 75 Files. I think i should only open each of the files one time and work with arrays. Below is my script that i have been working/struggling on for a couple of days. I know the task can be done in under 10 lines but i have over complicated my code and need some help. Below is what i have done so far. Please share some of your ideas oh wise monks.

#!/usr/bin/perl $CHR_NUM = $ARGV[0]; $file_location = "/home/ALL.chr$CHR_NUM.phase1_release_v3.20101123.snp +s_indels_svs.genotypes.vcf.gz"; for $x (1..75) { open (FH, "/home/raj/HAPLOTYPES_JAN_2015/PROG_1_Approach_2/C22 +-$x")|| die "Cannot"; while (<FH>){ chomp $_; push (@{$x} , $_);#this loop opens the 75 files with i +dentifier and stores in arrays } } open(IN, "zcat $file_location |") || die "can't open CHROMOSOME $CHR_N +UM input file 1000G!"; $g=1; $z=0; while (<IN>) { $choice = 1; $x=$g; $y=$z; chomp $_; $counter ++; LABEL: if ($choice == 1){ if ($counter > 29) { # print "$_\n"; @currentline = split (/\t/, $_); #print "$currentline[1]\n"; for $r($x..75) { # $r will be used as the name +s for files 1-75 for $t ($y..$#$r) { if ($currentline[1] == $$r[$t] +) { open ($r,">>$r"); print $r "$_\n"; $z = $t++; $choice = 0; goto LABEL; } } } } } if ($z >= $#$x){ $g = $x++; $z = $y = 0; close $r; if ($x==76){# last; } } }

I know this should be done using only several lines but my shortcut techniques are still not advanced. Any wisdom will be greatly appreciated.

In reply to Dear Venerable Monks by A1 Transcendence

Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":

  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or or How to display code and escape characters are good places to start.
Log In?

What's my password?
Create A New User
Domain Nodelet?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (5)
As of 2022-01-23 18:18 GMT
Find Nodes?
    Voting Booth?
    In 2022, my preferred method to securely store passwords is:

    Results (64 votes). Check out past polls.