| 1 |
|
| 2 |
|
| 3 |
# usage: ./perl GOmultifiles.pl <GOterm_file> <GOterm2term_file> <folder> <regex> |
| 4 |
|
| 5 |
use strict; |
| 6 |
|
| 7 |
# load GOfunctions |
| 8 |
require GOfunctions; |
| 9 |
GOfunctions::import($ARGV[0],$ARGV[1]); |
| 10 |
|
| 11 |
my $dir = $ARGV[2]; |
| 12 |
opendir(DIR, $dir) or die "could nor open dir: ".$ARGV[2]."\n"; |
| 13 |
my @files = grep (/$ARGV[3]/,readdir(DIR)); |
| 14 |
closedir(DIR); |
| 15 |
|
| 16 |
print @files; |
| 17 |
|
| 18 |
foreach my $file (@files) { |
| 19 |
|
| 20 |
$file = $dir.$file; |
| 21 |
open(INFILE, "<".$file) or die "could not open input file! ($file)\n"; |
| 22 |
open(OUTFILE, "> ".$file.".GOpath") or die "could not open output file! ($file.GOpath)\n"; |
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
# --- same as GOaddpath --- |
| 27 |
|
| 28 |
# -- parameter -- |
| 29 |
my $GOseperator = ','; |
| 30 |
#my $GOprefix = 'GO:'; |
| 31 |
|
| 32 |
|
| 33 |
# -- main loop -- |
| 34 |
|
| 35 |
my $output = ""; |
| 36 |
|
| 37 |
while(my $line=<INFILE>) { |
| 38 |
|
| 39 |
if(substr($line,0,1) eq '#') { |
| 40 |
$output .= $line; |
| 41 |
} else { |
| 42 |
|
| 43 |
my @table = split(/\t/,$line,2); # file "parser" |
| 44 |
my @GO = split($GOseperator,$table[0]); |
| 45 |
|
| 46 |
@GO = GOfunctions::goFilter(@GO); # filter out cellular_components and anything else unusual |
| 47 |
|
| 48 |
@GO = GOfunctions::goAddPath(@GO); # add all GO terms lying on the path to root |
| 49 |
|
| 50 |
@GO = GOfunctions::goFilter(@GO); # filter out anything unusual which might have been added |
| 51 |
|
| 52 |
if($#GO != -1) { # remove empty hits |
| 53 |
$output .= join("\t",join($GOseperator,@GO),$table[1]); |
| 54 |
} |
| 55 |
} |
| 56 |
} |
| 57 |
|
| 58 |
print OUTFILE $output; |
| 59 |
|
| 60 |
# print $output; |
| 61 |
|
| 62 |
close(INFILE); |
| 63 |
close(OUTFILE); |
| 64 |
|
| 65 |
} |