Mercurial > repos > mcharles > rapsosnp
comparison rapsodyn/listfiltering.pl @ 8:d857538d9fea draft
Uploaded
author | mcharles |
---|---|
date | Fri, 10 Oct 2014 07:05:36 -0400 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
7:3f7b0788a1c4 | 8:d857538d9fea |
---|---|
1 #!/usr/bin/perl | |
2 # v1.0.1 added log, and two different type of filtering (common / specific) | |
3 use strict; | |
4 use Getopt::Long; | |
5 | |
6 my $list1_file; | |
7 my $list2_file; | |
8 my $log_file; | |
9 my $NB_COL=1; | |
10 my $TYPE = "common"; | |
11 my %header; | |
12 my $nb_list1 = 0; | |
13 my $nb_list2 = 0; | |
14 my $nb_common = 0; | |
15 | |
16 | |
17 GetOptions ( | |
18 "list1_file=s" => \$list1_file, | |
19 "list2_file=s" => \$list2_file, | |
20 "log_file=s" => \$log_file, | |
21 "type=s" => \$TYPE, | |
22 "nb_col=i" => \$NB_COL | |
23 ) or die("Error in command line arguments\n"); | |
24 | |
25 open(L2, $list2_file) or die("Can't open $list2_file\n"); | |
26 while (my $line=<L2>){ | |
27 $nb_list2++; | |
28 chomp($line); | |
29 my @fields = split(/\s+/,$line); | |
30 my $ref=""; | |
31 my $compt=0; | |
32 while ($compt<$NB_COL){ | |
33 if ($ref){$ref.="\t";} | |
34 $ref.=$fields[$compt]; | |
35 $compt++; | |
36 } | |
37 $header{$ref}=$line; | |
38 } | |
39 close (L2); | |
40 | |
41 | |
42 open(L1, $list1_file) or die("Can't open $list1_file\n"); | |
43 while (my $line=<L1>){ | |
44 $nb_list1++; | |
45 my @fields = split(/\s+/,$line); | |
46 my $ref=""; | |
47 my $compt=0; | |
48 while ($compt<$NB_COL){ | |
49 if ($ref){$ref.="\t";} | |
50 $ref.=$fields[$compt]; | |
51 $compt++; | |
52 } | |
53 # my $ref = "$fields[0]\t$fields[1]"; | |
54 | |
55 if ($header{$ref}){ | |
56 $nb_common++; | |
57 if ($TYPE eq "common"){ | |
58 print $line; | |
59 } | |
60 elsif ($TYPE eq "specific") { | |
61 } | |
62 else { | |
63 } | |
64 } | |
65 else { | |
66 if ($TYPE eq "common"){ | |
67 } | |
68 elsif ($TYPE eq "specific") { | |
69 print $line; | |
70 } | |
71 else { | |
72 } | |
73 } | |
74 | |
75 } | |
76 my $nb_list1_only = $nb_list1 - $nb_common; | |
77 my $nb_list2_only = $nb_list2 - $nb_common; | |
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 |