I am trying to create a pipeline using perl script to make calls to various code. The problem I'm facing is that the initial program splits a large data file into separate smaller files (separated by chromosome) so that numerous files are produced (e.g. chr1.out, chr2.out, chr3.out ...). When I was not restricted to the pipeline, I used unix for-loops to cycle through each respective output file in such manner:

for i in {1..24} do perl /home/perl/chr.match.pl chr$i.nonCG.out echo "chr$i" date done

What I am trying to convey here is that each filename is nearly the same except for the specific chr number for each (which is why I cycle through from chr1 to chr24)

However, within the perl script I am having a hard time trying to get the correct language to cycle through each chromosome. I have been using the system() command in perl which allows me to execute separate perl code in the server using the pipeline. I have tried:

system("for i in {1..24} do perl /home/perl/chr.match.pl chr$i.nonCG.out echo "chr$i" date done");

which does not seem to work, and I've also tried:

`for i in {1..24} do perl /home/perl/chr.match.pl chr$i.nonCG.out echo "chr$i" date done`;

because I know using the ` character allows you to enter unix commands. I know I am approaching this the wrong way but I'm having a hard time trying to find a solution. I have already tried to catenate the separated output files and then run the pipeline on one large file, but this method will create problems down the road for me. I've also included a sample to test if necessary:

pipe.test.pl

#!/usr/bin/perl -w # pipe.test.pl use strict; use warnings; open(IN, "<$ARGV[0]") or die "error reading file"; open(OUT, ">$ARGV[1]") or die "error reading file"; while (my $line = <IN>) { chomp($line); my @split = split("\t", $line); if ($split[5] == 1) { print OUT "$line\n"; } } close IN; close OUT;

chr1.in.txt

chr1 100 159 104 104 1 0.05 + chr1 100 159 145 145 0 0.04 + chr1 200 260 205 205 1 0.12 + chr1 500 750 600 600 1 0.09 + chr1 800 900 600 600 1 0.09 +

chr2.in.txt

chr2 100 200 105 105 1 0.03 + chr2 100 200 110 110 1 0.08 + chr2 300 400 350 350 0 0 +

As you can see its a very simple test, and to run it I use the command: "perl pipe.test.pl chr1.in.txt chr1.out.txt" for chr1. Essentially, the goal here is to be able to execute pipe.test.pl from a separate perl script using for-loops to cycle through each chromosome. I hope I am coming across clear to everybody.


In reply to unix loops in perl by a217

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.