#!/usr/bin/perl use warnings; use strict; use autodie; use Data::Dumper; @ARGV == 2 or die "Invalid number of arguments. Please re-run program and suppy as arguments \n1) the filter file and \n2) the input file."; my ($filter_file, $input_file) = @ARGV; open (my $FILTER,"<","$filter_file") or die "Cannot open filter file: $!"; my @filter_array; <$FILTER>; while (my $line = <$FILTER>) { chomp $line; my @line_array = split(/\t/, $line); push (@filter_array, \@line_array); } @filter_array = sort { $a->[5] <=> $b->[5]} @filter_array; #print Dumper \@filter_array, "\n"; #[DEBUGGING] my $num_elements = (@filter_array-1); #print "$num_elements", "\n"; #[DEBUGGING] open (IN,"<","$input_file") or die "Cannot open input file: $!"; open (OUTFILE, ">>", "OUTPUT_$input_file") or die "Cannot create an output file: $!"; for (my $i=0; $i<=$num_elements; $i++) { my $search_string = $filter_array[$i][0]; # print "$search_string", "\n"; my $header = ; my @header_titles = split /\t/, $header; my $extract_col = 0; for my $header_line (@header_titles) { last if $header_line =~ m/$search_string/; $extract_col++; } print "Extracting column $extract_col\n"; while (my $row = ) { last unless $row =~ /\S/; chomp $row; my @cells = split /\t/, $row; # print "$cells[$extract_col]\n"; if ((eval "$cells[$extract_col] $filter_array[$i][1] $filter_array[$i][2]")) { print OUTFILE "$cells[$extract_col]", "\n"; } } }