# for emacs: -*- mode: sh; -*-


# Drosophila sechellia -- 
# 
# Broad's 28 Oct. 2005 assembly
#

#  NOTE:  this doc may have genePred loads that fail to include
#  the bin column.  Please correct that for the next build by adding
#  a bin column when you make any of these tables:
#
#  mysql> SELECT tableName, type FROM trackDb WHERE type LIKE "%Pred%";
#  +-------------+---------------------------------+
#  | tableName   | type                            |
#  +-------------+---------------------------------+
#  | xenoRefGene | genePred xenoRefPep xenoRefMrna |
#  | genscan     | genePred genscanPep             |
#  +-------------+---------------------------------+


# DOWNLOAD SEQUENCE (DONE 11/29/05 angie)
    ssh kkstore02
    mkdir /cluster/store11/droSec1
    cd /cluster/data
    ln -s /cluster/store11/droSec1 droSec1
    cd /cluster/data/droSec1
    mkdir jkStuff bed
    mkdir downloads
    cd downloads
    wget http://www.broad.mit.edu/ftp/pub/assemblies/insects/droSec1/assembly.agp
    wget http://www.broad.mit.edu/ftp/pub/assemblies/insects/droSec1/assembly.links
    wget http://www.broad.mit.edu/ftp/pub/assemblies/insects/droSec1/BasicAssemblyOneLiner.out
    wget http://www.broad.mit.edu/ftp/pub/assemblies/insects/droSec1/assembly.quals.gz
    wget http://www.broad.mit.edu/ftp/pub/assemblies/insects/droSec1/scaffolds.fasta
    mv scaffolds.fasta ../scaffolds.fa
    faSize ../scaffolds.fa
#166577145 bases (9338570 N's 157238575 real 157238575 upper 0 lower) in 14730 sequences in 1 files
#Total size: mean 11308.7 sd 253114.3 min 204 (super_14729) max 21120651 (super_0) median 1710
#N count: mean 634.0 sd 6174.5
#U count: mean 10674.7 sd 248396.0
#L count: mean 0.0 sd 0.0


# PARTITION SCAFFOLDS FOR REPEATMASKER RUN (DONE 11/29/05 angie)
    # Chop up large scaffolds into ~500kb chunks for RepeatMasker, 
    # then glom the tiny scaffolds up into ~500k collections (looks like 
    # some almost-500k pieces are glommed together --> a few almost-1M chunks,
    # but that's OK).
    ssh kkstore02
    cd /cluster/data/droSec1
    mkdir scaffoldsSplit
    faSplit size scaffolds.fa 500000 -oneFile \
      scaffoldsSplit -lift=jkStuff/scaffoldsSplit.lft
    mkdir chunks500k
    faSplit about scaffoldsSplit.fa 500000 chunks500k/chunk_


# CREATING DATABASE (DONE 11/29/05 angie)
    # Create the database.
    ssh hgwdev
    # Make sure there is at least 5 gig free for the database
    df -h /var/lib/mysql
#/dev/sdc1             1.8T  1.3T  356G  79% /var/lib/mysql
    hgsql '' -e 'create database droSec1'
    # Copy the table "grp" from an existing database to the new database
    hgsql droSec1 -e 'create table grp (PRIMARY KEY(NAME)) select * from dm2.grp'


# RUN REPEAT MASKER (DONE 11/30/05 angie)
    ssh kkstore02
    cat /cluster/bluearc/RepeatMasker/Libraries/version 
#RepBase Update 9.11, RM database version 20050112
    # make the run directory, output directory, and job list
    cd /cluster/data/droSec1
    cat << '_EOF_' > jkStuff/RMDrosophila
#!/bin/csh -fe

cd $1
/bin/mkdir -p /tmp/droSec1/$2
/bin/cp ../chunks500k/$2 /tmp/droSec1/$2/
pushd /tmp/droSec1/$2
/cluster/bluearc/RepeatMasker/RepeatMasker -s -spec drosophila $2
popd
/bin/cp /tmp/droSec1/$2/$2.out ./
/bin/rm -fr /tmp/droSec1/$2/*
/bin/rmdir --ignore-fail-on-non-empty /tmp/droSec1/$2
/bin/rmdir --ignore-fail-on-non-empty /tmp/droSec1
'_EOF_'
    # << this line makes emacs coloring happy
    chmod +x jkStuff/RMDrosophila
    mkdir RMRun RMOut
    cp /dev/null RMRun/RMJobs
    foreach f ( chunks500k/*.fa )
      set chunk = $f:t
      echo ../jkStuff/RMDrosophila \
           /cluster/data/droSec1/RMOut $chunk \
           '{'check in line+ /cluster/data/droSec1/$f'}' \
         '{'check out line+ /cluster/data/droSec1/RMOut/$chunk.out'}' \
      >> RMRun/RMJobs
    end

    # do the run
    ssh kk
    cd /cluster/data/droSec1/RMRun
    para make RMJobs
    para time
#Completed: 312 of 312 jobs
#Average job time:                7359s     122.64m     2.04h    0.09d
#Longest finished job:           15164s     252.73m     4.21h    0.18d
#Submission to last job:         15165s     252.75m     4.21h    0.18d

    # Lift up the split-scaffold .out's to scaffold .out's
    ssh kkstore02
    cd /cluster/data/droSec1
    foreach f (RMOut/*.fa.out)
      liftUp $f:r:r.scaf.out jkStuff/scaffoldsSplit.lft warn $f > /dev/null
    end
    # Make a consolidated scaffold .out file too:
    head -3 RMOut/chunk_00.fa.out > RMOut/scaffolds.fa.out
    foreach f (RMOut/*.scaf.out)
      tail +4 $f >> RMOut/scaffolds.fa.out 
    end
    # Load the .out files into the database with:
    ssh hgwdev
    hgLoadOut -nosplit droSec1 /cluster/data/droSec1/RMOut/scaffolds.fa.out
#note: 3 records dropped due to repStart > repEnd
#bad rep range [868, 862] line 42582 of /cluster/data/droSec1/RMOut/scaffolds.fa.out 
#bad rep range [865, 862] line 49234 of /cluster/data/droSec1/RMOut/scaffolds.fa.out 
#bad rep range [862, 861] line 49837 of /cluster/data/droSec1/RMOut/scaffolds.fa.out 
    # Sent test case to Robert Hubley.


# GOLD, GAP FROM AGP (DONE 11/30/05 angie)
    ssh hgwdev
    cd /cluster/data/droSec1
    # Weird, their sequences are called "super_*" but their agp has 
    # "scaffold_*"... go with the sequence names and fix the agp.
    sed -e 's/^scaffold_/super_/' downloads/assembly.agp > ucsc.agp
    hgGoldGapGl -noGl droSec1 ucsc.agp


# SIMPLE REPEATS (TRF) (DONE 11/30/05 angie)
    ssh kolossus
    mkdir /cluster/data/droSec1/bed/simpleRepeat
    cd /cluster/data/droSec1/bed/simpleRepeat
    nice trfBig -trf=/cluster/bin/i386/trf ../../scaffolds.fa \
      /dev/null -bedAt=simpleRepeat.bed -tempDir=/tmp \
    |& egrep -v '^(Removed|Tandem|Copyright|Loading|Allocating|Initializing|Computing|Scanning|Freeing)' \
    > trf.log &
    # check on this with
    tail -f trf.log

    # Load this into the database as so
    ssh hgwdev
    hgLoadBed droSec1 simpleRepeat \
      /cluster/data/droSec1/bed/simpleRepeat/simpleRepeat.bed \
      -sqlTable=$HOME/kent/src/hg/lib/simpleRepeat.sql


# FILTER SIMPLE REPEATS (TRF) INTO MASK (DONE 11/30/05 angie)
    # make a filtered version of the trf output: 
    # keep trf's with period <= 12:
    ssh kkstore02
    cd /cluster/data/droSec1/bed/simpleRepeat
    awk '{if ($5 <= 12) print;}' simpleRepeat.bed > trfMask.bed


# MASK FA USING REPEATMASKER AND FILTERED TRF FILES (DONE 11/30/05 angie)
    ssh kkstore02
    cd /cluster/data/droSec1
    maskOutFa -soft scaffolds.fa bed/simpleRepeat/trfMask.bed \
      scaffolds.fa
    maskOutFa -softAdd scaffolds.fa RMOut/scaffolds.fa.out scaffolds.fa
    # Now clean up the unmasked split scaffolds to avoid confusion later.
    rm -r chunks500k scaffoldsSplit.fa jkStuff/scaffoldsSplit.lft


# STORE SEQUENCE AND ASSEMBLY INFORMATION (DONE 11/30/05 angie)
    # Translate to 2bit
    ssh kkstore02
    cd /cluster/data/droSec1
    faToTwoBit scaffolds.fa droSec1.2bit
    # Make chromInfo.tab.
    mkdir bed/chromInfo
    twoBitInfo droSec1.2bit stdout \
    | awk '{printf "%s\t%s\t/gbdb/droSec1/droSec1.2bit\n", $1, $2;}' \
    > bed/chromInfo/chromInfo.tab

    # Make symbolic a link from /gbdb/droSec1 to the 2bit.
    ssh hgwdev
    mkdir -p /gbdb/droSec1
    ln -s /cluster/data/droSec1/droSec1.2bit /gbdb/droSec1/
    # Load chromInfo table.
    hgsql droSec1 < $HOME/kent/src/hg/lib/chromInfo.sql
    hgsql droSec1 -e 'load data local infile \
      "/cluster/data/droSec1/bed/chromInfo/chromInfo.tab" into table chromInfo'
    # Make chrom.sizes from chromInfo contents and check scaffold count.
    hgsql droSec1 -N -e 'select chrom,size from chromInfo' \
    > /cluster/data/droSec1/chrom.sizes
    wc -l /cluster/data/droSec1/chrom.sizes
#  14730 /cluster/data/droSec1/chrom.sizes


# MAKE HGCENTRALTEST ENTRY AND TRACKDB TABLE (DONE 11/30/05 angie)
    # Make trackDb table so browser knows what tracks to expect:
    ssh hgwdev
    cd ~/kent/src/hg/makeDb/trackDb
    cvs up -d -P

    # Edit trackDb/makefile to add droSec1 to the DBS variable.
    mkdir drosophila/droSec1
    # Create a simple drosophila/droSec1/description.html file.
    cvs add drosophila/droSec1
    cvs add drosophila/droSec1/description.html
    make update DBS=droSec1

    # go public on genome-test
    cvs ci -m "Added droSec1." makefile
    cvs ci -m "Elementary description.html for droSec1." drosophila/droSec1
    mkdir /gbdb/droSec1/html
    # in a clean, updated tree's kent/src/hg/makeDb/trackDb:
    make alpha
    # Note: genome and organism fields must correspond
    # with defaultDb values
    hgsql -h genome-testdb hgcentraltest -e \
       'INSERT INTO dbDb \
        (name, description, nibPath, organism, \
             defaultPos, active, orderKey, genome, scientificName, \
             htmlPath, hgNearOk, hgPbOk, sourceName) values \
        ("droSec1", "Oct. 2005", "/gbdb/droSec1", "D. sechellia", \
             "super_14:795001-815000", 1, 52, \
             "D. sechellia", \
             "Drosophila sechellia", "/gbdb/droSec1/html/description.html", \
             0, 0, "Broad 28 Oct. 2005");'
    echo 'INSERT INTO defaultDb (genome, name) values ("D. sechellia", "droSec1");' \
      | hgsql -h genome-testdb hgcentraltest
    hgsql -h genome-testdb hgcentraltest \
      -e 'INSERT INTO genomeClade (genome, clade, priority) values \
            ("D. sechellia", "insect", 18);'


# MAKE GCPERCENT (DONE 11/30/05 angie)
    ssh hgwdev
    mkdir /cluster/data/droSec1/bed/gc5Base
    cd /cluster/data/droSec1/bed/gc5Base
    hgGcPercent -wigOut -doGaps -file=stdout -win=5 -verbose=2 droSec1 \
       /cluster/data/droSec1 | wigEncode stdin gc5Base.wig gc5Base.wib
    mkdir /gbdb/droSec1/wib
    ln -s `pwd`/gc5Base.wib /gbdb/droSec1/wib
    hgLoadWiggle -pathPrefix=/gbdb/droSec1/wib droSec1 gc5Base gc5Base.wig


# PUT SEQUENCE ON /ISCRATCH FOR BLASTZ AND MAKE 11.OOC (DONE 11/30/05 angie)
    # First, agglomerate small scaffolds into chunks of ~100k median 
    # (many scaffolds are larger than that) so we don't have too many 
    # files for one dir, but keep a reasonably low job run time:
    ssh kkstore02
    cd /cluster/data/droSec1
    mkdir chunksUnsplit
    faSplit about scaffolds.fa 100000 chunksUnsplit/chunk_
    ssh kkr1u00
    mkdir /iscratch/i/droSec1
    rsync -av /cluster/data/droSec1/chunksUnsplit /iscratch/i/droSec1/
    rsync -av /cluster/data/droSec1/droSec1.2bit /iscratch/i/droSec1/
    # Use -repMatch=100 (based on size -- for human we use 1024, and 
    # fly size is ~4.4% of human judging by gapless dm1 genome size from 
    # featureBits -- we would use 45, but bump that up a bit to be more 
    # conservative).
    mkdir /cluster/bluearc/droSec1
    blat /cluster/data/droSec1/droSec1.2bit /dev/null /dev/null -tileSize=11 \
      -makeOoc=/cluster/bluearc/droSec1/11.ooc -repMatch=100
#Wrote 7825 overused 11-mers to /cluster/bluearc/droSec1/11.ooc
    cp -p /cluster/bluearc/droSec1/*.ooc /iscratch/i/droSec1/
    iSync


# PRODUCING GENSCAN PREDICTIONS (DONE 11/30/05 angie)
    ssh kkstore02
    # Make hard-masked scaffolds and split up for processing:
    cd /cluster/data/droSec1
    maskOutFa scaffolds.fa hard scaffolds.fa.masked
    mkdir chunksUnsplitMasked
    faSplit about scaffolds.fa.masked 100000 chunksUnsplitMasked/chunk_
    mkdir /cluster/data/droSec1/bed/genscan
    cd /cluster/data/droSec1/bed/genscan
    # Check out hg3rdParty/genscanlinux to get latest genscan:
    cvs co hg3rdParty/genscanlinux
    # Make 3 subdirectories for genscan to put their output files in
    mkdir gtf pep subopt
    ls -1S ../../chunksUnsplitMasked/chunk*.fa > chunks.list
    cat << '_EOF_' > gsub
#LOOP
/cluster/bin/x86_64/gsBig {check in line+ $(path1)} {check out line gtf/$(root1).gtf} -trans={check out line pep/$(root1).pep} -subopt={check out line subopt/$(root1).bed} -exe=hg3rdParty/genscanlinux/genscan -par=hg3rdParty/genscanlinux/HumanIso.smat -tmp=/tmp -window=2400000
#ENDLOOP
'_EOF_'
    # << this line keeps emacs coloring happy
    ssh kki
    cd /cluster/data/droSec1/bed/genscan
    gensub2 chunks.list single gsub jobList
    para make jobList
    para time
#Completed: 514 of 514 jobs
#Average job time:                  13s       0.22m     0.00h    0.00d
#Longest finished job:             674s      11.23m     0.19h    0.01d
#Submission to last job:           674s      11.23m     0.19h    0.01d

    # If there are crashes, diagnose with "para problems".  
    # If a job crashes due to genscan running out of memory, re-run it 
    # manually with "-window=1200000" instead of "-window=2400000".
    
    # Concatenate scaffold-level results:
    ssh kkstore02
    cd /cluster/data/droSec1/bed/genscan
    cat gtf/*.gtf > genscan.gtf
    cat subopt/*.bed > genscanSubopt.bed
    cat pep/*.pep > genscan.pep
    # Clean up
    rm -r /cluster/data/droSec1/chunksUnsplitMasked

    # Load into the database as so:
    ssh hgwdev
    cd /cluster/data/droSec1/bed/genscan
    ldHgGene -gtf droSec1 genscan genscan.gtf
    hgPepPred droSec1 generic genscanPep genscan.pep
    hgLoadBed droSec1 genscanSubopt genscanSubopt.bed


# MAKE DOWNLOADABLE FILES (DONE 11/30/05 angie)
    ssh kolossus
    mkdir /cluster/data/droSec1/bigZips
    cd /cluster/data/droSec1
    gzip -c RMOut/scaffolds.fa.out > bigZips/scaffoldOut.gz
    gzip -c scaffolds.fa > bigZips/scaffoldFa.gz
    gzip -c scaffolds.fa.masked > bigZips/scaffoldFaMasked.gz
    gzip -c bed/simpleRepeat/trfMask.bed > bigZips/scaffoldTrf.gz
    cd bigZips
    md5sum *.gz > md5sum.txt
    # create a README.txt
    ssh hgwdev
    mkdir /usr/local/apache/htdocs/goldenPath/droSec1
    cd /usr/local/apache/htdocs/goldenPath/droSec1
    mkdir bigZips database
    # Create README.txt files in database/ to explain the files.
    ln -s /cluster/data/droSec1/bigZips/*.{gz,txt} bigZips


# SWAP CHAINS FROM DM2, BUILD NETS ETC. (DONE 12/5/05 angie)
    mkdir /cluster/data/droSec1/bed/blastz.dm2.swap
    cd /cluster/data/droSec1/bed/blastz.dm2.swap
    doBlastzChainNet.pl -swap /cluster/data/dm2/bed/blastz.droSec1/DEF \
      >& do.log
    echo "check /cluster/data/droSec1/bed/blastz.dm2.swap/do.log" \
    | mail -s "check do.log" $USER
    # Add {chain,net}Dm2 to trackDb.ra if necessary.


# AUTO UPDATE GENBANK INITIAL RUN (DONE 12/6/05 angie)
    # align with revised genbank process
    cd ~kent/src/makeDb/genbank
    cvs update -d etc
    # edit etc/genbank.conf to add droSec1
# droSec1 (D. sechellia)
# genbank.150.0/full has 7 mRNAs and 0 ESTs at time of initial build,
# so no need to make native tracks.
droSec1.serverGenome = /cluster/data/droSec1/droSec1.2bit
droSec1.clusterGenome = /iscratch/i/droSec1/droSec1.2bit
droSec1.ooc = /iscratch/i/droSec1/11.ooc
droSec1.lift = no
droSec1.refseq.mrna.native.pslCDnaFilter  = ${lowCover.refseq.mrna.native.pslCDnaFilter}
droSec1.refseq.mrna.xeno.pslCDnaFilter    = ${lowCover.refseq.mrna.xeno.pslCDnaFilter}
droSec1.genbank.mrna.native.pslCDnaFilter = ${lowCover.genbank.mrna.native.pslCDnaFilter}
droSec1.genbank.mrna.xeno.pslCDnaFilter   = ${lowCover.genbank.mrna.xeno.pslCDnaFilter}
droSec1.genbank.est.native.pslCDnaFilter  = ${lowCover.genbank.est.native.pslCDnaFilter}
droSec1.genbank.est.xeno.pslCDnaFilter    = ${lowCover.genbank.est.xeno.pslCDnaFilter}
droSec1.refseq.mrna.native.load = no
droSec1.refseq.mrna.xeno.load = yes
droSec1.genbank.mrna.native.load = no
droSec1.genbank.mrna.xeno.load = yes
droSec1.genbank.est.native.load = no
droSec1.genbank.est.xeno.load = no
droSec1.downloadDir = droSec1
droSec1.perChromTables = no

    # update /cluster/data/genbank/
    cvs ci -m "Added droSec1." etc/genbank.conf
    make etc-update

    # droSec1 is a new species, so add it to src/lib/gbGenome.c
    make
    cvs ci -m "Added droSec." src/lib/gbGenome.c
    make install-server

    ssh kkstore02
    cd /cluster/data/genbank
    nice bin/gbAlignStep -initial droSec1 &

    # when finished
    ssh hgwdev
    cd /cluster/data/genbank
    nice ./bin/gbDbLoadStep -drop -initialLoad droSec1&
    featureBits droSec1 xenoRefGene
#27947465 bases of 157238575 (17.774%) in intersection
    featureBits droSec1 xenoMrna
#24574087 bases of 157238575 (15.629%) in intersection

# MAKE Drosophila Proteins track (DONE braney 2005-12-07)
    ssh kkstore02
    mkdir -p /cluster/data/droSec1/blastDb
    cd /cluster/data/droSec1/blastDb
    faSplit sequence ../scaffolds.fa 400 x
    for i in *.fa; do /cluster/bluearc/blast229/formatdb -i $i -p F 2> /dev/null; done
    rm *.fa *.log
    cd ..

    ssh kk
    destDir=/cluster/panasas/home/store/droSec1/blastDb
    mkdir -p $destDir
    cp /cluster/data/droSec1/blastDb/* $destDir
    
    mkdir -p /cluster/data/droSec1/bed/tblastn.dm2FB
    cd /cluster/data/droSec1/bed/tblastn.dm2FB
    ls -1S $destDir/*.nsq | sed "s/\.nsq//" > target.lst
    mkdir fbfa
    # calculate a reasonable number of jobs 
    calc `wc /cluster/data/dm2/bed/blat.dm2FB/dm2FB.psl|awk "{print \\\$1}"`/\(80000/`wc target.lst | awk "{print \\\$1}"`\)
# 18929/(80000/396) = 93.698550

    split -l 94 /cluster/data/dm2/bed/blat.dm2FB/dm2FB.psl fbfa/fb
    cd fbfa
    for i in *; do pslxToFa $i $i.fa; rm $i; done
    cd ..
    ls -1S fbfa/*.fa > fb.lst
    mkdir -p /cluster/bluearc/droSec1/bed/tblastn.dm2FB/blastOut  
    ln -s /cluster/bluearc/droSec1/bed/tblastn.dm2FB/blastOut  
    for i in `cat fb.lst`; do  mkdir blastOut/`basename $i .fa`; done
    tcsh
    cat << '_EOF_' > blastGsub
#LOOP
blastSome $(path1) {check in line $(path2)} {check out exists blastOut/$(root2)/q.$(root1).psl } 
#ENDLOOP
'_EOF_'
cat << '_EOF_' > blastSome
#!/bin/sh
BLASTMAT=/iscratch/i/blast/data
export BLASTMAT
g=`basename $2`
f=/tmp/`basename $3`.$g
for eVal in 0.01 0.001 0.0001 0.00001 0.000001 1E-09 1E-11
do
if /scratch/blast/blastall -M BLOSUM80 -m 0 -F no -e $eVal -p tblastn -d $1 -i $2 -o $f.8
then
        mv $f.8 $f.1
        break;
fi
done
if test -f  $f.1
then
if /cluster/bin/i386/blastToPsl $f.1 $f.2
then
        liftUp -nosort -type=".psl" -pslQ -nohead $3.tmp /cluster/data/dm2/bed/blat.dm2FB/protein.lft warn $f.2
        mv $3.tmp $3
        rm -f $f.1 $f.2 $f.3 $f.4
        exit 0
    fi
fi
rm -f $f.1 $f.2 $3.tmp $f.3 $f.8 $f.4
exit 1
'_EOF_'

    chmod +x blastSome
    gensub2 target.lst fb.lst blastGsub blastSpec

    para create blastSpec
    para push

# Completed: 79992 of 79992 jobs
# CPU time in finished jobs:    2936163s   48936.05m   815.60h   33.98d  0.093 y
# IO & Wait Time:                653523s   10892.05m   181.53h    7.56d  0.021 y
# Average job time:                  45s       0.75m     0.01h    0.00d
# Longest running job:                0s       0.00m     0.00h    0.00d
# Longest finished job:           13727s     228.78m     3.81h    0.16d
# Submission to last job:         25997s     433.28m     7.22h    0.30d

    ssh kkstore02
    cd /cluster/data/droSec1/bed/tblastn.dm2FB
    tcsh
    cat << '_EOF_' > chainGsub
#LOOP
chainSome $(path1)
#ENDLOOP
'_EOF_'

    cat << '_EOF_' > chainSome
(cd $1; cat q.*.psl | /cluster/bin/i386/simpleChain -prot -outPsl -maxGap=25000 stdin ../c.`basename $1`.psl)
'_EOF_'
    chmod +x chainSome

    ls -1dS `pwd`/blastOut/fb?? > chain.lst
    gensub2 chain.lst single chainGsub chainSpec

    exit # out of cshell
    ssh kki

    cd /cluster/data/droSec1/bed/tblastn.dm2FB
    para create chainSpec

# Completed: 202 of 202 jobs
# CPU time in finished jobs:        337s       5.61m     0.09h    0.00d  0.000 y
# IO & Wait Time:                  4606s      76.77m     1.28h    0.05d  0.000 y
# Average job time:                  24s       0.41m     0.01h    0.00d
# Longest finished job:              80s       1.33m     0.02h    0.00d
# Submission to last job:           430s       7.17m     0.12h    0.00d

    cd /cluster/data/droSec1/bed/tblastn.dm2FB/blastOut
    for i in fb??
    do 
	awk "(\$13 - \$12)/\$11 > 0.6 {print}" c.$i.psl > c60.$i.psl
	sort -rn c60.$i.psl | pslUniq stdin u.$i.psl
	awk "((\$1 / \$11) ) > 0.60 { print   }" c60.$i.psl > m60.$i.psl
	echo $i
    done

    sort -T /tmp -k 14,14 -k 16,16n -k 17,17n u.*.psl m60* | uniq > /cluster/data/droSec1/bed/tblastn.dm2FB/blastDm2FB.psl
    cd ..
    wc blastDm2FB.psl
# 21575  453075 3313821 blastDm2FB.psl
    pslUniq blastDm2FB.psl stdout | wc                                                                                    
#  18827  395367 2992653
    cat fbfa/*fa | grep ">" | wc
# 82338   82338 1300520

    ssh hgwdev
    cd /cluster/data/droSec1/bed/tblastn.dm2FB
    hgLoadPsl droSec1 blastDm2FB.psl
    featureBits droSec1 blastDm2FB
# 20986178 bases of 157238575 (13.347%) in intersection
    exit

    # back to kkstore02
    rm -rf blastOut

# End tblastn


###########################################################################
# SWAP/CHAIN/NET DM3 (DONE 6/8/07 angie)
    ssh kkstore02
    mkdir /cluster/data/droSec1/bed/blastz.dm3.swap
    cd /cluster/data/droSec1/bed/blastz.dm3.swap
    doBlastzChainNet.pl -swap /cluster/data/dm3/bed/blastz.droSec1/DEF >& do.log &
    tail -f do.log
    ln -s blastz.dm3.swap /cluster/data/droSec1/bed/blastz.dm3


