The code below does really what I want it to do, but it also adds extra information that I don't want.

The batch file consists of a list of batches that have been run and I need this list to look at folders that have this name.

The list file is a list of samples that I need to get the information from in report files.

The report files is a list of tab delimited results where I need to get the third and 23rd tab. From the first report file I need all the samples that are in the list file. From the second report file I only need the sample that I don’t have already. I know it can be done by using an exist, but I can’t get my head around how it should look like.

Thanks for your help.

#!/usr/bin/perl -w =head Title : apt_SNPCall_report Function : To combine the results from the different reports based on + the batch list. =cut #--------------------------------------------------------------------- +---------- # use and library files use strict; use Getopt::Long; #--------------------------------------------------------------------- +---------- # Get options my ($help, $batch, $list); my $output = "genotyping_results.txt"; my ($good_batch, $out_name, $out_dir_name); my (@list_files, %sample); sub help { print <<EOH; Description: Using the apt_SNP_batch_call will generate reports for each of the sep +arate samples that failed QC together with either samples that passed + QC or HapMap reference samples. This script will combine the results + from each of the report files into one table containing the SNP call + rate and the pm_mean (average intensity). Input files The script will search for the customer samples using Known issues/bug/beware... NA Use: perl $0 [options] Options and arguments: -help this --batch Name of the file that contains the batches used for + genotyping [mandatory] --list File containing the list of CEL files of interest + [mandatory] --output Name of output file + [optional] EOH $help = 1; exit; } #--------------------------------------------------------------------- +---------- # Options: GetOptions( 'help' => \$help, 'batch=s' => \$batch, 'list=s' => \$list, 'output=s' => \$output ); if ((! $batch) or (! $list) or $help){ &help(); } # File opening: open (BATCH, $batch) || die "Cannot open input file $batch: $!\n"; open (LIST, $list) || die "Cannot open input file $list: $!\n"; open (W, ">$output") || die "Error to open $!"; #--------------------------------------------------------------------- +---------- # Script #print W "SampleName\tcall_rate\tpm_mean\n"; print "SampleName\tcall_rate\tpm_mean\n"; while (<LIST>) { chomp; my ($path, $file) = ($_ =~ /(.*\/)(.*)/); push (@list_files, $file); } close LIST; while (<BATCH>) { chomp; s/\r//; my $filename = $_; $out_name = $filename; $out_name =~ s/\.txt//; $out_dir_name = "apt_SNPCall_".$out_name; foreach my $lf (@list_files){ open (SAMPLE, "$out_dir_name/birdseed-v2.report.txt") || die "Erro +r to open: $!"; while (<SAMPLE>) { chomp; my @tab = split("\t", $_); if ($tab[0] eq $lf){ my $sample = $lf; $sample =~ s/\.CEL//; print $sample."\t".$tab[2]."\t".$tab[22]."\n"; #I get problems + here # print W $sample."\t".$tab[2]."\t".$tab[22]."\n"; } } } } close SAMPLE; close W; close BATCH; ################################### # Functions

In reply to Does the output exist in a hash or array? by Light

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.