comparison rapsodyn/listfiltering.pl @ 29:7b8646f46010 draft

Uploaded
author mcharles
date Wed, 08 Oct 2014 09:06:53 -0400
parents ad321ff1b67d
children
comparison
equal deleted inserted replaced
28:fefe6d89dbf1 29:7b8646f46010
1 #!/usr/bin/perl 1 #!/usr/bin/perl
2 # v1.0.1 added log, and two different type of filtering (common / specific)
2 use strict; 3 use strict;
3 use Getopt::Long; 4 use Getopt::Long;
4 5
5 my $inputfile; 6 my $list1_file;
6 my $headerfile; 7 my $list2_file;
7 my $nb_col=1; 8 my $log_file;
9 my $NB_COL=1;
10 my $TYPE = "common";
8 my %header; 11 my %header;
12 my $nb_list1 = 0;
13 my $nb_list2 = 0;
14 my $nb_common = 0;
9 15
10 if ($#ARGV<0){
11 print "\n";
12 print "perl 021_ListFiltering.pl -input_file <file> -header_file <file> -nb_col <integer>[1]\n";
13 exit(0);
14 }
15 16
16 GetOptions ( 17 GetOptions (
17 "input_file=s" => \$inputfile, 18 "list1_file=s" => \$list1_file,
18 "header_file=s" => \$headerfile, 19 "list2_file=s" => \$list2_file,
19 "nb_col=i" => \$nb_col 20 "log_file=s" => \$log_file,
21 "type=s" => \$TYPE,
22 "nb_col=i" => \$NB_COL
20 ) or die("Error in command line arguments\n"); 23 ) or die("Error in command line arguments\n");
21 24
22 open(HF, $headerfile) or die("Can't open $headerfile\n"); 25 open(L2, $list2_file) or die("Can't open $list2_file\n");
23 while (my $line=<HF>){ 26 while (my $line=<L2>){
27 $nb_list2++;
24 chomp($line); 28 chomp($line);
25 my @fields = split(/\s+/,$line); 29 my @fields = split(/\s+/,$line);
26 my $ref=""; 30 my $ref="";
27 my $compt=0; 31 my $compt=0;
28 while ($compt<$nb_col){ 32 while ($compt<$NB_COL){
29 if ($ref){$ref.="\t";} 33 if ($ref){$ref.="\t";}
30 $ref.=$fields[$compt]; 34 $ref.=$fields[$compt];
31 $compt++; 35 $compt++;
32 } 36 }
33 # my $ref = "$fields[0]\t$fields[1]";
34 $header{$ref}=$line; 37 $header{$ref}=$line;
35 } 38 }
36 close (HF); 39 close (L2);
37 40
38 41
39 open(IF, $inputfile) or die("Can't open $inputfile\n"); 42 open(L1, $list1_file) or die("Can't open $list1_file\n");
40 while (my $line=<IF>){ 43 while (my $line=<L1>){
44 $nb_list1++;
41 my @fields = split(/\s+/,$line); 45 my @fields = split(/\s+/,$line);
42 my $ref=""; 46 my $ref="";
43 my $compt=0; 47 my $compt=0;
44 while ($compt<$nb_col){ 48 while ($compt<$NB_COL){
45 if ($ref){$ref.="\t";} 49 if ($ref){$ref.="\t";}
46 $ref.=$fields[$compt]; 50 $ref.=$fields[$compt];
47 $compt++; 51 $compt++;
48 } 52 }
49 # my $ref = "$fields[0]\t$fields[1]"; 53 # my $ref = "$fields[0]\t$fields[1]";
50 54
51 if ($header{$ref}){ 55 if ($header{$ref}){
52 # print $line; 56 $nb_common++;
53 # print $header{$ref},"\n"; 57 if ($TYPE eq "common"){
58 print $line;
59 }
60 elsif ($TYPE eq "specific") {
61 }
62 else {
63 }
54 } 64 }
55 else { 65 else {
56 print $line; 66 if ($TYPE eq "common"){
67 }
68 elsif ($TYPE eq "specific") {
69 print $line;
70 }
71 else {
72 }
57 } 73 }
58 74
59 } 75 }
60 close(IF); 76 my $nb_list1_only = $nb_list1 - $nb_common;
77 my $nb_list2_only = $nb_list2 - $nb_common;
61 78
79 close(L1);
80 open (LF,">$log_file") or die("Can't open $log_file\n");
81 print LF "\n####\t List Filtering \n";
82 print LF "#List 1 :\t$nb_list1 ($nb_list1_only)\n";
83 print LF "#List 2 :\t$nb_list2 ($nb_list2_only)\n";
84 print LF "#Common :\t$nb_common\n";
85 close (LF);
86