Mercurial > repos > mcharles > rapsodyn
diff rapsodyn/listfiltering.pl @ 9:ad321ff1b67d draft
Uploaded
author | mcharles |
---|---|
date | Thu, 14 Aug 2014 08:12:06 -0400 |
parents | |
children | 7b8646f46010 |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/rapsodyn/listfiltering.pl Thu Aug 14 08:12:06 2014 -0400 @@ -0,0 +1,61 @@ +#!/usr/bin/perl +use strict; +use Getopt::Long; + +my $inputfile; +my $headerfile; +my $nb_col=1; +my %header; + +if ($#ARGV<0){ + print "\n"; + print "perl 021_ListFiltering.pl -input_file <file> -header_file <file> -nb_col <integer>[1]\n"; + exit(0); +} + +GetOptions ( +"input_file=s" => \$inputfile, +"header_file=s" => \$headerfile, +"nb_col=i" => \$nb_col +) or die("Error in command line arguments\n"); + +open(HF, $headerfile) or die("Can't open $headerfile\n"); +while (my $line=<HF>){ + chomp($line); + my @fields = split(/\s+/,$line); + my $ref=""; + my $compt=0; + while ($compt<$nb_col){ + if ($ref){$ref.="\t";} + $ref.=$fields[$compt]; + $compt++; + } + # my $ref = "$fields[0]\t$fields[1]"; + $header{$ref}=$line; +} +close (HF); + + +open(IF, $inputfile) or die("Can't open $inputfile\n"); +while (my $line=<IF>){ + my @fields = split(/\s+/,$line); + my $ref=""; + my $compt=0; + while ($compt<$nb_col){ + if ($ref){$ref.="\t";} + $ref.=$fields[$compt]; + $compt++; + } + # my $ref = "$fields[0]\t$fields[1]"; + + if ($header{$ref}){ + # print $line; + # print $header{$ref},"\n"; + } + else { + print $line; + } + +} +close(IF); +