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

# This file describes how we made the browser database on
# the Patch 10 release for the NCBI build 37 (February 2009 freeze) aka:
#	GRCh37.p10 - Genome Reference Consortium Human Reference 37

############################################################################
# gather sequence and AGP definitions (DONE - 2012-09-26 - Hiram)
    mkdir -p /hive/data/genomes/hg19Patch10/sequence
    cd /hive/data/genomes/hg19Patch10/sequence
    # a round about way here since patch10 sequence was already assembled.
    # there are perl and shell scripts in
    # ../../hg19/bed/additionalSequence/patch10
    #	which created the fasta file with UCSC names
    # see also in hg19.txt:
    # NCBI patch 9 (DONE - 2012-07-16 - Hiram)

    ln -s ../../hg19/bed/additionalSequence/patch10/hg19.patch10.fa .
    # check what might be different from previous
    faCount hg19.patch10.fa | grep -v total | grep -v seq \
        | sort > patch10.faCount.txt
    faCount ../../hg19/bed/additionalSequence/patch9/hg19.patch9.fa \
        | grep -v total | grep -v seq | sort > patch9.faCount.txt
    # 148 are identical
    comm -12 patch9.faCount.txt patch10.faCount.txt | wc
    #   148    1184    8345
    # it appears that four have changed or removed since patch 9:
    comm -23 patch9.faCount.txt patch10.faCount.txt | wc
    #   4      32     224
    # and 34 added or different:
    comm -13 patch9.faCount.txt patch10.faCount.txt | wc
    #   34     272    1858
    
    # reuse the script from patch9
    sed -e "s/atch9/atch10/g" ../../hg19Patch9/sequence/patch9Agp.pl \
        > ./patch10Agp.pl
    chmod +x patch10Agp.pl
    # one little addition to this script since then:
    diff ./patch10Agp.pl ../../hg19Patch9/sequence/patch9Agp.pl
# 41d40
# <     $faName =~ s/.*gb.JH/JH/;

    ./patch10Agp.pl \
	../../hg19/bed/additionalSequence/patch10/patches.chrom.sizes \
	../../hg19/bed/additionalSequence/patch10/ucscNames.patch10.txt \
        ../../hg19/bed/additionalSequence/patch10/PATCHES/alt_scaffolds/AGP/alt.scaf.agp.gz \
    > hg19Patch10.agp

    # add in the haplotypes from hg19
for H in chr17_ctg5_hap1 chr4_ctg9_hap1 chr6_apd_hap1 chr6_cox_hap2 \
        chr6_dbb_hap3 chr6_mann_hap4 chr6_mcf_hap5 chr6_qbl_hap6 \
        chr6_ssto_hap7
do
    grep "^${H}" /hive/data/genomes/hg19/hg19.agp
    twoBitToFa ../../hg19/hg19.2bit:${H} ${H}.fa
done >> hg19Patch10.agp

    # and the chrM_rCRS
    echo -e "chrM_rCRS\t1\t16569\t1\tF\tNC_012920\t1\t16569\t+" \
	>> hg19Patch10.agp

    sed -e "s/^>.*/>chrM_rCRS/" \
	../../hg19/bed/additionalSequence/chrM/NC_012920.1.fa > chrM_rCRS.fa

    # verify we have correct sequence and AGP file:
    faToTwoBit *.fa patch10.2bit
    checkAgpAndFa  hg19Patch10.agp patch10.2bit 2>&1 | tail -3
    # All AGP and FASTA entries agree - both files are valid

    # compare the two chrom.sizes to see what is missing or has been added
    twoBitInfo patch10.2bit stdout | sort > patch10.chrom.sizes
    twoBitInfo ../../hg19Patch9/sequence/patch9.2bit stdout \
        | sort > patch9.chrom.sizes
    # 158 identical:
    comm -12 patch9.chrom.sizes patch10.chrom.sizes | wc
    #   158     316    3795
    # 4 have disappeared or changed:
    comm -23 patch9.chrom.sizes patch10.chrom.sizes | wc
    #   4       8      84
    # and 54 new ones:
    comm -13 patch9.chrom.sizes patch10.chrom.sizes | wc
    #   34      68     721

##############################################################
# Build the browser (DONE - 2012-09-26 - Hiram)
    cd /hive/data/genomes/hg19Patch10
    cat << '_EOF_' > hg19Patch10.config.ra
# Config parameters for makeGenomeDb.pl:
db hg19Patch10
clade haplotypes
genomeCladePriority 136
scientificName Homo sapiens
commonName GRCh37.p10
assemblyDate Sep. 2012
assemblyLabel GRCh37 Patch 10 Genome Reference Consortium Human Reference 37
assemblyShortLabel GRCh37.p10
orderKey 145
mitoAcc none
fastaFiles /hive/data/genomes/hg19Patch10/sequence/*.fa
agpFiles /hive/data/genomes/hg19Patch10/sequence/hg19Patch10.agp
# qualFiles /dev/null
dbDbSpeciesDir human
photoCreditURL http://www.cbse.ucsc.edu/
photoCreditName CBSE
ncbiGenomeId 51
ncbiAssemblyId 420368
ncbiAssemblyName GRCh37.p10
ncbiBioProject 31257
genBankAccessionID GCA_000001405.11
taxId   9606
'_EOF_'
    # << happy emacs

    # you need to have the clade and genomeCladePriority since this unique
    # db name hg19Patch10 is always a 'new' genome

    # stop after agp to verify agp and fasta agree properly
    makeGenomeDb.pl -dbHost=hgwdev -fileServer=hgwdev -workhorse=hgwdev \
        -stop=agp hg19Patch10.config.ra > makeGenomeDb.log 2>&1
    makeGenomeDb.pl -dbHost=hgwdev -fileServer=hgwdev -workhorse=hgwdev \
	-continue=db hg19Patch10.config.ra > makeGenomeDb.db.log 2>&1

    featureBits -countGaps hg19Patch10 gap
    #   8953321 bases of 122675649 (7.298%) in intersection

    # the makeGenomeDb.pl script changed the case of the genome name:
    hgsql -e 'update dbDb set genome="GRCh37.p10" where name="hg19Patch10";' \
	hgcentraltest
    hgsql -e 'update genomeClade set genome="GRCh37.p10" where genome="Grch37.p1l";' \
	hgcentraltest

###########################################################################
# RepeatMasker (DONE - 2012-09-26 - Hiram)
    mkdir /hive/data/genomes/hg19Patch10/bed/repeatMasker
    cd /hive/data/genomes/hg19Patch10/bed/repeatMasker
    time doRepeatMasker.pl hg19Patch10 -buildDir=`pwd` -noSplit \
	-bigClusterHub=swarm \
        -dbHost=hgwdev -workhorse=hgwdev > do.log 2>&1 &
    #   real    91m24.748s
    cat faSize.rmsk.txt
# 122675649 bases (8953672 N's 113721977 real 51658860 upper 62063117 lower)
#       in 192 sequences in 1 files
# Total size: mean 638935.7 sd 1178791.6 min 16569 (chrM_rCRS)
#       max 7208242 (chr1_jh636052) median 226852
# %50.59 masked total, %54.57 masked real

###########################################################################
# TRF simple repeats (DONE - 2012-09-26 - Hiram)
    mkdir /hive/data/genomes/hg19Patch10/bed/simpleRepeat
    cd /hive/data/genomes/hg19Patch10/bed/simpleRepeat
    time doSimpleRepeat.pl hg19Patch10 -buildDir=`pwd` -dbHost=hgwdev \
        -smallClusterHub=encodek -workhorse=hgwdev > do.log 2>&1 &
    #   real    11m8.170s
    cat fb.simpleRepeat 
    # 3781680 bases of 113722328 (3.325%) in intersection

    cd /hive/data/genomes/hg19Patch10
    twoBitMask hg19Patch10.rmsk.2bit \
        -add bed/simpleRepeat/trfMask.bed hg19Patch10.2bit
    # safe to ignore warning: has >=13 fields
    twoBitToFa hg19Patch10.2bit stdout | faSize stdin \
	> faSize.hg19Patch10.2bit.txt
# 122675649 bases (8953672 N's 113721977 real 51603922 upper 62118055 lower)
#       in 192 sequences in 1 files
# Total size: mean 638935.7 sd 1178791.6 min 16569 (chrM_rCRS)
#       max 7208242 (chr1_jh636052) median 226852
# %50.64 masked total, %54.62 masked real

    rm /gbdb/hg19Patch10/hg19Patch10.2bit
    ln -s `pwd`/hg19Patch10.2bit /gbdb/hg19Patch10/

###########################################################################
# ctgPos track (DONE - 2012-09-26 - Hiram)
    mkdir /hive/data/genomes/hg19Patch10/bed/ctgPos
    cd /hive/data/genomes/hg19Patch10/bed/ctgPos
    for C in `cut -f1 ../../chrom.sizes | grep -v chrM_rCRS`
do
    ctgPos=`hgsql -N -e 'select * from ctgPos where chrom="'$C'";' hg19`
    if [ "x${ctgPos}y" = "xy" ]; then
        GL=`echo $C | sed -e "s/.*_gl//; s/.*_jh//"`
        glAcc=`grep -i ${GL} ../../../hg19/bed/additionalSequence/patch10/PATCHES/scaffold_localID2acc | cut -f2`
        glSize=`grep -i ${GL} ../../chrom.sizes | cut -f2`
        echo -e "$glAcc\t$glSize\t${C}\t0\t$glSize"
    else
        echo "$ctgPos"
    fi
done > ctgPos.txt

    echo -e "NC_012920.1\t16569\tchrM_rCRS\t0\t16569" >> ctgPos.txt

    # check length of ctg names:
    cut -f 1 ctgPos.txt | awk '{print length($0)}' | sort -n | tail -1
    #	11
    # and length of chrom names:
    cut -f 3 ctgPos.txt | awk '{print length($0)}' | sort -n | tail -1
    #	25
    # set those lengths in the indexes for the SQL create:
    sed -e "s/14/11/; s/16/25/" $HOME/kent/src/hg/lib/ctgPos.sql > ctgPos.sql

    hgLoadSqlTab hg19Patch10 ctgPos ctgPos.sql ctgPos.txt
    # should be %100 with gaps:
    featureBits -countGaps hg19Patch10 ctgPos
    #   122675649 bases of 122675649 (100.000%) in intersection

###########################################################################
# ctgPos2 track (DONE - 2012-09-26 - Hiram)
    mkdir /hive/data/genomes/hg19Patch10/bed/ctgPos2
    cd /hive/data/genomes/hg19Patch10/bed/ctgPos2

for C in `cut -f1 ../../chrom.sizes | grep -v chrM_rCRS`
do
    ctgPos2=`hgsql -N -e 'select * from ctgPos2 where chrom="'$C'";' hg19`
    if [ "x${ctgPos}y" = "xy" ]; then
        GL=`echo $C | sed -e "s/.*_gl//; s/.*_jh//"`
        glSize=`grep ${GL} /hive/data/genomes/hg19Patch10/chrom.sizes | cut -f2`
        ncbiChrName=`grep ${GL} ../../../hg19/bed/additionalSequence/patch10/PATCHES/scaffold_localID2acc | cut -f1`
        if [ "x${ncbiChrName}y" = "xy" ]; then
            GL=`echo $C | sed -e "s/_hap.*//" | sed -e "s/chr.*_/_/" | tr '[a-z]' '[A-Z]'`
            ncbiChrName=`grep -h ${GL} /hive/data/genomes/hg19/download/alternate_loci/ALT_REF_LOCI_?/localID2acc | cut -f1`
        fi
        echo -e "$ncbiChrName\t$glSize\t${C}\t0\t$glSize\tF"
    else
        echo -e "$ctgPos2\tF"
    fi
done > ctgPos2.tab

    echo -e "NC_012920.1\t16569\tchrM_rCRS\t0\t16569\tF" >> ctgPos2.tab

    # check length of ctg names:
    cut -f 1 ctgPos2.tab | awk '{print length($0)}' | sort -n | tail -1
    # 24
    # and length of chrom names:
    cut -f 3 ctgPos2.tab | awk '{print length($0)}' | sort -n | tail -1
    # 25

    sed -e "s/20/24/; s/16/25/" $HOME/kent/src/hg/lib/ctgPos2.sql \
	> ctgPos2.sql
    hgLoadSqlTab hg19Patch10 ctgPos2 ctgPos2.sql ctgPos2.tab

    # should be %100 with gaps
    featureBits -countGaps hg19Patch10 ctgPos2
    #	122675649 bases of 122675649 (100.000%) in intersection

###########################################################################
# altSequence track patch10 (DONE - 2012-09-26 - Hiram)
    # provide links to locations on reference genome where these patches and
    # haplotypes belong
    mkdir /hive/data/genomes/hg19Patch10/bed/altSequence
    cd /hive/data/genomes/hg19Patch10/bed/altSequence
    ln -s ../../../hg19/bed/additionalSequence/patch10/altSequence.bed \
	altSeq.bed.0

    cat altSeq.bed.0 | while read L
do
    C=`echo "${L}" | awk '{print $4}'`
    hg19C=`echo "${L}" | awk '{print $1}'`
    hg19S=`echo "${L}" | awk '{print $2}'`
    hg19E=`echo "${L}" | awk '{print $3}'`
    S=`grep "^${C}" ../../chrom.sizes | cut -f2`
    echo $C $S $hg19C $hg19S $hg19E | awk '{printf "%s\t0\t%d\t%s:%d-%d\t", $1, $2, $3, $4, $5}'
    echo "${L}" | awk '{printf "%d\t%s\t%d\t%d\t%s\n", $5,$6,$7,$8,$9}'
done | grep -v "chrM_rCRS:" > altSequence.tab

    hgLoadBed hg19Patch10 altSequence altSequence.tab
    #   Read 192 elements of size 9 from altSequence.tab

    featureBits -countGaps hg19Patch10 altSequence
    #   122675649 bases of 122675649 (100.000%) in intersection

############################################################################
# lastz alignment to hg19 (DONE - 2012-09-27 - Hiram)
    mkdir /hive/data/genomes/hg19Patch10/bed/lastzHg19.2012-09-27
    cd /hive/data/genomes/hg19Patch10/bed/lastzHg19.2012-09-27
    #	construct a 2bit file of just the hg19 reference sequences
    # and all the business to run lastz on each haplotype with its
    # corresponding target sequence in hg19

rm -fr hg19Bits run.blastz hg19Bits.lift
mkdir hg19Bits
mkdir -p run.blastz/tParts
mkdir -p run.blastz/qParts
awk '{print $1}' ../altSequence/altSequence.tab | sort -u | while read H
do
    P=`grep "^${H}" ../altSequence/altSequence.tab | head -1 | awk '{print $4}'`
    HE=`grep "^${H}" ../altSequence/altSequence.tab | head -1 | awk '{print $3}'`
    C=`echo ${P} | sed -e "s/:.*//"`
    CE=`grep "^${C}" /hive/data/genomes/hg19/chrom.sizes | cut -f2 | head -1`
    SE=`echo ${P} | sed -e "s/.*://"`
    S=`echo ${SE} | sed -e "s/-.*//" | awk '{printf "%d", $1-1}'`
    if [ "${S}" -lt 0 ]; then
       S=0
    fi
    E=`echo ${SE} | sed -e "s/.*-//"`
    size=`echo $E $S | awk '{printf "%d", $1-$2}'`
    echo -e "$S\t$C.$S-$E\t$size\t$C\t$CE"
    echo hg19.2bit:${C}:$S-$E 1>&2
    if [ ! -s hg19Bits/$C.$S-$E.fa ]; then
	echo ">$C.$S-$E" > hg19Bits/$C.$S-$E.fa
	twoBitToFa /gbdb/hg19/hg19.2bit:${C}:$S-$E stdout \
	    | grep -v "^>" >> hg19Bits/$C.$S-$E.fa
    fi
    echo -e "/hive/data/genomes/hg19Patch10/hg19Patch10.2bit:$H:0-$HE" \
        > run.blastz/tParts/$H.lst
    echo -e "/hive/data/genomes/hg19Patch10/bed/lastzHg19.2012-09-27/hg19Bits.2bit:$C.$S-$E:0-$size" \
        > run.blastz/qParts/$H.lst
    echo -e "/cluster/bin/scripts/blastz-run-ucsc -outFormat psl tParts/$H.lst qParts/$H.lst ../DEF {check out exists ../psl/$H.psl}" \
	>> run.blastz/jobList
done | sort -u > hg19Bits.lift

    faToTwoBit hg19Bits/chr*.fa hg19Bits.2bit
    twoBitInfo hg19Bits.2bit stdout | sort -k2nr > hg19Bits.chrom.sizes
XXX - ready to go here - Wed Sep 26 14:29:35 PDT 2012

    cat << '_EOF_' > DEF
# human vs human
BLASTZ=lastz
# maximum M allowed with lastz is only 254
BLASTZ_M=254
# lastz does not like the O= and E= lines in the matrix file
BLASTZ_Q=/scratch/data/blastz/human_chimp.v2.q
BLASTZ_O=600
BLASTZ_E=150
# other parameters from hg18 vs venter1 lastz on advice from Webb
BLASTZ_K=10000
BLASTZ_Y=15000
BLASTZ_T=2

# TARGET: Human Hg19Patch10
SEQ1_DIR=/hive/data/genomes/hg19Patch10/hg19Patch10.2bit
SEQ1_LEN=/hive/data/genomes/hg19Patch10/chrom.sizes
SEQ1_CHUNK=5000000
SEQ1_LAP=10000
SEQ1_IN_CONTIGS=0
SEQ1_LIMIT=2

# QUERY: Human Hg19
SEQ2_DIR=/scratch/data/hg19/hg19.2bit
SEQ2_LEN=/scratch/data/hg19/chrom.sizes
SEQ2_CTGDIR=/hive/data/genomes/hg19Patch10/bed/lastzHg19.2012-09-27/hg19Bits.2bit
SEQ2_CTGLEN=/hive/data/genomes/hg19Patch10/bed/lastzHg19.2012-09-27/hg19Bits.chrom.sizes
SEQ2_LIFT=/hive/data/genomes/hg19Patch10/bed/lastzHg19.2012-09-27/hg19Bits.lift
SEQ2_CHUNK=5000000
SEQ2_LAP=0
SEQ2_IN_CONTIGS=0
SEQ2_LIMIT=2

BASE=/hive/data/genomes/hg19Patch10/bed/lastzHg19.2012-09-27
TMPDIR=/scratch/tmp
'_EOF_'
    # << happy emacs

    ssh swarm
    cd /hive/data/genomes/hg19Patch10/bed/lastzHg19.2012-09-27/run.blastz
    mkdir ../psl
    para create jobList
    para try ... check ... push
    para time
# Completed: 192 of 192 jobs
# CPU time in finished jobs:        582s       9.69m     0.16h    0.01d  0.000 y
# IO & Wait Time:                   637s      10.62m     0.18h    0.01d  0.000 y
# Average job time:                   6s       0.11m     0.00h    0.00d
# Longest finished job:             208s       3.47m     0.06h    0.00d
# Submission to last job:           230s       3.83m     0.06h    0.00d

    #	put together the individual results:
    cd /hive/data/genomes/hg19Patch10/bed/lastzHg19.2012-09-27
    mkdir pslParts
    cat psl/chr*.psl | gzip -c > pslParts/hg19Patch10.hg19.psl.gz

    #	constructing a chain from those results
    mkdir -p /hive/data/genomes/hg19Patch10/bed/lastzHg19.2012-09-27/axtChain/run
    cd /hive/data/genomes/hg19Patch10/bed/lastzHg19.2012-09-27/axtChain/run
time zcat ../../pslParts/hg19Patch10.hg19.psl.gz \
| axtChain -psl -verbose=0 -scoreScheme=/scratch/data/blastz/human_chimp.v2.q -minScore=2000 -linearGap=medium stdin \
    /hive/data/genomes/hg19Patch10/hg19Patch10.2bit \
    /hive/data/genomes/hg19Patch10/bed/lastzHg19.2012-09-27/hg19Bits.2bit \
    stdout \
| chainAntiRepeat /hive/data/genomes/hg19Patch10/hg19Patch10.2bit \
    /hive/data/genomes/hg19Patch10/bed/lastzHg19.2012-09-27/hg19Bits.2bit \
    stdin hg19Patch10.hg19.preLift.chain
    #   real    0m44.175s
liftUp -chainQ hg19Patch10.hg19.lifted.chain \
    ../../hg19Bits.lift carry hg19Patch10.hg19.preLift.chain

    # constructing the net files:
cd /hive/data/genomes/hg19Patch10/bed/lastzHg19.2012-09-27/axtChain

chainMergeSort run/hg19Patch10.hg19.lifted.chain \
        | nice gzip -c > hg19Patch10.hg19.all.chain.gz
chainSplit chain hg19Patch10.hg19.all.chain.gz
# Make nets ("noClass", i.e. without rmsk/class stats which are added later):
time chainPreNet  hg19Patch10.hg19.all.chain.gz \
    /hive/data/genomes/hg19Patch10/chrom.sizes \
    /scratch/data/hg19/chrom.sizes stdout \
    | chainNet  stdin -minSpace=1 /hive/data/genomes/hg19Patch10/chrom.sizes \
        /scratch/data/hg19/chrom.sizes stdout /dev/null \
    | netSyntenic stdin noClass.net
    #   real    0m1.338s

# Make liftOver chains:
netChainSubset -verbose=0 noClass.net hg19Patch10.hg19.all.chain.gz stdout \
    | chainStitchId stdin stdout | gzip -c > hg19Patch10.hg19.over.chain.gz

# Make axtNet for download: one .axt per hg19Patch10 seq.
netSplit noClass.net net
cd ..
mkdir -p axtNet
foreach f (axtChain/net/*.net)
netToAxt $f axtChain/chain/$f:t:r.chain \
  /hive/data/genomes/hg19Patch10/hg19Patch10.2bit \
        /scratch/data/hg19/hg19.2bit stdout \
  | axtSort stdin stdout \
  | gzip -c > axtNet/$f:t:r.hg19Patch10.hg19.net.axt.gz
end

# Make mafNet for multiz: one .maf per hg19Patch10 seq.
mkdir -p mafNet
foreach f (axtNet/*.hg19Patch10.hg19.net.axt.gz)
  axtToMaf -tPrefix=hg19Patch10. -qPrefix=hg19. $f \
        /hive/data/genomes/hg19Patch10/chrom.sizes \
        /scratch/data/hg19/chrom.sizes \
        stdout \
  | gzip -c > mafNet/$f:t:r:r:r:r:r.maf.gz
end

    # swap that business to hg19
    mkdir /hive/data/genomes/hg19/bed/blastz.hg19Patch10.swap
    cd /hive/data/genomes/hg19/bed/blastz.hg19Patch10.swap
    time doBlastzChainNet.pl -verbose=2 \
	/hive/data/genomes/hg19Patch10/bed/lastzHg19.2012-09-27/DEF \
	-swap -noDbNameCheck  -stop=load \
	-noLoadChainSplit -chainMinScore=2000 \
	-chainLinearGap=medium -workhorse=hgwdev \
	-smallClusterHub=encodek -bigClusterHub=swarm > swap.load.log 2>&1
    #   real     2m51.872s

    cat fb.hg19.chainHg19Patch10Link.txt 
    #   83360723 bases of 2897316137 (2.877%) in intersection

    # and then fixup the chains to include the haplotypes
    cd /hive/data/genomes/hg19/bed/blastz.hg19Patch10.swap/axtChain
    # split up each chain by the hg19Patch10 query sequences
    mkdir -p queryChains
    chainSplit -q queryChains hg19.hg19Patch10.all.chain.gz

    # then run a 'lift over' chain/net on each single one
    mkdir -p singleLiftOver

for F in queryChains/*.chain
do
    C=`basename ${F}`
    B=`echo ${C} | sed -e "s/.chain//"`
    chainPreNet -inclHap ${F} /scratch/data/hg19/chrom.sizes \
        /hive/data/genomes/hg19Patch10/chrom.sizes stdout \
    | chainNet -inclHap stdin -minSpace=1 /scratch/data/hg19/chrom.sizes \
        /hive/data/genomes/hg19Patch10/chrom.sizes singleLiftOver/${B}.raw.net \
        /dev/null
    netSyntenic singleLiftOver/${B}.raw.net singleLiftOver/${B}.noClass.net
    netFilter -chimpSyn singleLiftOver/${B}.noClass.net > singleLiftOver/${B}.chimpSyn.net
    netChainSubset -verbose=0 singleLiftOver/${B}.noClass.net \
        ${F} stdout \
    | chainStitchId stdin stdout > singleLiftOver/${C}
    echo "${F} -> singleLiftOver/${C}"
done
    # put the chains together into one file
    chainMergeSort singleLiftOver/chr*.chain | gzip -c \
	> hg19.hg19Patch10.single.over.chain.gz

    # construct psl files from those chains
    chainToPsl hg19.hg19Patch10.single.over.chain.gz \
	/hive/data/genomes/hg19/chrom.sizes \
        /hive/data/genomes/hg19Patch10/chrom.sizes \
        /hive/data/genomes/hg19/hg19.2bit \
        /hive/data/genomes/hg19Patch10/hg19Patch10.2bit \
        hg19.hg19Patch10.over.psl
    # chainToPsl appears to have a problem, note errors from pslCheck:
    pslCheck -db=hg19 hg19.hg19Patch10.over.psl
    # checked: 946 failed: 45 errors: 45

    pslRecalcMatch hg19.hg19Patch10.over.psl \
	/hive/data/genomes/hg19/hg19.2bit \
	/hive/data/genomes/hg19Patch10/hg19Patch10.2bit \
	fixup.hg19.hg19Patch10.over.psl
    pslCheck -db=hg19 fixup.hg19.hg19Patch10.over.psl
    # checked: 946 failed: 0 errors: 0

    # load this PSL track
    hgLoadPsl hg19 -table=altSeqLiftOverPslP10 fixup.hg19.hg19Patch10.over.psl

############################################################################
# Add this sequence to hg19 (DONE - 2012-09-27 - Hiram)
    mkdir /hive/data/genomes/hg19Patch10/bed/altSequence/seqExt
    cd /hive/data/genomes/hg19Patch10/bed/altSequence/seqExt
    twoBitToFa ../../../hg19Patch10.2bit hg19Patch10.fa
    mkdir -p /gbdb/hg19/hg19Patch10 hg19Patch10
    faSplit byname hg19Patch10.fa ./hg19Patch10/
    ln -s `pwd`/hg19Patch10/*.fa /gbdb/hg19/hg19Patch10
    hgLoadSeq -drop -seqTbl=seqHg19Patch10 -extFileTbl=extHg19Patch10 hg19 \
        /gbdb/hg19/hg19Patch10/*.fa

############################################################################
