Mercurial > repos > mcharles > rapsosnp
view rapsodyn/listfiltering.pl @ 1:7f36bd129321 draft
Uploaded
author | mcharles |
---|---|
date | Wed, 10 Sep 2014 10:24:01 -0400 |
parents | 442a7c88b886 |
children |
line wrap: on
line source
#!/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);