Hi Monks, My issue revolves around going back to a do{}while loop in my code, I thought I had figured out how to label it and perlsyn corroborated my theory I thought, but I still can't get it to work, as I get the error: {0}: perl putLinesBackInVCF4.pl -1kg CEU.head.txt -knome wo127.head.txt -o output.txt Label not found for "redo LOOP" at putLinesBackInVCF4.pl line 96, <KGFILE> line 20. Here's my code, I've tried to comment it pretty extensively.
#!/usr/bin/perl use strict; use warnings; use Pod::Usage; use Getopt::Long; my $KG_FILE; my $OUTFILE; my $KNOME_FILE; GetOptions( '1kg=s' =>\$KG_FILE, 'knome=s' =>\$KNOME_FILE, 'o=s' =>\$OUTFILE, 'help' =>sub{pod2usage(1);} ) or pod2usage(2); =head SYNOPSIS putLinesBackinVCF.pl Options: -1kg 1000 genomes input vcf file -knome knome file with sites -o output file -help display this message =cut if (!$KG_FILE){ pod2usage(2); die "Please supply an input 1000 genomes file\n"; } if(!$KNOME_FILE){ pod2usage(2); die "Please supply our sites file\n"; } if(!$OUTFILE){ pod2usage(2); die "Please supply an output file\n"; } unless(open( KGFILE, $KG_FILE)){ die "Couldn't create link to 1kg file: $!\n"; } unless(open( KNOME, $KNOME_FILE)){ die "Couldn't create link to knome input file: $!\n"; } unless (open( OUTFILE,">", $OUTFILE)){ die "Couldn't create link to output file: $!\n"; } my $pos = 0; while (<KGFILE>){ if ($_ =~ /^#/){ next; } # skip header lines... my ($kgLine) = $_; chomp $kgLine; my @kgArr = (split("\t", $kgLine))[0,1]; #grab the chrom and posit +ion columns my $chr; my @arr; LOOP: { do{ # go through the KNOME file; # print out the positions till we reach (or exceed) the position f +rom the KGFILE my $line = <KNOME>; if (not defined $line) { last; } chomp $line; @arr = (split("\t", $line))[0,1]; $arr[0] =~ s/^0//; $chr = $arr[0]; #remove leading 0's from chromosome number $pos = $arr[1]+1; #to adjust positions to base 1 rather than + base 0 if ($pos < $kgArr[1]){ print OUTFILE "$chr\t$pos\n"; #probably unncessary if sta +tement but shouldn't hurt anything even if so } } while $pos < $kgArr[1]; } if($kgArr[1] < $pos){ #at this point the position from KNOME is + no longer LESS THAN position from KGFILE print OUTFILE $kgLine,"\n"; while ($kgArr[1] < $pos){ #if last position from KNOME is GREATER THAN position from KGFILE we n +ow need to loop through #and print all the lines from KGFILE until we catch back up to KNOME's + position! my $catchup = (<KGFILE>); chomp $catchup; @kgArr = (split("\t", $catchup))[0,1]; if ($kgArr[1] == $pos){ #If we get to the point where th +ey're equal, good... just print, this while loop will end, and we'll +start the whole process over print OUTFILE $catchup,"\n"; } elsif($kgArr[1] > $pos){ print OUTFILE "$chr\t$pos\n"; redo LOOP ; last; #print OUTFILE "$catchup\n"; #if KGFILE's position has become GREATER than the KNOME $pos again, ho +wever, it gets tricky... # but now we need to go through KNOME file positions again and see if +that position matches later on... # can't just quit the loop or this line will be lost, but we don't rea +lly want to print it here either... # } } } elsif($kgArr[1] == $pos){ print OUTFILE $kgLine,"\n"; } } #if we get to the end of the KGFILE and there's still lines left in th +e KNOME file, just print the rest of those lines chr and pos values; while (<KNOME>){ chomp; my @remainingArr = (split("\t", $_))[0,1]; $remainingArr[0] =~ s/^0//; my $remChr = $remainingArr[0]; my $remPos = $remainingArr[1]+1; print OUTFILE "$remChr\t$remPos\n"; }

In reply to Trouble with do{}while LABELS by aquinom

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



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.