#!/bin/csh -ef
#
# bcgscSageLoad db XXX_u.map ...
#
# Loaded tables for the BCGSC Embronic Stem Cell LongSAGE tracks.  Data file
# format is described in the bcgscSageToBed awk script.  These files are named
# in the form SHE15_u.map and will be loaded into a table named escLongSageSHE15.
# the files may also be gzipped.
#

# find path to directory containing conversion script
set script=`which $0`
set scriptDir=$script:h

set db=$argv[1]
shift
set liftSpec=/cluster/data/$db/jkStuff/liftAll.lft

foreach map ($argv[*])
    echo processing $map
    set lib=`echo $map:t|sed -e 's/_.*$//'`
    if ($map =~ *.gz) then
        set cat=zcat
    else
        set cat=cat
    endif
    $cat $map | $scriptDir/bcgscSageToBed -prefix=${lib}. \
        | liftUp  -ignoreVersions -type=.bed8 -nosort stdout $liftSpec error stdin \
        | hgLoadBed -tab -strict -noNameIx $db escLongSage$lib stdin
    rm -f bed.tab 
end
