#!/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 = ; [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 terminate."; my ($filter_file, $input_file) = @ARGV; ############################################### # STORE CRITERIA FOR FILTERING INPUT FILE # ############################################### open (FILTER,"$filter_file"); my @filter; ; # read one line from the file while () { # 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 , 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' COLUMN #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 displayed 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 specified column #Hashes are put into an array; each hash is an array row; while(my $line = ) { 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 STEP?????? #******************************************************************** 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"; } } } #### column relationship value filter_or_append order a <= 0.3 filter 1 b = abc append 3 c <= 0.3 filter 2 #### if ($hash{$filter[0]->[0]} le $filter[0]->[2]) { print OUTFILE $line, "\n"; } #### if ($hash{$filter[0]->[0]} $filter[0]->[1] $filter[0]->[2]) { print OUTFILE $line, "\n"; }