#!/bin/csh
set list = $1 # The gene set
set dir = $2 # Directory with the TF targets
if ($# != 2) then
echo "Usage: findOveralp.csh gene-list input-directory"
exit
endif
touch result.$$
# Prepare the list file for the comparison:
sort $list > ! tmp.$$
# Check targets of each TF:
foreach f ($dir/*.targets.txt)
if ( -e $f ) then # Would the flags -f and -d work here?
awk -F '\t' '(FNR>1){print $1}' $f | sort | join tmp.$$ - | awk -v a=$f:t:r:r '{sum++} END{OFS="\t";print a,sum}' >> result.$$
endif
end
rm -f tmp.$$
set n = `cat $list | wc -l`
cat result.$$ | sort -nrk 2 | awk -v a=$n '{print "The TF",$1," Has ",$2,"Target genes (out of a total of",a,")"}'