Good Morning Monks. Here is my code:
#!/usr/bin/perl #because everyone says its important to include in code use warnings; use strict; use Data::Dumper; #---------------------------------------------------- #print "Enter the input file name: "; [OLD CODE] #my $filename = <STDIN>; [OLD CODE] #chomp ($filename); [OLD CODE] #---------------------------------------------------- #link to input file from command line - 2 arguments or error displayed +; Set to respective variables @ARGV == 2 or die "Invalid number or arguments. Program will now termi +nate."; my ($filter_file, $input_file) = @ARGV; ############################################### # STORE CRITERIA FOR FILTERING INPUT FILE # ############################################### open (FILTER,"$filter_file"); my @filter; <FILTER>; # read one line from the file while (<FILTER>) { # read other lines chomp; # remove "\n" from the end of the line push @filter,[(split /\t/,$_)]; # create an array of the line by +splitting it by <TAB>, make a reference of it and push the reference +to the @filter array } @filter = sort { $a->[4] <=> $b->[4] } @filter; # sort the array #--------------------------------------------------------------------- +----- #PRINTS REFERENCES TO ARRAY FROM LEAST TO GREATEST REGARDING 'ORDER' C +OLUMN #print Dumper \@filter; #print $filter[0]->[0], "\n"; #--------------------------------------------------------------------- +----- ############################################### # LOAD INPUT FILE FOR PROCESSING # ############################################### open (IN, "$input_file") or die "Cannot open file: $!"; #variables my $x=0; my @keys; my @holder; my @array_hash; my $blank = "-"; #my $threshold=.03; #my $nonsyn = "nonsynonymous"; #********************************************* #set relationship operators to variables # HOW ?!?!?!?!?!?!?! #********************************************* #open output file - Given name: OUTPUT_"input_file" or error displaye +d if file cannot be created open (OUTFILE, ">OUTPUT_$input_file") or die "Cannot create an output +file: $!"; #Column headers stored as keys; Can be called to retrieve data in spec +ified column #Hashes are put into an array; each hash is an array row; while(my $line = <IN>) { chomp($line); $x++; if ($x==1) { print OUTFILE $line, "\n"; (@keys)=split(/\t/, $line); } else { my $y=0; (@holder) = split(/\t/, $line); my %hash; for my $column (@holder) { $hash{$keys[$y]}=$column; $y++; } #************************************************************* +******* #HOW TO COMBINE PROCESSING BLANKS AND RELATIONSHIPS IN ONE STE +P?????? #************************************************************* +******* if ($hash{$filter[0]->[0]} eq $blank) { print OUTFILE $line, "\n"; } if ($hash{$filter[0]->[0]} le $filter[0]->[2]) { print OUTFILE $line, "\n"; } if ($hash{$filter[1]->[0]} eq $blank) { print OUTFILE $line, "\n"; } if ($hash{$filter[1]->[0]} eq $filter[1]->[2]) { print OUTFILE $line, "\n"; } } }
I have a tab delim file containing the following data:
column relationship value filter_or_append order a <= 0.3 filter 1 b = abc append 3 c <= 0.3 filter 2
Basically, in the beginning of the program, a filter file will be read in, and sorted through the order column and ordered from least to greatest. Each value of the filter file will be store in a variable. Then the program will read in an input file which will be processed based on the criteria defined in the filter file. Ex. the program will first read in the filter file. For column a (order #1) the user wants the program to filter through that specific column for values less than or eq to 0.3. Then the program will move on to order #2. Then the program will move on to order #3 but for this specific column, will search for anything that eq 'abc' and append it to the output file.
My question is: I can pull up the "relationship' (Ex. <=, =, etc.) for any specific column but later on in my program when I make the comparisons, how do format the variable to be used in an IF statement. Ex.
if ($hash{$filter[0]->[0]} le $filter[0]->[2]) { print OUTFILE $line, "\n"; }
if the hash of column a is less than or equal to the value specified in the filter file, print line. My concern is this. I manually type "le" into the code. However, if I pulled out $filter[0]->[1] and printed that value it would be "<=". I need to be able to use this value in the If statement. Ex.
if ($hash{$filter[0]->[0]} $filter[0]->[1] $filter[0]->[2]) { print OUTFILE $line, "\n"; }
How would one go about doing this? Thank you!
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |