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

Uploaded
author mcharles
date Wed, 08 Oct 2014 09:06:53 -0400
parents ad321ff1b67d
children
line wrap: on
line diff
--- a/rapsodyn/listfiltering.pl	Wed Sep 10 08:10:38 2014 -0400
+++ b/rapsodyn/listfiltering.pl	Wed Oct 08 09:06:53 2014 -0400
@@ -1,47 +1,51 @@
 #!/usr/bin/perl
+# v1.0.1 added log, and two different type of filtering (common / specific)
 use strict;
 use Getopt::Long;
 
-my $inputfile;
-my $headerfile;
-my $nb_col=1;
+my $list1_file;
+my $list2_file;
+my $log_file;
+my $NB_COL=1;
+my $TYPE = "common";
 my %header;
+my $nb_list1 = 0;
+my $nb_list2 = 0;
+my $nb_common = 0;
 
-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
+"list1_file=s" => \$list1_file,
+"list2_file=s" => \$list2_file,
+"log_file=s" => \$log_file,
+"type=s" => \$TYPE,
+"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>){
+open(L2, $list2_file)  or die("Can't open $list2_file\n");
+while (my $line=<L2>){
+	$nb_list2++;
 	chomp($line);
 	my @fields = split(/\s+/,$line);
 	my $ref="";
 	my $compt=0;
-	while ($compt<$nb_col){
+	while ($compt<$NB_COL){
 		if ($ref){$ref.="\t";}
 		$ref.=$fields[$compt];
 		$compt++;
 	}
-	# my $ref = "$fields[0]\t$fields[1]";
 	$header{$ref}=$line;
 }
-close (HF);
+close (L2);
 
 
-open(IF, $inputfile)  or die("Can't open $inputfile\n");
-while (my $line=<IF>){
+open(L1, $list1_file)  or die("Can't open $list1_file\n");
+while (my $line=<L1>){
+	$nb_list1++;
 	my @fields = split(/\s+/,$line);
 	my $ref="";
 	my $compt=0;
-	while ($compt<$nb_col){
+	while ($compt<$NB_COL){
 		if ($ref){$ref.="\t";}
 		$ref.=$fields[$compt];
 		$compt++;
@@ -49,13 +53,34 @@
 	# my $ref = "$fields[0]\t$fields[1]";
 
 	if ($header{$ref}){
-		# print $line;
-		# print $header{$ref},"\n";
+		$nb_common++;
+		if ($TYPE eq "common"){
+			print $line;
+		}
+		elsif ($TYPE eq "specific") {
+		}
+		else {
+		}
 	}
 	else {
-		print $line;
+		if ($TYPE eq "common"){
+		}
+		elsif ($TYPE eq "specific") {
+			print $line;
+		}
+		else {
+		}
 	}
 	
 }
-close(IF);
+my $nb_list1_only = $nb_list1 - $nb_common;
+my $nb_list2_only = $nb_list2 - $nb_common;
 
+close(L1);
+open (LF,">$log_file") or die("Can't open $log_file\n");
+print LF "\n####\t List Filtering \n";
+print LF "#List 1 :\t$nb_list1 ($nb_list1_only)\n";
+print LF "#List 2 :\t$nb_list2 ($nb_list2_only)\n";
+print LF "#Common :\t$nb_common\n";
+close (LF);
+