Light has asked for the wisdom of the Perl Monks concerning the following question:
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
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Does the output exist in a hash or array?
by Riales (Hermit) on Mar 19, 2012 at 17:11 UTC | |
by Light (Initiate) on Mar 20, 2012 at 09:57 UTC |