#!/usr/bin/perl -w
use strict;
use warnings;
my $usage=<<USAGE;
Usage:
perl get_motif_file.pl gene_name /path/to/all.motif_file /path/to/motifFile
USAGE
if(@ARGV==0){die $usage};
my $file1=$ARGV[0];
my $file2=$ARGV[1];
my $file3=$ARGV[2];
my @data;
open(RF,$file2) || die $!;
open(WF,">process.txt") || die $!;
while(my $line=<RF>){
chomp($line);
push @data, $line;
my $temp="\t";
push @data, $temp;
}
print WF @data;
close(RF);
close(WF);
open(RF,"process.txt") || die $!;
open(WF,">process_1.txt") || die $!;
while (my $line=<RF>){
my @arr=split(/>/,$line);
for my $i (1..$#arr){
print WF ">".$arr[$i]."\n";
}
}
close(RF);
close(WF);
my $g=0;
open(RF,"process_1.txt") || die $!;
open(WF,">".$file3) || die $!;
while(my $line=<RF>){
chomp($line);
my @arr=split(/\t/,$line);
my @gene=split(/\(/,$arr[1]);
if ($gene[0] eq $file1){
for my $i (0..4){
print WF $arr[$i]."\t";
}
print WF $arr[5]."\n";
for my $j (6..$#arr){
if ($g <= 2){
print WF $arr[$j]."\t";
}
if ($g==3){
print WF $arr[$j]."\n";
$g=0;
next;
}
$g=$g+1;
}
}
}
close(RF);
close(WF);