#!/usr/bin/perl

use strict;
use warnings;

# program to take a list of genes, and find all interactions in an interaction file (sif format) 
#     where both interaction genes are in the list

if($#ARGV != 2) {
	print "usage: find_matching_interactions.pl input_gene_list interaction_file output_file\n";
	exit;
}

my $in_file = $ARGV[0];
my $inter_file = $ARGV[1];
my $out_file = $ARGV[2];

# read in the genes to look for
open (in_file, "$in_file");

my %in_hash;
while(<in_file>) {
	my $line = $_;
	chomp $line;
	
	$in_hash{$line} = $line;
}

# read in the interaction file and do the lookups
open (inter_file, "$inter_file");
open (out_file, ">$out_file");

while(<inter_file>) {
	my $line = $_;
	chomp $line;
	my ($inter_1, $type, $inter_2) = split("\t", $line);
	if(defined($in_hash{$inter_1}) && defined($in_hash{$inter_2}) ) {
		print out_file "$line\n";
	}
}
