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


# Drosophila mojavensis -- 
# 
# Agencourt's 11 Aug 2004 assembly
# 
#


# DOWNLOAD SEQUENCE (DONE 11/3/04 angie)
    ssh kksilo
    mkdir /cluster/store8/droMoj1
    cd /cluster/data
    ln -s /cluster/store8/droMoj1 droMoj1
    cd /cluster/data/droMoj1
    mkdir jkStuff bed
    mkdir downloads
    cd downloads
    wget http://rana.lbl.gov/drosophila/assemblies/dmoj_agencourt_arachne_11aug04.tar.gz
    tar xvzf dmoj_agencourt_arachne_11aug04.tar.gz
    gunzip mojavensis/assembly.bases.gz
    faSize mojavensis/assembly.bases
#189814987 bases (0 N's 189814987 real) in 38423 sequences in 1 files
#Total size: mean 4940.1 sd 12402.7 min 452 (contig_2604) max 332654 (contig_1100) median 1273
#N count: mean 0.0 sd 0.0


# PARTITION SCAFFOLDS FOR REPEATMASKER RUN (DONE 11/3/04 angie)
    # Max scaffold size is 332k, so no splitting/lifting req'd!
    # Agglomerate the small scaffolds up into ~500k collections.
    ssh kksilo
    cd /cluster/data/droMoj1
    mkdir chunks
    faSplit about downloads/mojavensis/assembly.bases 500000 chunks/chunk_


# CREATING DATABASE (DONE 11/3/04 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  638G 1022G  39% /var/lib/mysql
    hgsql '' -e 'create database droMoj1'


# RUN REPEAT MASKER (DONE 11/4/04 angie)
    # January ("March") '04 version of RepeatMasker and libs.
    # make the run directory, output directory, and job list
    ssh kksilo
    cd /cluster/data/droMoj1
    cat << '_EOF_' > jkStuff/RMDrosophila
#!/bin/csh -fe

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

    # do the run
    ssh kk9
    cd /cluster/data/droMoj1/RMRun
    para create RMJobs
    para try, check, push, check,...
#Completed: 366 of 366 jobs
#Average job time:                2881s      48.01m     0.80h    0.03d
#Longest job:                     4316s      71.93m     1.20h    0.05d
#Submission to last job:         15955s     265.92m     4.43h    0.18d

    # Make a consolidated scaffold .out file too:
    head -3 RMOut/chunk_00.fa.out > RMOut/scaffolds.fa.out
    foreach f (RMOut/chunk*.fa.out)
      tail +4 $f >> RMOut/scaffolds.fa.out 
    end
    # Load the .out files into the database with:
    ssh hgwdev
    hgLoadOut droMoj1 /cluster/data/droMoj1/RMOut/scaffolds.fa.out
    # hgLoadOut made a "scaffolds_rmsk" table even with -table=rmsk, 
    # but we want a non-split with no prefix table:
    hgsql droMoj1 -e 'rename table scaffolds_rmsk to rmsk'
    # Fix up the indices too:
    hgsql droMoj1 -e 'drop index bin       on rmsk; \
                  drop index genoStart on rmsk; \
                  drop index genoEnd   on rmsk; \
                  create index bin       on rmsk (genoName(12), bin); \
                  create index genoStart on rmsk (genoName(12), genoStart); \
                  create index genoEnd   on rmsk (genoName(12), genoEnd);'


# EXTRACTING GAP INFO FROM BLOCKS OF NS (DONE 11/5/04 angie)
    ssh kksilo
    mkdir /cluster/data/droMoj1/bed/fakeAgp
    cd /cluster/data/droMoj1/bed/fakeAgp
    faGapSizes ../../downloads/mojavensis/assembly.bases \
        -niceSizes=5,10,20,25,30,40,50,100,250,500,1000,10000,100000
    # Oops, forgot that faSize told us there were no N's at all!
    # No need to run hgFakeAgp here -- just create an empty gap table.
    ssh hgwdev
    hgLoadGap -unsplit droMoj1 /dev/null


# SIMPLE REPEATS (TRF) (DONE 11/4/04 angie)
    ssh kksilo
    mkdir /cluster/data/droMoj1/bed/simpleRepeat
    cd /cluster/data/droMoj1/bed/simpleRepeat
    nice trfBig -trf=/cluster/bin/i386/trf \
      ../../downloads/mojavensis/assembly.bases \
      /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 droMoj1 simpleRepeat \
      /cluster/data/droMoj1/bed/simpleRepeat/simpleRepeat.bed \
      -sqlTable=$HOME/kent/src/hg/lib/simpleRepeat.sql


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


# MASK FA USING REPEATMASKER AND FILTERED TRF FILES (DONE 11/4/04 angie)
    ssh kksilo
    cd /cluster/data/droMoj1
    maskOutFa -soft downloads/mojavensis/assembly.bases \
      bed/simpleRepeat/trfMask.bed scaffolds.fa
    maskOutFa -softAdd scaffolds.fa RMOut/scaffolds.fa.out scaffolds.fa
    # Now clean up the unmasked chunks to avoid confusion later.
    rm -r chunks


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

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


# CREATING GRP TABLE FOR TRACK GROUPING (DONE 11/3/04 angie)
    # Copy all the data from the table "grp" 
    # in an existing database to the new database
    ssh hgwdev
    hgsql droMoj1 -e 'create table grp (PRIMARY KEY(NAME)) select * from hg17.grp'


# MAKE HGCENTRALTEST ENTRY AND TRACKDB TABLE (DONE 11/4/04 angie)
    # Warning: genome and organism fields must correspond
    # with defaultDb values
    echo 'INSERT INTO dbDb \
        (name, description, nibPath, organism, \
             defaultPos, active, orderKey, genome, scientificName, \
             htmlPath, hgNearOk, hgPbOk, sourceName) values \
        ("droMoj1", "Aug. 2004", "/gbdb/droMoj1", "D. mojavensis", \
             "contig_2959:30001-44626", 1, 57, \
             "D. mojavensis", \
             "Drosophila mojavensis", "/gbdb/droMoj1/html/description.html", \
             0, 0, "Agencourt 11 Aug 2004");' \
      | hgsql -h genome-testdb hgcentraltest
    echo 'INSERT INTO defaultDb (genome, name) values ("D. mojavensis", "droMoj1");' \
      | hgsql -h genome-testdb hgcentraltest

    # 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 droMoj1 to the DBS variable.
    mkdir drosophila/droMoj1
    # Create a simple drosophila/droMoj1/description.html file.
    cvs add drosophila/droMoj1
    cvs add drosophila/droMoj1/description.html
    make update DBS=droMoj1 ZOO_DBS=

    # go public on genome-test
    cvs commit makefile
    cvs commit drosophila/droMoj1
    mkdir /gbdb/droMoj1/html
    # in a clean, updated tree's kent/src/hg/makeDb/trackDb:
    make alpha


# PUT SEQUENCE ON /ISCRATCH FOR BLASTZ (DONE 11/4/04 angie)
    # First, agglomerate small scaffolds into chunks of ~200k 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:
    # I should have split these a little coarser -- avg job time too small.
    ssh kksilo
    cd /cluster/data/droMoj1
    mkdir chunks
    faSplit about scaffolds.fa 200000 chunks/chunk_
    ssh kkr1u00
    mkdir /iscratch/i/droMoj1
    cp -pR /cluster/data/droMoj1/chunks /iscratch/i/droMoj1/
    cp -p /cluster/data/droMoj1/droMoj1.2bit /iscratch/i/droMoj1/
    iSync


# PRODUCING GENSCAN PREDICTIONS (DONE 11/4/04 angie)
    ssh kksilo
    # Make hard-masked scaffolds and split up for processing:
    cd /cluster/data/droMoj1
    maskOutFa scaffolds.fa hard scaffolds.fa.masked
    mkdir chunksHardMasked
    faSplit about scaffolds.fa.masked 500000 chunksHardMasked/chunk_
    mkdir /cluster/data/droMoj1/bed/genscan
    cd /cluster/data/droMoj1/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 ../../chunksHardMasked/chunk*.fa > chunks.list
    cat << '_EOF_' > gsub
#LOOP
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
    gensub2 chunks.list single gsub jobList
    ssh kki
    cd /cluster/data/droMoj1/bed/genscan
    para create jobList
    para try, check, push, check, ...
#Completed: 366 of 366 jobs
#Average job time:                  16s       0.26m     0.00h    0.00d
#Longest job:                       29s       0.48m     0.01h    0.00d
#Submission to last job:           462s       7.70m     0.13h    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 kksilo
    cd /cluster/data/droMoj1/bed/genscan
    cat gtf/*.gtf > genscan.gtf
    cat subopt/*.bed > genscanSubopt.bed
    cat pep/*.pep > genscan.pep
    # Clean up:
    rm -r /cluster/data/droMoj1/chunksHardMasked

    # Load into the database as so:
    ssh hgwdev
    cd /cluster/data/droMoj1/bed/genscan
    # Reloaded without -genePredExt 1/6/05:
    ldHgGene -gtf droMoj1 genscan genscan.gtf
    hgPepPred droMoj1 generic genscanPep genscan.pep
    hgLoadBed droMoj1 genscanSubopt genscanSubopt.bed

# MYTOUCH FIX - jen - 2006-01-24
  sudo mytouch droMoj1 genscanPep 0501071300.00

# MAKE DOWNLOADABLE FILES (DONE 11/4/04 angie)
    ssh kksilo
    mkdir /cluster/data/droMoj1/zips
    cd /cluster/data/droMoj1
    zip -j zips/scaffoldOut.zip RMOut/scaffolds.fa.out
    zip -j zips/scaffoldFa.zip scaffolds.fa
    zip -j zips/scaffoldFaMasked.zip scaffolds.fa.masked
    zip -j zips/scaffoldTrf.zip bed/simpleRepeat/trfMask.bed
    foreach f (zips/*.zip)
      echo $f
      unzip -t $f | tail -1
    end
    ssh hgwdev
    mkdir /usr/local/apache/htdocs/goldenPath/droMoj1
    cd /usr/local/apache/htdocs/goldenPath/droMoj1
    mkdir bigZips database
    # Create README.txt files in bigZips/ and database/ to explain the files.
    cd bigZips
    cp -p /cluster/data/droMoj1/zips/*.zip .
    md5sum *.zip > md5sum.txt


# SWAP DM1-DROMOJ1 BLASTZ (DONE 11/4/04 angie)
    ssh kksilo
    mkdir -p /cluster/data/droMoj1/bed/blastz.dm1.swap.2004-11-04/axtScaffold
    ln -s blastz.dm1.swap.2004-11-04 /cluster/data/droMoj1/bed/blastz.dm1
    cd /cluster/data/droMoj1/bed/blastz.dm1
    set aliDir = /cluster/data/dm1/bed/blastz.droMoj1
    cp $aliDir/S1.len S2.len
    cp $aliDir/S2.len S1.len
    # With 38k scaffolds, we don't want a directory with one file per 
    # scaffold.  So just make one .axt with everything -- not too huge 
    # anyway, given these little insect genomes.
    cat $aliDir/axtChrom/chr*.axt \
    | axtSwap stdin $aliDir/S1.len $aliDir/S2.len stdout \
    | axtSort stdin dm1.axt
    du -sh $aliDir/axtChrom dm1.axt
#235M    /cluster/data/dm1/bed/blastz.droMoj1/axtChrom
#235M    dm1.axt


# CHAIN MELANOGASTER BLASTZ (DONE 11/4/04 angie)
    # Run axtChain on kolossus (one big dm1.axt input)
    ssh kolossus
    mkdir /cluster/data/droMoj1/bed/blastz.dm1/axtChain
    cd /cluster/data/droMoj1/bed/blastz.dm1/axtChain
    axtChain -verbose=0 ../dm1.axt /cluster/data/droMoj1/droMoj1.2bit \
      /cluster/data/dm1/nib stdout \
    | chainAntiRepeat /cluster/data/droMoj1/droMoj1.2bit \
      /cluster/data/dm1/nib stdin stdout \
    | chainMergeSort stdin > all.chain
    # Load chains into database
    ssh hgwdev
    cd /cluster/data/droMoj1/bed/blastz.dm1/axtChain
    hgLoadChain -tIndex droMoj1 chainDm1 all.chain


# NET MELANOGASTER BLASTZ (DONE 11/5/04 angie)
    ssh kksilo
    cd /cluster/data/droMoj1/bed/blastz.dm1/axtChain
    chainPreNet all.chain ../S1.len ../S2.len stdout \
    | chainNet stdin -minSpace=1 ../S1.len ../S2.len stdout /dev/null \
    | netSyntenic stdin noClass.net

    # Add classification info using db tables:
    ssh hgwdev
    cd /cluster/data/droMoj1/bed/blastz.dm1/axtChain
    # Note: this was painfully slow until I added an index on genoName to rmsk.
    # An index on genoName,bin is fine too -- but explain shows that the index 
    # on bin,genoName was ignored ==> 38k very slow hChromQuery calls.
    netClass -noAr noClass.net droMoj1 dm1 melanogaster.net \
    |& g -v "table gap doesn't exist"

    # Make a 'syntenic' subset:
    ssh kksilo
    cd /cluster/data/droMoj1/bed/blastz.dm1/axtChain
    rm noClass.net
    netFilter -syn melanogaster.net > melanogasterSyn.net

    # Load the nets into database 
    ssh hgwdev
    cd /cluster/data/droMoj1/bed/blastz.dm1/axtChain
    netFilter -minGap=10 melanogaster.net |  hgLoadNet droMoj1 netDm1 stdin
    netFilter -minGap=10 melanogasterSyn.net \
    | hgLoadNet droMoj1 netSyntenyDm1 stdin


# MAKE AXTNET (DONE 11/4/04 angie)
    ssh kksilo
    cd /cluster/data/droMoj1/bed/blastz.dm1/axtChain
    netToAxt melanogaster.net all.chain /cluster/data/droMoj1/droMoj1.2bit \
        /cluster/data/dm1/nib stdout \
      | axtSort stdin melanogasterNet.axt


# MAKE VSDM1 DOWNLOADABLES (DONE 11/5/04 angie)
    ssh kksilo
    cd /cluster/data/droMoj1/bed/blastz.dm1/axtChain
    nice gzip *.{chain,net,axt}
    ssh hgwdev
    mkdir /usr/local/apache/htdocs/goldenPath/droMoj1/vsDm1
    cd /usr/local/apache/htdocs/goldenPath/droMoj1/vsDm1
    cp -p /cluster/data/droMoj1/bed/blastz.dm1/axtChain/all.chain.gz \
      melanogaster.chain.gz
    cp -p /cluster/data/droMoj1/bed/blastz.dm1/axtChain/melanogaster.net.gz .
    cp -p /cluster/data/droMoj1/bed/blastz.dm1/axtChain/melanogasterNet.axt.gz .
    # Make a README.txt which explains the files & formats.
    md5sum *.gz */*.gz > md5sum.txt


# MAKE 11.OOC FILE FOR BLAT (DONE 11/4/04 angie)
    # 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).
    ssh kkr1u00
    mkdir /cluster/bluearc/droMoj1
    blat /cluster/data/droMoj1/droMoj1.2bit /dev/null /dev/null -tileSize=11 \
      -makeOoc=/cluster/bluearc/droMoj1/11.ooc -repMatch=100
#Wrote 18637 overused 11-mers to /cluster/bluearc/droMoj1/11.ooc
    cp -p /cluster/bluearc/droMoj1/*.ooc /iscratch/i/droMoj1/
    iSync


# AUTO UPDATE GENBANK MRNA RUN  (DONE 11/19/04 angie)
    ssh hgwdev
    # Update genbank config and source in CVS:
    cd ~/kent/src/hg/makeDb/genbank
    cvsup .

    # Edit etc/genbank.conf and add these lines (note scaffold-browser settings):
# droMoj1 (D. mojavensis)
droMoj1.genome = /iscratch/i/droMoj1/droMoj1.2bit
droMoj1.mondoTwoBitParts = 1000
droMoj1.lift = no
droMoj1.refseq.mrna.native.load = no
droMoj1.refseq.mrna.xeno.load = yes
droMoj1.refseq.mrna.xeno.pslReps = -minCover=0.15 -minAli=0.75 -nearTop=0.005
droMoj1.genbank.mrna.xeno.load = yes
# GenBank has no D. mojavensis ESTs at this point... that may change.
droMoj1.genbank.est.native.load = no
droMoj1.genbank.est.xeno.load = no
droMoj1.downloadDir = droMoj1
droMoj1.perChromTables = no

    cvs ci etc/genbank.conf
    # Since D. mojavensis is a new species for us, edit src/lib/gbGenome.c.  
    # Pick some other browser species, & monkey-see monkey-do.  
    cvs diff src/lib/gbGenome.c
    make
    cvs ci src/lib/gbGenome.c
    # Edit src/align/gbBlat to add /iscratch/i/droMoj1/11.ooc
    cvs diff src/align/gbBlat
    make
    cvs ci src/align/gbBlat

    # Install to /cluster/data/genbank:
    make install-server

    ssh eieio
    cd /cluster/data/genbank
    # This is an -initial run, (xeno) RefSeq only:
    nice bin/gbAlignStep -srcDb=refseq -type=mrna -initial droMoj1 &
    tail -f [its logfile]
    # Load results:
    ssh hgwdev
    cd /cluster/data/genbank
    nice bin/gbDbLoadStep -verbose=1 -drop -initialLoad droMoj1
    featureBits droMoj1 xenoRefGene
# About half the coverage of dp2...maybe we should loosen the params:
#10125930 bases of 189814987 (5.335%) in intersection
    # Clean up:
    rm -rf work/initial.droMoj1

    # This is an -initial run, mRNA only:
    nice bin/gbAlignStep -srcDb=genbank -type=mrna -initial droMoj1 &
    tail -f [its logfile]
    # Load results:
    ssh hgwdev
    cd /cluster/data/genbank
    nice bin/gbDbLoadStep -verbose=1 -drop -initialLoad droMoj1
    featureBits droMoj1 all_mrna
#245 bases of 189814987 (0.000%) in intersection
    featureBits droMoj1 xenoMrna
#14690077 bases of 189814987 (7.739%) in intersection
    # Clean up:
    rm -rf work/initial.droMoj1


# MAKE GCPERCENT (DONE 11/4/04 angie)
    ssh hgwdev
    mkdir /cluster/data/droMoj1/bed/gcPercent
    cd /cluster/data/droMoj1/bed/gcPercent
    # create and load gcPercent table
    hgGcPercent droMoj1 /cluster/data/droMoj1


# MAKE HGCENTRALTEST BLATSERVERS ENTRY (DONE 12/?/04 heather)
    ssh hgwdev
    echo 'insert into blatServers values("droMoj1", "blat14", "17782", 1, 0); \
          insert into blatServers values("droMoj1", "blat14", "17783", 0, 1);' \
      | hgsql -h genome-testdb hgcentraltest

# MAKE Drosophila Proteins track  (DONE braney 11/17/04)
    ssh kksilo
    mkdir -p /cluster/data/droMoj1/blastDb
    cd /cluster/data/droMoj1/blastDb
    faSplit sequence ../scaffolds.fa 400 x
    for i in *.fa; do formatdb -i $i -p F 2> /dev/null; done
    rm *.fa *.log

    ssh kkr1u00
    mkdir -p /iscratch/i/droMoj1/blastDb
    cp /cluster/data/droMoj1/blastDb/* /iscratch/i/droMoj1/blastDb
    (iSync) 2>&1 > sync.out
    
    mkdir -p /cluster/data/droMoj1/bed/tblastn.dm1FB
    cd /cluster/data/droMoj1/bed/tblastn.dm1FB
    ls -1S /iscratch/i/droMoj1/blastDb/*.nsq | sed "s/\.nsq//" > bug.lst
    exit

    # back to kksilo
    cd /cluster/data/droMoj1/bed/tblastn.dm1FB
    mkdir fbfa
    # calculate a reasonable number of jobs
    calc `wc /cluster/data/dm1/bed/blat.dm1FB/dm1FB.psl | awk "{print \\\$1}"`/\(150000/`wc bug.lst | awk "{print \\\$1}"`\)
    # 18735/(150000/396) = 49.460400
    split -l 49 /cluster/data/dm1/bed/blat.dm1FB/dm1FB.psl fbfa/fb
    cd fbfa
    for i in *; do pslxToFa $i $i.fa; rm $i; done
    cd ..
    ls -1S fbfa/*.fa > fb.lst
    mkdir blastOut
    for i in `cat fb.lst`; do  mkdir blastOut/`basename $i .fa`; done
    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 /iscratch/i/dm1/protein.lft warn $f.2

        mv $3.tmp $3
        rm -f $f.1 $f.2 
        exit 0
    fi
fi
rm -f $f.1 $f.2 $3.tmp 
exit 1
'_EOF_'

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

    ssh kk
    cd /cluster/data/droMoj1/bed/tblastn.dm1FB
    para create blastSpec
    para try, push
# Completed: 151668 of 151668 jobs
# CPU time in finished jobs:    2116764s   35279.40m   587.99h   24.50d  0.067 y
# IO & Wait Time:                708771s   11812.85m   196.88h    8.20d  0.022 y
# Average job time:                  19s       0.31m     0.01h    0.00d
# Longest job:                       78s       1.30m     0.02h    0.00d
# Submission to last job:         66560s    1109.33m    18.49h    0.77d

    cat << '_EOF_' > chainGsub
#LOOP
chainSome $(path1)
#ENDLOOP
'_EOF_'

    cat << '_EOF_' > chainSome
(cd $1; cat q.*.psl | 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
    para create chainSpec

    # should run this on the mini-cluster or with my shove script
    # so you can limit the number of jobs starting to 3 or 4
    para try, push...

# Completed: 383 of 383 jobs
# CPU time in finished jobs:        859s      14.32m     0.24h    0.01d  0.000 y
# IO & Wait Time:                 20594s     343.23m     5.72h    0.24d  0.001 y
# Average job time:                  56s       0.93m     0.02h    0.00d
# Longest job:                      121s       2.02m     0.03h    0.00d
# Submission to last job:          1679s      27.98m     0.47h    0.02d
    exit
    # back to kksilo
    cd /cluster/data/droMoj1/bed/tblastn.dm1FB/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/droMoj1/bed/tblastn.dm1FB/blastDm1FB.psl

    ssh hgwdev
    cd /cluster/data/droMoj1/bed/tblastn.dm1FB

    hgLoadPsl droMoj1 blastDm1FB.psl

# End tblastn


# SWAP CHAINS FROM DM2, BUILD NETS ETC. (REDONE 5/23/05 angie)
# Originally done 3/11/05 -- redone (better params) 5/23/05.
    mkdir /cluster/data/droMoj1/bed/blastz.dm2.swap
    cd /cluster/data/droMoj1/bed/blastz.dm2.swap
    doBlastzChainNet.pl -swap /cluster/data/dm2/bed/blastz.droMoj1/DEF \
      >& do.log &
    tail -f do.log
    # Add {chain,net}Dm2 to trackDb.ra if necessary.


# MAKE Drosophila Proteins track (DONE braney 06-30-05)
    ssh kk
    mkdir -p /cluster/data/droMoj1/bed/tblastn.dm2FB
    cd /cluster/data/droMoj1/bed/tblastn.dm2FB
    ls -1S /iscratch/i/droMoj1/blastDb/*.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/droMoj1/bed/tblastn.dm2FB/blastOut  
    ln -s /cluster/bluearc/droMoj1/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

    ssh kk
    cd /cluster/data/droMoj1/bed/tblastn.dm2FB
    para create blastSpec
    para push

# Completed: 79992 of 79992 jobs
# CPU time in finished jobs:     991690s   16528.17m   275.47h   11.48d  0.031 y
# IO & Wait Time:                390588s    6509.79m   108.50h    4.52d  0.012 y
# Average job time:                  17s       0.29m     0.00h    0.00d
# Longest finished job:             147s       2.45m     0.04h    0.00d
# Submission to last job:         38524s     642.07m    10.70h    0.45d

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

    cat << '_EOF_' > chainSome
(cd $1; cat q.*.psl | 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

    para create chainSpec
    para push
 
# Completed: 164 of 164 jobs
# CPU time in finished jobs:        332s       5.53m     0.09h    0.00d  0.000 y
# IO & Wait Time:                  2165s      36.09m     0.60h    0.03d  0.000 y
# Average job time:                  15s       0.25m     0.00h    0.00d
# Longest finished job:              58s       0.97m     0.02h    0.00d
# Submission to last job:           187s       3.12m     0.05h    0.00d

    cd /cluster/data/droMoj1/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 -u -T /tmp -k 14,14 -k 16,16n -k 17,17n u.*.psl m60* > /cluster/data/droMoj1/bed/tblastn.dm2FB/blastDm2FB.psl
    cd ..

    ssh hgwdev
    cd /cluster/data/droMoj1/bed/tblastn.dm2FB
    hgLoadPsl droMoj1 blastDm2FB.psl
    exit

    # back to kksilo
    rm -rf blastOut

# End tblastn


# GENEID PREDICTIONS FROM IMIM (DONE 7/26/05 angie)
    ssh hgwdev
    mkdir /cluster/data/droMoj1/bed/geneid
    cd /cluster/data/droMoj1/bed/geneid
    wget http://genome.imim.es/genepredictions/D.mojavensis/golden_path_200408/geneidv1.2/scaffolds.gtf
    ldHgGene -gtf -genePredExt droMoj1 geneid *.gtf


