#  SAM:  Sequence Alignment and Modeling Software System
#                                                                  
#  Baskin Center for Computer Engineering and Information Sciences 
#  University of California, Santa Cruz                            
#                                                                  
#  Copyright 1992-1996, The Regents of the University of California     
#
#  Citations:  A. Krogh et al., JMB 235:1501-1531, Feb. 1994.
#              R. Hughey, A. Krogh, CABIOS 12:95-107, 1996.
#
#  Distributed for non-commercial use only.
#  http://www.cse.ucsc.edu/research/compbio/sam.html
#  Questions or comments to sam-info@cse.ucsc.edu
#

# SysV need this defined or it uses the user's shell.

SHELL = /bin/sh

###############################################################################
# Makefile to run SAM demos.  To run these demos outside of the SAM src
# distribution edit this file to set the following macros
#    o BINDIR - To point to the directory where the SAM executables are
#      installed.
#    o LIBDIR - To point to the directory where the SAM runtime files are
#      installed.
#    o DEMOSRC - The directory containing this source (normally `.').
# It is not necessary to set the top_srcdir or srcdir macros if BINDIR, LIBDIR,
# and DEMOSRC don't reference them.
###############################################################################


LIBDIR = /usr/local/lib/sam
DEMOSRC = .
BINDIR = /usr/local/bin
CONFDIR =  ${DEMOSRC}
T2KDIR = /usr/local/bin

###############################################################################
# This make file is used to both run demos and to do regression testing.
# The output of the demos is used in the doumentation.  Regression testing
# is done by runing thisthe argument FIXEDSEEDS="-randseed 0 -trainseed 0" (or
# some other constant seed value). This forces all models to be build in the
# same manner.  This file references all programs and input relative to
# the parent directory (../src/xxx and ../demos/yyy) or to ${srcdir}.  This
# allows this makefile to be used in parallel directories.
#
# To use this file outside of edit BINDIR to point to the directory containing
# the SAM programs, DEMOSRC to be `.' and LIBDIR to the directory containing
# the prior libraries.
#------------------------------------------------------------------------------

# Top of SAM tree and source directory associated with this makefile.  The
# macro srcdir is normally set to `.' unless compiling outside of the source
# hierarchy.  

top_srcdir = @top_srcdir@
srcdir     = @srcdir@

prefix = @prefix@
exec_prefix = @exec_prefix@

DEMODIST = $(INSTALL_ROOT)${prefix}/sam-demos
INSTALL = $(top_srcdir)/install-sh

###############################################################################
# SAM programs
#------------------------------------------------------------------------------

BUILDMODEL     = ${BINDIR}/buildmodel
DRAWMODEL      = ${BINDIR}/drawmodel
HMMSCORE       = ${BINDIR}/hmmscore
MAKEHIST       = ${BINDIR}/makehist
MAKELOGO       = ${BINDIR}/makelogo
ALIGN2MODEL    = ${BINDIR}/align2model
PRETTYALIGN    = ${BINDIR}/prettyalign
ADDFIMS        = ${BINDIR}/addfims
SAMPLESEQS     = ${BINDIR}/sampleseqs
MODELFROMALIGN = ${BINDIR}/modelfromalign
HMMCONVERT     = ${BINDIR}/hmmconvert
SAM2HMMER      = ${BINDIR}/sam2hmmer
HMMER2SAM      = ${BINDIR}/hmmer2sam
MODIFYMODEL    = ${BINDIR}/modifymodel
SORTSEQ        = ${BINDIR}/sortseq
CHECKSEQ       = ${BINDIR}/checkseq
PERMUTESEQ     = ${BINDIR}/permuteseq
MKTEMPLATE     = ${BINDIR}/make_template
PREDICT_TRACK  = ${BINDIR}/predict_track
PATHPROBS      = ${BINDIR}/pathprobs
GET_FISHER_SCORES = ${BINDIR}/get_fisher_scores
LISTALPHABETS  = ${BINDIR}/listalphabets
GRABDP         = ${BINDIR}/grabdp

TARGET2K	= ${T2KDIR}/target2k
W0.7		= ${T2KDIR}/w0.7
W1.0		= ${T2KDIR}/w1.0
W0.5		= ${T2KDIR}/w0.5

# Set PRIOR_PATH for tests
SET_PATHS = PRIOR_PATH=${LIBDIR}

#
# List of demo files to distribute with a binary distributions.
#
# Install the T99 alignment targets too.
INST_TARGETS = 	1babA-t99.a2m d2ohxa1-t99.a2m \
	d2ohxa2-t99.a2m 2ohxA-2cmd-t99.a2m \
	2pgd-2cmd-2ohxA-t99.a2m 

INST_FILES = ${INST_TARGETS} \
	${srcdir}/2prd.hssp \
	${srcdir}/2prd.training.seqs \
	${srcdir}/atesthssp.seq \
	${srcdir}/atestnot.seq \
	${srcdir}/atestpos.seq \
	${srcdir}/ftrain.init \
	${srcdir}/globins50.seq \
	${srcdir}/gseg4.seq \
	${srcdir}/gseg4.weights \
	${srcdir}/gseg4.weights2 \
	${srcdir}/gsegment.seq \
	${srcdir}/multtrna.seq \
	${srcdir}/test.fasta \
	${srcdir}/trna10.seq \
	${srcdir}/trna10num.seq \
	${srcdir}/trna10f.seq \
	${srcdir}/trna1frag.seq \
	${srcdir}/trna10.cst.save  \
	${srcdir}/trna10e.cst.save  \
	${srcdir}/trna1frag.seq2 \
	${srcdir}/alphadef.seq \
	${srcdir}/alphadef.regularizer \
	${srcdir}/1babA.seq \
	${srcdir}/db1.test1.seq \
	${srcdir}/db1.test2.seq \
	${srcdir}/predict.db1.seq \
	${srcdir}/predict.db1.2d \
	${srcdir}/d2ohxa1.seq \
	${srcdir}/d2ohxa2.seq \
	${srcdir}/1babA-pir39a.dist.save \
	${srcdir}/2pgd-2cmd-2ohxA-scop.dist.save \
	${srcdir}/1babA-scop.dist.save \
	${srcdir}/2pgd-2cmd-2ohxA.a2m.save \
	${srcdir}/2ohxA-2cmd-scop.dist.save \
	${srcdir}/d2ohxa1-scop.dist.save \
	${srcdir}/2ohxA-2cmd.a2m.save \
	${srcdir}/d2ohxa2-scop.dist.save \
	${srcdir}/2pgd-2cmd-2ohxA-not99-scop.dist.save \
	${srcdir}/2ohxA-2cmd.a2m.save \
	${srcdir}/2pgd-2cmd-2ohxA.a2m.save \
	${srcdir}/test.mlib.save \
	${srcdir}/text.seq 

LINE="------------------------------------------------------------------------------"

###############################################################################
# Sources and main targets.
#------------------------------------------------------------------------------

UPRIOR9 = ${LIBDIR}/uprior.9comp

RMFILES =  core *.core *.o *.stat *.Z *.gz *~ *.mod *.mstat *.mult *.freq \
	   *.dist *.dist-rdb *.pretty *.align  doc/*.mod doc/*~ demos.done \
	   *.a2m *.sel drawmodel.ps *.pure_* *.ps *.cst \
	   readseq/*.o $(RSEQSRC) .mppe* .pure* .samr* *.params \
	   sample.seq mon.out gmon.out *.data *.plt .xref* \
	   testhist.ps checkseq.out *.hmmer permuted.seq sort.seq *.tplate \
	   *.pdoc trna10f.tmp.seq *.constr.* sam-t2k.dconf tmp \
	   *.ptrack *.ptrack-rdb *.ptrack.dist *.mlib listalph.out listalphn.out

all: demos

demos: basicdemos aligndemos fimdemos miscdemos multdemos wdemos fragdemos \
       gziptests regdemos hsspdemos vdemos constraintsdemos alphadefdemos \
       mlibdemos predict_tests numdemos fisher samt2kdemos  

#------------------------------------------------------------------------------
mlibdemos:  caltest.mlib caltest.dist 

test.mlib: ${DEMOSRC}/test.mlib.save test.mod
	cp ${DEMOSRC}/test.mlib.save test.mlib
caltest.mlib: test.mlib test.mod
	${HMMSCORE} caltest -modellibrary test.mlib -calibrate 1
caltest.dist: caltest.mlib test.mod
	${HMMSCORE} caltest -modellibrary caltest.mlib -db ${DEMOSRC}/trna10.seq

%.eps: %.mod
	${MAKELOGO} $* -modelfile  $^
#------------------------------------------------------------------------------
#------------------------------------------------------------------------------
#------------------------------------------------------------------------------


basicdemos: test.mod retrain.mod drawmodel.ps test.dist tests.dist  test.eps \
            default.params \
            testhist.ps testv.mod testrev.dist test.dist-rdb testrev.dist-rdb 


testv.mod: ${DEMOSRC}/trna10.seq
	${BUILDMODEL} testv -a RNA -train ${DEMOSRC}/trna10.seq -randseed 0 \
	    -dpstyle 1 -print_frequencies 1 ${FIXEDSEEDS} > sline.mod
	@echo ${LINE}

retrain.mod: test.mod
	${BUILDMODEL} retrain -i test.mod ${FIXEDSEEDS}
	@echo ${LINE}

drawmodel.ps: test.mod
	${DRAWMODEL} test.mod drawmodel.ps -freq 1
	@echo ${LINE}

test.dist: test.mod
	${HMMSCORE} test -i test.mod -db ${DEMOSRC}/trna10.seq -sw 2
	@echo ${LINE}
testrev.dist: test.mod
	${HMMSCORE} testrev -i test.mod -db ${DEMOSRC}/trna10.seq -sw 2\
	-subtractnull 4
	@echo ${LINE}

test.dist-rdb: test.mod
	${HMMSCORE} test -rdb 1 -i test.mod -db ${DEMOSRC}/trna10.seq -sw 2
	@echo ${LINE}

testrev.dist-rdb: test.mod
	${HMMSCORE} testrev -rdb 1 -i test.mod -db ${DEMOSRC}/trna10.seq -sw 2\
	-subtractnull 4
	@echo ${LINE}

tests.dist: test.mod
	${HMMSCORE} tests -i test.mod -db ${DEMOSRC}/trna10.seq \
	    -select_seq 1 -NLLNull -40 -sw 2
	@echo ${LINE}

default.params:
	${BUILDMODEL} -dump_parameters 2
	@echo ${LINE}

testhist.ps: test.dist
	${MAKEHIST} testhist -Nllfile test.dist -histbins 5
	@echo ${LINE}

#------------------------------------------------------------------------------
aligndemos: trna10.a2m trna10.pretty trna2.a2m trna3.a2m trna3.pretty \
	    trna5X.a2m trna5X.pretty

trna10.a2m: test.mod
	${ALIGN2MODEL} trna10 -model_file test.mod -db ${DEMOSRC}/trna10.seq
	@echo ${LINE}

trna10.pretty: trna10.a2m
	${PRETTYALIGN} trna10.a2m -l 90 > trna10.pretty
	@echo ${LINE}

trna2.a2m: test.mod
	${ALIGN2MODEL} trna2 -i test.mod -db ${DEMOSRC}/trna10.seq \
             -id TRNA1 -id TRNA9
	@echo ${LINE}

trna3.a2m: test.mod
	${ALIGN2MODEL} trna3 -i test.mod -db ${DEMOSRC}/trna10.seq \
	     -id TRNA1 -id TRNA2 -id TRNA9 
	@echo ${LINE}

trna3.pretty: trna3.a2m
	${PRETTYALIGN} trna3.a2m -l 50 > trna3.pretty
	@echo ${LINE}

trna5X.a2m: test.mod
	${ALIGN2MODEL} trna5X -i test.mod -db ${DEMOSRC}/trna10f.seq \
	     -id TRNA1 -id TRNA2X -id TRNA3X -id TRNA4X -id TRNA5X
	@echo ${LINE}

trna5X.pretty: trna5X.a2m
	${PRETTYALIGN} trna5X.a2m -l 70 > trna5X.pretty
	@echo ${LINE}

#------------------------------------------------------------------------------
vdemos:  train4regv.mod
train4regv.mod: ${DEMOSRC}/globins50.seq
	${BUILDMODEL} train4regv  -train ${DEMOSRC}/globins50.seq -nmodels 1 \
                  -nsurgery 1 -randseed 0 -trainseed 0 -ntrain 4 \
		  -prior_library ${LIBDIR}/recode3.20comp \
		  -regularizer_file ${LIBDIR}/weak-gap.regularizer 
#------------------------------------------------------------------------------
regdemos: train4.ps train4reg.ps   train4wreg.ps \
	  train10.ps train10reg.ps train10wreg.ps

train4.ps: ${DEMOSRC}/globins50.seq
	${BUILDMODEL} train4  -train ${DEMOSRC}/globins50.seq -nmodels 1 \
                   -nsurgery 0 -randseed 0 -trainseed 0 -ntrain 4 \
		    -proteinprior NoPrior
	${HMMSCORE} train4  -i train4.mod  -db ${DEMOSRC}/globins50.seq -sw 2
	${MAKEHIST} train4 -nllfile train4.dist -plotleft -100 -plotright 50 -plotmax 40
	@echo ${LINE}

train4reg.ps: ${DEMOSRC}/globins50.seq
	${BUILDMODEL} train4reg  -train ${DEMOSRC}/globins50.seq -nmodels 1 \
                  -nsurgery 0 -randseed 0 -trainseed 0 -ntrain 4 \
		  -prior_library ${LIBDIR}/recode3.20comp -internalweight 0 \
		  -regularizer_file ${LIBDIR}/weak-gap.regularizer 
	${HMMSCORE} train4reg  -i train4reg.mod  -db ${DEMOSRC}/globins50.seq -sw 2
	${MAKEHIST} train4reg -nllfile train4reg.dist \
		     -plotleft -100 -plotright 50 -plotmax 40
	@echo ${LINE}
train4wreg.ps: ${DEMOSRC}/globins50.seq
	${BUILDMODEL} train4wreg  -train ${DEMOSRC}/globins50.seq -nmodels 1 \
                  -nsurgery 0 -randseed 0 -trainseed 0 -ntrain 4 \
		  -prior_library ${LIBDIR}/recode3.20comp -internalweight 2 \
		  -regularizer_file ${LIBDIR}/weak-gap.regularizer 
	${HMMSCORE} train4wreg  -i train4wreg.mod  -db ${DEMOSRC}/globins50.seq -sw 2
	${MAKEHIST} train4wreg -nllfile train4wreg.dist \
		     -plotleft -100 -plotright 50 -plotmax 40
	@echo ${LINE}
train10.ps: ${DEMOSRC}/globins50.seq
	${BUILDMODEL} train10  -train ${DEMOSRC}/globins50.seq -nmodels 1 \
                  -nsurgery 0 -randseed 0 -trainseed 0 -ntrain 10 -proteinprior 0
	${HMMSCORE} train10  -i train10.mod  -db ${DEMOSRC}/globins50.seq -sw 2
	${MAKEHIST} train10 -nllfile train10.dist \
		     -plotleft -100 -plotright 50 -plotmax 40
	@echo ${LINE}

train10reg.ps: ${DEMOSRC}/globins50.seq
	${BUILDMODEL} train10reg -train ${DEMOSRC}/globins50.seq -nmodels 1 \
                  -nsurgery 0 -randseed 0 -trainseed 0 -ntrain 10 \
		  -prior_library ${LIBDIR}/recode3.20comp -internalweight 0 \
		  -regularizer_file ${LIBDIR}/weak-gap.regularizer 
	${HMMSCORE} train10reg  -i train10reg.mod  -db ${DEMOSRC}/globins50.seq -sw 2
	${MAKEHIST} train10reg -nllfile train10reg.dist \
		     -plotleft -100 -plotright 50 -plotmax 40
	@echo ${LINE}
train10wreg.ps: ${DEMOSRC}/globins50.seq
	${BUILDMODEL} train10wreg -train ${DEMOSRC}/globins50.seq -nmodels 1 \
                  -nsurgery 0 -randseed 0 -trainseed 0 -ntrain 10 \
		  -prior_library ${LIBDIR}/recode3.20comp -internal_weight 2 \
		  -regularizer_file ${LIBDIR}/weak-gap.regularizer 
	${HMMSCORE} train10wreg  -i train10wreg.mod  -db ${DEMOSRC}/globins50.seq -sw 2
	${MAKEHIST} train10wreg -nllfile train10wreg.dist \
		     -plotleft -100 -plotright 50 -plotmax 40
	@echo ${LINE}
#------------------------------------------------------------------------------
fimdemos: testf.mod trna5f.pretty

testf.mod: test.mod
	${ADDFIMS} testf -insert test.mod ${FIXEDSEEDS}
	@echo ${LINE}

trna5f.a2m: testf.mod
	${ALIGN2MODEL} trna5f -i testf.mod -db ${DEMOSRC}/trna10f.seq \
	     -id TRNA1 -id TRNA2X -id TRNA3X -id TRNA4X -id TRNA5X
	@echo ${LINE}

trna5f.pretty: trna5f.a2m
	${PRETTYALIGN} trna5f.a2m -l 70 > trna5f.pretty
	@echo ${LINE}
#-----------------------------------------------------------------------------
fragdemos: frag.dist fragsw1.dist fragsw2.dist frag.pretty \
	   fragsw1.pretty fragsw2.pretty rfragsw2.dist \
	   fragsw0dp4.pretty fragsw2dp4.pretty  \
	   fragsw0dp5.pretty fragsw2dp5.pretty 

fragsw2dp4.a2m: test.mod
	${ALIGN2MODEL} fragsw2dp4 -sw 2 -adpstyle 4 \
	       -i test.mod -db ${DEMOSRC}/trna1frag.seq 
	@echo ${LINE}
fragsw0dp4.a2m: test.mod
	${ALIGN2MODEL} fragsw0dp4 -sw 0 -adpstyle 4 \
	       -i test.mod -db ${DEMOSRC}/trna1frag.seq 
	@echo ${LINE}
fragsw2dp5.a2m: test.mod
	${ALIGN2MODEL} fragsw2dp5 -sw 2 -adpstyle 5 \
	       -i test.mod -db ${DEMOSRC}/trna1frag.seq 
	@echo ${LINE}
fragsw0dp5.a2m: test.mod
	${ALIGN2MODEL} fragsw0dp5 -sw 0 -adpstyle 5 \
	       -i test.mod -db ${DEMOSRC}/trna1frag.seq 
	@echo ${LINE}
frag.a2m: test.mod
	${ALIGN2MODEL} frag -i test.mod -db ${DEMOSRC}/trna1frag.seq
	@echo ${LINE}
fragsw1.a2m: test.mod
	${ALIGN2MODEL} fragsw1 -sw 1 -i test.mod -db ${DEMOSRC}/trna1frag.seq
	@echo ${LINE}
fragsw2.a2m: test.mod
	${ALIGN2MODEL} fragsw2 -sw 2 -i test.mod -db ${DEMOSRC}/trna1frag.seq
	@echo ${LINE}
frag.pretty: frag.a2m
	${PRETTYALIGN} frag.a2m -l 75 -m 8 > frag.pretty
	@echo ${LINE}
fragsw1.pretty: fragsw1.a2m
	${PRETTYALIGN} fragsw1.a2m -l 75 -m 8 > fragsw1.pretty
	@echo ${LINE}
fragsw2.pretty: fragsw2.a2m
	${PRETTYALIGN} fragsw2.a2m -l 75 -m 8 > fragsw2.pretty
	@echo ${LINE}
fragsw2dp4.pretty: fragsw2dp4.a2m
	${PRETTYALIGN} fragsw2dp4.a2m -l 75 -m 8 > fragsw2dp4.pretty
	@echo ${LINE}
fragsw0dp4.pretty: fragsw0dp4.a2m
	${PRETTYALIGN} fragsw0dp4.a2m -l 75 -m 8 > fragsw0dp4.pretty
	@echo ${LINE}
fragsw2dp5.pretty: fragsw2dp5.a2m
	${PRETTYALIGN} fragsw2dp5.a2m -l 75 -m 8 > fragsw2dp5.pretty
	@echo ${LINE}
fragsw0dp5.pretty: fragsw0dp5.a2m
	${PRETTYALIGN} fragsw0dp5.a2m -l 75 -m 8 > fragsw0dp5.pretty
	@echo ${LINE}
frag.dist: test.mod
	${HMMSCORE} frag -i test.mod -db ${DEMOSRC}/trna1frag.seq 
	@echo ${LINE}
fragsw1.dist: test.mod
	${HMMSCORE} fragsw1 -i test.mod -db ${DEMOSRC}/trna1frag.seq \
	    -SW 1
	@echo ${LINE}
fragsw2.dist: test.mod
	${HMMSCORE} fragsw2 -i test.mod -db ${DEMOSRC}/trna1frag.seq \
	    -SW 2
	@echo ${LINE}
rfrag.dist: test.mod
	${HMMSCORE} rfrag -i test.mod -db ${DEMOSRC}/trna1frag.seq \
	-subtractnull 4
	@echo ${LINE}
rfragsw1.dist: test.mod
	${HMMSCORE} rfragsw1 -i test.mod -db ${DEMOSRC}/trna1frag.seq \
	    -SW 1 	-subtractnull 4
	@echo ${LINE}
rfragsw2.dist: test.mod
	${HMMSCORE} rfragsw2 -i test.mod -db ${DEMOSRC}/trna1frag.seq \
	    -SW 2 	-subtractnull 4
	@echo ${LINE}
#------------------------------------------------------------------------------
hsspdemos: 2prd.tplate 

2prd.tplate: ${DEMOSRC}/2prd.hssp
	${MKTEMPLATE} 2prd -alignfile ${DEMOSRC}/2prd.hssp
	@echo ${LINE}
#-----------------------------------------------------------------------------
miscdemos: sample.seq trna2.mod ig.a2m ig.pretty ig.mod atestpos.mod \
	   atesthssp.mod atestnot.mod test3.dist btest.mod test4.dist \
	   bbtest.mod test5.dist testhmm.hmmer test2.mod test2.dist \
	   modifymod.mod sort.seq checkseq.out permuted.seq permuted.dist \
	   sw.dist t2.dist 

sw.dist: ${DEMOSRC}/globins50.seq
	${HMMSCORE} sw -query ${DEMOSRC}/globins50.seq -db ${DEMOSRC}/globins50.seq \
		-matrix ${LIBDIR}/matrix/aa/blosum62 -gap 12 -continue 1 -Nseq 10

# Quite, Output, display alignments, Bscores, gap, continue, score matrix, histogram
# Like ssearch -Q -O ss.out -d 0 -b 100000 -f -12 -g -1 -s BLOSUM50 -h

t2.dist: test.mod
	${HMMSCORE} t2 -trackmod test.mod,test.mod -db ${DEMOSRC}/trna10.seq,${DEMOSRC}/trna10.seq \
	             -a RNA,RNA -trackcoeff 0.5,0.5 -selectalign 8

sample.seq: test.mod
	${SAMPLESEQS} sample -i test.mod -Nseq 10 ${FIXEDSEEDS}
	@echo ${LINE}

trna2.mod: trna2.a2m
	${MODELFROMALIGN} trna2 -alignfile trna2.a2m ${FIXEDSEEDS}
	@echo ${LINE}

ig.a2m: test.mod
	${ALIGN2MODEL} ig -i test.mod -db ${DEMOSRC}/trna10.seq \
	    -id TRNA1 -id TRNA9
	@echo ${LINE}

ig.pretty: ig.a2m
	${PRETTYALIGN} ig.a2m -I > ig.pretty
	@echo ${LINE}

ig.mod: ig.a2m
	${MODELFROMALIGN} ig -alignfile ig.a2m ${FIXEDSEEDS}
	@echo ${LINE}

atestpos.mod: ${DEMOSRC}/atestpos.seq
	${MODELFROMALIGN} atestpos -alignfile ${DEMOSRC}/atestpos.seq \
	    ${FIXEDSEEDS}
	@echo ${LINE}

atesthssp.mod: ${DEMOSRC}/atesthssp.seq
	${SET_PATHS} ${MODELFROMALIGN} atesthssp -alignfile ${DEMOSRC}/atesthssp.seq \
	    ${FIXEDSEEDS}
	@echo ${LINE}

atestnot.mod: ${DEMOSRC}/atestnot.seq 
	-${SET_PATHS} ${MODELFROMALIGN} atestnot -alignfile ${DEMOSRC}/atestnot.seq \
	    ${FIXEDSEEDS}
	@echo ${LINE}

test3.dist: test.mod
	${HMMSCORE} test3 -i test.mod -db ${DEMOSRC}/trna10.seq
	@echo ${LINE}

btest.mod: test.mod
	${HMMCONVERT} btest -model_file test.mod
	@echo ${LINE}

test4.dist: btest.mod
	${HMMSCORE} test4 -i btest.mod -db ${DEMOSRC}/trna10.seq
	@echo ${LINE}

bbtest.mod: btest.mod
	${HMMCONVERT} bbtest -model_file btest.mod
	@echo ${LINE}

test5.dist: bbtest.mod
	${HMMSCORE} test5 -i bbtest.mod -db ${DEMOSRC}/trna10.seq
	-/bin/ls -l test.mod btest.mod bbtest.mod
	@echo ${LINE}

testhmm.hmmer: test.mod
	${SAM2HMMER} testhmm -i test.mod
	@echo ${LINE}

test2.mod: testhmm.hmmer
	${HMMER2SAM} testhmm.hmmer test2.mod
	@echo ${LINE}

test2.dist: test2.mod
	${HMMSCORE} test2 -i test2.mod -db ${DEMOSRC}/trna10.seq
	@echo ${LINE}

modifymod.mod: test.mod
	${MODIFYMODEL} test.mod \? > modifymod.mod
	@echo ${LINE}

sort.seq: test.dist
	${SORTSEQ} sort -db ${DEMOSRC}/trna10.seq -NLLfile test.dist
	@echo ${LINE}

checkseq.out: ${DEMOSRC}/trna10.seq
	${CHECKSEQ} chkseq -db ${DEMOSRC}/trna10.seq > checkseq.out
	@echo ${LINE}

permuted.seq: ${DEMOSRC}/trna10.seq
	${PERMUTESEQ} permuted -db ${DEMOSRC}/trna10.seq -Nseq 8 \
		    -id TRNA1 -id TRNA2 -id TRNA3 ${FIXEDSEEDS}
	@echo ${LINE}

permuted.dist: test.mod permuted.seq
	${HMMSCORE} permuted -i test.mod -db permuted.seq -sw 2
	@echo ${LINE}


#------------------------------------------------------------------------------
multdemos: multtrna.mult multtrna.pretty multtrnas.mult multtrnas.pretty 
 

multtrna.mult: testf.mod
	${HMMSCORE} multtrna -i testf.mod -db ${DEMOSRC}/multtrna.seq \
	            -select_mdalign 8 -sw 2
	@echo ${LINE}

multtrna.pretty: multtrna.mult
	${PRETTYALIGN} multtrna.mult -l 70 > multtrna.pretty
	@echo ${LINE}

multtrnas.mult: testf.mod
	${HMMSCORE} multtrnas -i testf.mod -db ${DEMOSRC}/multtrna.seq \
	    -alignshort 3 -select_mdalign 8 -sw 2
	@echo ${LINE}

multtrnas.pretty: multtrnas.mult
	${PRETTYALIGN} multtrnas.mult -l 70 > multtrnas.pretty
	@echo ${LINE}

#------------------------------------------------------------------------------
wdemos: gseg4.mod gseg4.dist gseg4s.dist gseg4w.mod gseg4w.dist \
	gseg4ws.dist gseg4w2.0.mod gseg4w2.0.dist gseg4w2s.0.dist \
	gseg4w2.1.dist gseg4w2s.1.dist \
        gseg4iw1.mod gseg4iw1.dist gseg4iw2.mod gseg4iw2.dist

gseg4.mod: ${DEMOSRC}/gseg4.seq
	${BUILDMODEL} gseg4 -train ${DEMOSRC}/gseg4.seq \
	    -prior_library ${UPRIOR9} ${FIXEDSEEDS} -internalweight 0
	@echo ${LINE}

gseg4.dist: gseg4.mod
	${HMMSCORE} gseg4  -i gseg4.mod -db ${DEMOSRC}/gseg4.seq -sw 2
	@echo ${LINE}

gseg4s.dist: gseg4.mod
	${HMMSCORE} gseg4s -i gseg4.mod -db ${DEMOSRC}/gsegment.seq -sw 2
	@echo ${LINE}

gseg4w.mod: ${DEMOSRC}/gseg4.seq
	${BUILDMODEL} gseg4w -train ${DEMOSRC}/gseg4.seq \
            -sequence_weights ${DEMOSRC}/gseg4.weights \
	    -prior_library ${UPRIOR9} ${FIXEDSEEDS}
	@echo ${LINE}

gseg4w.dist: gseg4w.mod
	${HMMSCORE} gseg4w  -i gseg4w.mod -db ${DEMOSRC}/gseg4.seq -sw 2
	@echo ${LINE}

gseg4ws.dist: gseg4w.mod
	${HMMSCORE} gseg4ws -i gseg4w.mod -db ${DEMOSRC}/gsegment.seq -sw 2
	@echo ${LINE}

gseg4w2.0.mod gseg4w2.1.mod: ${DEMOSRC}/gseg4.seq
	${BUILDMODEL} gseg4w2 -train ${DEMOSRC}/gseg4.seq \
	    -sequence_weights ${DEMOSRC}/gseg4.weights2 \
	    -prior_library ${UPRIOR9} ${FIXEDSEEDS}
	@echo ${LINE}

gseg4w2.0.dist: gseg4w2.0.mod
	${HMMSCORE} gseg4w2.0  -i gseg4w2.0.mod -db ${DEMOSRC}/gseg4.seq -sw 2
	@echo ${LINE}

gseg4w2s.0.dist: gseg4w2.0.mod
	${HMMSCORE} gseg4w2s.0 -i gseg4w2.0.mod -db ${DEMOSRC}/gsegment.seq -sw 2
	@echo ${LINE}

gseg4w2.1.dist: gseg4w2.1.mod
	${HMMSCORE} gseg4w2.1  -i gseg4w2.1.mod -db ${DEMOSRC}/gseg4.seq  -sw 2
	@echo ${LINE}

gseg4w2s.1.dist: gseg4w2.1.mod
	${HMMSCORE} gseg4w2s.1 -i gseg4w2.1.mod -db ${DEMOSRC}/gsegment.seq -sw 2
	@echo ${LINE}

gseg4iw1.mod: ${DEMOSRC}/gseg4.seq
	${BUILDMODEL} gseg4iw1 -train ${DEMOSRC}/gseg4.seq \
              -prior_library ${UPRIOR9} ${FIXEDSEEDS} \
              -internal_weight 1 -iweight 0.1 -mix_weights 1
	@echo ${LINE}

gseg4iw1.dist: gseg4iw1.mod
	${HMMSCORE} gseg4iw1  -i gseg4iw1.mod -db ${DEMOSRC}/gseg4.seq -sw 2
	@echo ${LINE}

gseg4iw2.mod: ${DEMOSRC}/gseg4.seq
	${BUILDMODEL} gseg4iw2 -train ${DEMOSRC}/gseg4.seq \
              -prior_library ${UPRIOR9} ${FIXEDSEEDS} \
              -internal_weight 2 -iweight 0.1 -mix_weights 1
	@echo ${LINE}

gseg4iw2.dist: gseg4iw2.mod
	${HMMSCORE} gseg4iw2  -i gseg4iw2.mod -db ${DEMOSRC}/gseg4.seq -sw 2
	@echo ${LINE}

#------------------------------------------------------------------------------
# Compressed data files.
#
# Removed:
#   testZ1.dist  testZ2.dist 
# as this is stable code and CYGWIN does not have compress.

gziptests: testgz.mod.gz testgz1.dist testgz2.dist trna10gz.a2m  \
	 hsspgz.mod


testgz.mod.gz: trna10gz.seq.gz
	rm -f testgz.mod.gz testgz.mod
	${BUILDMODEL} testgz -a RNA -train trna10gz.seq.gz -randseed 0 \
	    -print_frequencies 1 ${FIXEDSEEDS}
	gzip -9 testgz.mod
	@echo ${LINE}

testgz1.dist: testgz.mod.gz trna10gz.seq.gz
	${HMMSCORE} testgz1 -i testgz.mod.gz -db trna10gz.seq.gz -sw 2
	@echo ${LINE}

testgz2.dist: testgz.mod.gz trna10gz.seq.gz
	${HMMSCORE} testgz2 -i testgz.mod -db trna10gz.seq -sw 2
	@echo ${LINE}

trna10gz.a2m: testgz.mod.gz trna10gz.seq.gz
	${ALIGN2MODEL} trna10gz -model_file testgz.mod -db trna10gz.seq.gz
	@echo ${LINE}

testZ1.dist: testgz.mod.gz trna10gz.seq.Z
	${HMMSCORE} testZ1 -i testgz.mod -db trna10gz.seq.Z -sw 2
	@echo ${LINE}

testZ2.dist: testgz.mod.gz trna10gz.seq.Z
	${HMMSCORE} testZ2 -i testgz.mod.gz -db trna10gz.seq -sw 2
	@echo ${LINE}

hsspgz.mod: atesthsspgz.seq.gz
	${SET_PATHS} ${MODELFROMALIGN} hsspgz -alignfile atesthsspgz.seq.gz \
	    ${FIXEDSEEDS}
	@echo ${LINE}

trna10gz.seq.gz: ${DEMOSRC}/trna10.seq
	rm -f trna10gz.seq.gz
	gzip <${DEMOSRC}/trna10.seq >trna10gz.seq.gz

trna10gz.seq.Z: ${DEMOSRC}/trna10.seq
	rm -f trna10gz.seq.Z
	compress <${DEMOSRC}/trna10.seq >trna10gz.seq.Z

atesthsspgz.seq.gz: ${DEMOSRC}/atesthssp.seq
	rm -f atesthsspgz.seq.gz
	gzip <${DEMOSRC}/atesthssp.seq >atesthsspgz.seq.gz

#------------------------------------------------------------------------------
constraintsdemos: trna10a.constr.mod trna10a.constr.dist trna10a.constr.a2m \
		  trna10b.constr.mod trna10b.constr.a2m \
		  trna10c.constr.mod trna10c.constr.a2m \
		  trna10d.constr.fim.mod trna10d.constr.mult \
		  trna10e.constr.mod trna10e.constr.a2m

constraints: constraintsdemos

# Constrained model and alignment to it.
trna10a.constr.mod:
	${BUILDMODEL} trna10a.constr -a RNA -train ${DEMOSRC}/trna10.seq \
	    -constraints ${DEMOSRC}/trna10.cst.save -nmodels 1 \
	    -randseed 0 -print_frequencies 1 ${FIXEDSEEDS}
	@echo ${LINE}

        # Not really useful, but its a test:
trna10a.constr.dist: trna10a.constr.mod
	${HMMSCORE} trna10a.constr -i trna10a.constr.mod \
	    -db ${DEMOSRC}/trna10.seq -constraints ${DEMOSRC}/trna10.cst.save
	@echo ${LINE}

trna10a.constr.a2m: trna10a.constr.mod
	${ALIGN2MODEL} trna10a.constr -model_file trna10a.constr.mod \
	    -db ${DEMOSRC}/trna10.seq -constraints ${DEMOSRC}/trna10.cst.save
	@echo ${LINE}

# Constrained model from alignment using a constraints file.
trna10b.constr.mod trna10b.constr.cst: trna10a.constr.a2m
	${SET_PATHS} ${MODELFROMALIGN} trna10b.constr -alignfile trna10a.constr.a2m \
	    -constraints ${DEMOSRC}/trna10.cst.save \
	    -constraints_out trna10b.constr.cst
	@echo ${LINE}

trna10b.constr.a2m: trna10b.constr.mod trna10b.constr.cst
	${ALIGN2MODEL} trna10b.constr -model_file trna10b.constr.mod \
	    -db ${DEMOSRC}/trna10.seq \
	    -constraints trna10b.constr.cst
	@echo ${LINE}

# Constrained model from alignment using alignment for constraints.
trna10c.constr.mod trna10c.constr.cst: trna10b.constr.a2m
	${SET_PATHS} ${MODELFROMALIGN} trna10c.constr -alignfile trna10b.constr.a2m \
	    -constraints_from_align 1 \
	    -constraints_out trna10c.constr.cst
	@echo ${LINE}

trna10c.constr.a2m: trna10c.constr.mod trna10c.constr.cst
	${ALIGN2MODEL} trna10c.constr -model_file trna10c.constr.mod \
	    -db ${DEMOSRC}/trna10.seq -constraints trna10c.constr.cst
	@echo ${LINE}

# Make sure addfims works
trna10d.constr.fim.mod: trna10a.constr.mod
	-${ADDFIMS} trna10d.constr.fim -i trna10a.constr.mod
	@echo ${LINE}

# Extraction of constraints on domains.
trna10d.constr.mult trna10d.constr.cst: trna10d.constr.fim.mod
	-${HMMSCORE} trna10d.constr -i trna10d.constr.fim.mod \
	    -alignshort 3 -select_mdalign 8 -select_score 0 -sw 2 \
	    -db ${DEMOSRC}/trna10.seq \
	    -constraints ${DEMOSRC}/trna10.cst.save \
	    -constraints_out trna10d.constr.cst
	@echo ${LINE}

# Constrained model from alignment using a constraints file, not specifying
# explicit model postions, getting them from the alignment.
trna10e.constr.mod trna10e.constr.cst: trna10a.constr.a2m
	${SET_PATHS} ${MODELFROMALIGN} trna10e.constr -alignfile trna10a.constr.a2m \
	    -constraints ${DEMOSRC}/trna10e.cst.save \
	    -constraints_out trna10e.constr.cst
	@echo ${LINE}

trna10e.constr.a2m: trna10e.constr.mod trna10e.constr.cst
	${ALIGN2MODEL} trna10e.constr -model_file trna10e.constr.mod \
	    -db ${DEMOSRC}/trna10.seq \
	    -constraints trna10e.constr.cst
	@echo ${LINE}

#------------------------------------------------------------------------------
numdemos:  testn.mod testn.dist testn.a2m listalphn.out
test.mod: ${DEMOSRC}/trna10.seq
	${BUILDMODEL} test -a RNA -train ${DEMOSRC}/trna10.seq -randseed 0 \
	    -print_frequencies 1 ${FIXEDSEEDS} > sline.mod
	@echo ${LINE}

testn.mod: ${DEMOSRC}/trna10num.seq
	${BUILDMODEL} testn -alphabetdef "RNAnumbers 5" -train ${DEMOSRC}/trna10num.seq \
	    ${FIXEDSEEDS} > sline.mod
	@echo ${LINE}
testn.dist: testn.mod
	${HMMSCORE} testn -i testn.mod -db ${DEMOSRC}/trna10nun.seq -sw 2
	@echo ${LINE}
testn.a2m: test.mod
	${ALIGN2MODEL} trna10n -model_file testn.mod -id TRNAn1 -id TRNAn2 -id TRNAn3 -db ${DEMOSRC}/trna10num.seq
	@echo ${LINE}
listalphn.out: 
	${LISTALPHABETS} testn -alphabetdef "RNAnumbers 5" > listalphn.out
	@echo ${LINE}

alphadefdemos: alphadef.mod alphadefv.mod alphadef.retrain.mod alphadef.dist \
        alphadef2.dist alphadef.a2m alphadef.pretty text.mod text.a2m \
	listalph.out
text.mod: $(DEMOSRC)/text.seq
	${BUILDMODEL} text \
	    -alphabet_def "text QWERTYUIOPASDFGHJKLZCVBNMX" \
            -train ${DEMOSRC}/text.seq -randseed 0 ${FIXEDSEEDS}
	@echo ${LINE}
text.a2m: text.mod
	${ALIGN2MODEL} text -i text.mod -db ${DEMOSRC}/text.seq
	@echo ${LINE}
listalph.out: 
	${LISTALPHABETS} test -a protein,EHL > listalph.out
	@echo ${LINE}
alphadef.mod: ${DEMOSRC}/alphadef.seq
	${BUILDMODEL} alphadef -alphabet_def "defrna BDEVX" -i ${DEMOSRC}/alphadef.regularizer \
            -train ${DEMOSRC}/alphadef.seq -randseed 0 ${FIXEDSEEDS}
alphadefv.mod: ${DEMOSRC}/alphadef.seq
	${BUILDMODEL} alphadefv -a RNA -train ${DEMOSRC}/alphadef.seq -randseed 0 \
	    -dpstyle 1 ${FIXEDSEEDS}
	@echo ${LINE}
alphadef.retrain.mod: alphadef.mod
	${BUILDMODEL} alphadef.retrain -i alphadef.mod ${FIXEDSEEDS}
	@echo ${LINE}
alphadef.dist: alphadef.mod
	${HMMSCORE} alphadef -i alphadef.mod -db ${DEMOSRC}/alphadef.seq -sw 2
	@echo ${LINE}
alphadef2.dist: alphadef.mod
	${HMMSCORE} alphadef2 -i alphadef.mod -db ${DEMOSRC}/alphadef.seq \
	    -select_seq 1 -NLLNull -40 -sw 2
	@echo ${LINE}
alphadef.a2m: alphadef.mod
	${ALIGN2MODEL} alphadef -i alphadef.mod -db ${DEMOSRC}/alphadef.seq
	@echo ${LINE}
alphadef.pretty: alphadef.a2m
	${PRETTYALIGN} alphadef.a2m -l 90 > alphadef.pretty
	@echo ${LINE}

## The next group of commands are for demonstrating the target2k script
##   (SAM-T2K method). 
# this line defines the conf file within the makefile
# Don't use the original name in case there's a directory clobber
SAM_T2k_CONF=${CONFDIR}/sam-t2k.conf.tmp
${CONFDIR}/sam-t2k.conf.tmp: ${T2KDIR}/sam-t2k.conf Makefile
	sed -e 's%/projects/compbio/bin/\$$::arch\"%${BINDIR}\"%' \
	 -e 's%/projects/compbio/bin/scripts%${T2KDIR}%' \
	 -e 's%/projects/compbio/tmp%tmp%' \
	 -e 's%/projects/compbio/lib%${LIBDIR}%' \
		< ${T2KDIR}/sam-t2k.conf > ${CONFDIR}/sam-t2k.conf.tmp
# this makes it an environment variable in  subcalls
export SAM_T2k_CONF=${CONFDIR}/sam-t2k.conf.tmp
b2demos: $(SAM_T2k_CONF) b2demosreal
b2demosreal: B2-1babA-t2k.a2m B2-1babA-t2k-w0.5.mod \
        B2-1babA-globins.dist B2-1babA-globins.ps 

w2demos:  $(SAM_T2k_CONF) w2demosreal
w2demosreal: 1babA-t2k.a2m 1babA-t2k-w0.5.mod \
         1babA-globins.dist 1babA-globins.ps

samt2kdemos: $(SAM_T2k_CONF)  samt2kdemosreal b2demos
samt2kdemosreal: 1babA-t2k.a2m 1babA-t2k-w0.5.mod \
         1babA-globins.dist 1babA-globins.pdoc 1babA-globins.freq \
	  1babA-50.a2m globins50-tuned.a2m \
	 d2ohxa1-t2k.a2m d2ohxa1-t2k-w0.5.mod d2ohxa2-t2k.a2m \
	 d2ohxa2-t2k-w0.5.mod 2ohxA-2cmd-t2k.a2m \
	 2ohxA-2cmd-t2k-w0.5.mod 2pgd-2cmd-2ohxA-t2k.a2m \
	 2pgd-2cmd-2ohxA-t2k-w0.5.mod  1babA-globins.ps \
	 1babA-50p.pa2m 1babA-50p.pretty b2demos \
	 d2ohxa1-t2k-w0.5.eps d2ohxa1-t2k-w0.7.eps \
	 d2ohxa1-t2k-w1.0.eps

1babA-50.a2m: $(DEMOSRC)/1babA.seq $(DEMOSRC)/globins50.seq $(SAM_T2k_CONF)
	${TARGET2K}  -seed $(DEMOSRC)/1babA.seq -homologs $(DEMOSRC)/globins50.seq -tuneup \
		-db_size 400000 -out 1babA-50

1babA-t2k.a2m:	$(DEMOSRC)/1babA.seq $(SAM_T2k_CONF)
	${TARGET2K} -seed $(DEMOSRC)/1babA.seq -out 1babA-t2k

1babA-t2k-w0.5.mod: 1babA-t2k.a2m
	${W0.5} 1babA-t2k.a2m 1babA-t2k-w0.5.mod

# t99 tuned alignment can have more states than the original alignment
1babA-50p.a2m: 1babA-t2k-w0.5.mod
	${ALIGN2MODEL} 1babA-50p -modelfile 1babA-t2k-w0.5.mod -db  1babA-50.a2m

1babA-50p.pa2m: 1babA-50p.a2m   1babA-t2k-w0.5.mod
	${PATHPROBS} 1babA-50p -modelfile 1babA-t2k-w0.5.mod -alignfile 1babA-50p.a2m

1babA-50p.pretty: 1babA-50p.pa2m 
	${PRETTYALIGN} 1babA-50p.pa2m -l 90 -m 8 > 1babA-50p.pretty

globins50-tuned.a2m: $(DEMOSRC)/globins50.seq
	${TARGET2K}  -homologs $(DEMOSRC)/globins50.seq -tuneup -db_size 400000 \
        -out globins50-tuned

d2ohxa1-t2k.a2m: $(DEMOSRC)/d2ohxa1.seq
	${TARGET2K} -seed $(DEMOSRC)/d2ohxa1.seq -out d2ohxa1-t2k

d2ohxa1-t2k-w0.7.mod: d2ohxa1-t2k.a2m
	${W0.7} d2ohxa1-t2k.a2m d2ohxa1-t2k-w0.7.mod

d2ohxa1-t2k-w0.5.mod: d2ohxa1-t2k.a2m
	${W0.5} d2ohxa1-t2k.a2m d2ohxa1-t2k-w0.5.mod

d2ohxa1-t2k-w1.0.mod: d2ohxa1-t2k.a2m
	${W1.0} d2ohxa1-t2k.a2m d2ohxa1-t2k-w1.0.mod

d2ohxa2-t2k.a2m: $(DEMOSRC)/d2ohxa2.seq
	${TARGET2K} -seed $(DEMOSRC)/d2ohxa2.seq -out d2ohxa2-t2k

d2ohxa2-t2k-w0.5.mod: d2ohxa2-t2k.a2m
	${W0.5} d2ohxa2-t2k.a2m d2ohxa2-t2k-w0.5.mod

2ohxA-2cmd-t2k.a2m: $(DEMOSRC)/2ohxA-2cmd.a2m.save
	${TARGET2K} -seed $(DEMOSRC)/2ohxA-2cmd.a2m.save -out 2ohxA-2cmd-t2k

2ohxA-2cmd-t2k-w0.5.mod: 2ohxA-2cmd-t2k.a2m
	${W0.5} 2ohxA-2cmd-t2k.a2m 2ohxA-2cmd-t2k-w0.5.mod


2pgd-2cmd-2ohxA-t2k.a2m: $(DEMOSRC)/2pgd-2cmd-2ohxA.a2m.save
	${TARGET2K} -seed $(DEMOSRC)/2pgd-2cmd-2ohxA.a2m.save -out 2pgd-2cmd-2ohxA-t2k

2pgd-2cmd-2ohxA-t2k-w0.5.mod: 2pgd-2cmd-2ohxA-t2k.a2m
	${W0.5} 2pgd-2cmd-2ohxA-t2k.a2m 2pgd-2cmd-2ohxA-t2k-w0.5.mod

2pgd-2cmd-2ohxA-w0.5.mod: $(DEMOSRC)/2pgd-2cmd-2ohxA.a2m.save
	${W0.5} 2pgd-2cmd-2ohxA.a2m.save 2pgd-2cmd-2ohxA-w0.5.mod



1babA-globins.dist: 1babA-t2k-w0.5.mod	 $(DEMOSRC)/globins50.seq
	${HMMSCORE} 1babA-globins -i 1babA-t2k-w0.5.mod \
		-db $(DEMOSRC)/globins50.seq -sw 2

1babA-globins.pdoc: 1babA-t2k-w0.5.mod	 $(DEMOSRC)/globins50.seq
	${GRABDP} 1babA-globins -i 1babA-t2k-w0.5.mod \
		-db $(DEMOSRC)/globins50.seq -sw 2 -dpstyle 2

1babA-globins.freq: 1babA-t2k-w0.5.mod	 $(DEMOSRC)/globins50.seq
	${GRABDP} 1babA-globins -i 1babA-t2k-w0.5.mod \
		-db $(DEMOSRC)/globins50.seq -sw 2 -dpstyle 0

1babA-globins.ps: 1babA-globins.dist
	${MAKEHIST} 1babA-globins -nllfile 1babA-globins.dist -plotleft -100 -plotright 50 -plotmax 40

B2-1babA-t2k.a2m:	$(DEMOSRC)/1babA.seq
	${TARGET2K}  -seed $(DEMOSRC)/1babA.seq -out B2-1babA-t2k

B2-1babA-t2k-w0.5.mod: B2-1babA-t2k.a2m
	${W0.5} B2-1babA-t2k.a2m B2-1babA-t2k-w0.5.mod

B2-1babA-globins.dist: B2-1babA-t2k-w0.5.mod	 $(DEMOSRC)/globins50.seq
	${HMMSCORE} B2-1babA-globins -i B2-1babA-t2k-w0.5.mod \
		-db $(DEMOSRC)/globins50.seq -sw 2
B2-1babA-globins.ps: B2-1babA-globins.dist
	${MAKEHIST} B2-1babA-globins -nllfile B2-1babA-globins.dist -plotleft -100 -plotright 50 -plotmax 40


# demos that rely on databases not distributed with SAM
ucsc-local-samt2kdemos: \
	1babA-scop.dist \
	1babA-pir39a.dist \
	d2ohxa1-scop.dist \
	d2ohxa2-scop.dist \
	2ohxA-2cmd-scop.dist \
	2pgd-2cmd-2ohxA-scop.dist \
	2pgd-2cmd-2ohxA-not2k-scop.dist

SCOP = /projects/compbio/data/scop/pdb90d_1.37
PIR39A = /projects/compbio/data/test-sets/pearson/pir39a-fasta.seqs
1babA-scop.dist: 	1babA-t2k-w0.5.mod
	${HMMSCORE} 1babA-scop -i 1babA-t2k-w0.5.mod \
		-db ${SCOP} -sw 2
1babA-pir39a.dist: 	1babA-t2k-w0.5.mod
	${HMMSCORE} 1babA-pir39a -i 1babA-t2k-w0.5.mod \
		-db ${PIR39A} -sw 2
d2ohxa1-scop.dist: 	d2ohxa1-t2k-w0.5.mod
	${HMMSCORE} d2ohxa1-scop -i d2ohxa1-t2k-w0.5.mod \
		-db ${SCOP} -sw 2
d2ohxa2-scop.dist: 	d2ohxa2-t2k-w0.5.mod
	${HMMSCORE} d2ohxa2-scop -i d2ohxa2-t2k-w0.5.mod \
		-db ${SCOP} -sw 2
2ohxA-2cmd-scop.dist: 	2ohxA-2cmd-t2k-w0.5.mod
	${HMMSCORE} 2ohxA-2cmd-scop -i 2ohxA-2cmd-t2k-w0.5.mod \
		-db ${SCOP} -sw 2
2pgd-2cmd-2ohxA-scop.dist: 	2pgd-2cmd-2ohxA-t2k-w0.5.mod
	${HMMSCORE} 2pgd-2cmd-2ohxA-scop -i 2pgd-2cmd-2ohxA-t2k-w0.5.mod \
		-db ${SCOP} -sw 2
2pgd-2cmd-2ohxA-not2k-scop.dist: 	2pgd-2cmd-2ohxA-w0.5.mod
	${HMMSCORE} 2pgd-2cmd-2ohxA-not2k-scop -i 2pgd-2cmd-2ohxA-w0.5.mod \
		-db ${SCOP} -sw 2

#
# 2nd structure prediction
#
predict_tests: db1.test1.ptrack-rdb db1.test1.ptrack \
	db1.test2.ptrack-rdb db1.test2.ptrack db1.test1.eps

# Predict sequence that is in database.
db1.test1.mod:
	${MODELFROMALIGN} db1.test1 -prior_library ${LIBDIR}/recode4.20comp\
	    -a protein -align_file ${DEMOSRC}/db1.test1.seq

db1.test1.ptrack-rdb: db1.test1.mod
	${PREDICT_TRACK} db1.test1 -rdb 1 -sw 2 -subtract_null 4 \
	    -i db1.test1.mod -alphabet_def "protein - struct HELX " \
	    -db "${DEMOSRC}/predict.db1.seq,${DEMOSRC}/predict.db1.2d" \
	    -predict_seq ${DEMOSRC}/db1.test1.seq
db1.test1.ptrack: db1.test1.mod
	${PREDICT_TRACK} db1.test1 -sw 2 -subtract_null 4 \
	    -i db1.test1.mod -alphabet_def protein,-,struct,HELX \
	    -db ${DEMOSRC}/predict.db1.seq,${DEMOSRC}/predict.db1.2d \
	    -predict_seq ${DEMOSRC}/db1.test1.seq

db1.test1.eps: db1.test1.mod db1.test1.ptrack
	${MAKELOGO} db1.test1 -modelfile db1.test1.mod \
	 -logo_captionf db1.test1.ptrack -logo_sections 1-32

db1.test1.ptrack.dist: db1.test1.mod
	${HMMSCORE} db1.test1.ptrack \
	    -alphabet_def protein,-,struct,HELX \
	    -trackmod db1.test1.mod,${DEMOSRC}/db1.test1.2nd.mod.save \
	    -db "${DEMOSRC}/predict.db1.seq,${DEMOSRC}/predict.db1.2d" \
	    -trackcoeff 0.5,0.5 -selectalign 8 -sw 2

# Predict sequence close to one in the database.
db1.test2.mod:
	${MODELFROMALIGN} db1.test2 -prior_library ${LIBDIR}/recode4.20comp\
	    -a protein -align_file ${DEMOSRC}/db1.test2.seq

db1.test2.ptrack-rdb: db1.test2.mod
	${PREDICT_TRACK} db1.test2 -rdb 1 -sw 2 -subtract_null 4 \
	    -i db1.test2.mod -alphabet_def "protein - struct HELX " \
	    -db ${DEMOSRC}/predict.db1.seq,${DEMOSRC}/predict.db1.2d \
	    -predict_seq ${DEMOSRC}/db1.test2.seq

db1.test2.ptrack: db1.test2.mod
	${PREDICT_TRACK} db1.test2 -sw 2 -subtract_null 4 \
	    -i db1.test2.mod -alphabet_def "protein - struct HELX " \
	    -db "${DEMOSRC}/predict.db1.seq,${DEMOSRC}/predict.db1.2d" \
	    -predict_seq ${DEMOSRC}/db1.test2.seq

#
# Fisher score vectors:
#
fisher: fisher1.fsv fisher2.fsv fisher3.fsv fisher4.fisher-rdb \
	fisher5.fisher-rdb

fisher1.fsv: gseg4.mod ${DEMOSRC}/gseg4.seq
	${GET_FISHER_SCORES} unused -i gseg4.mod -db ${DEMOSRC}/gseg4.seq \
	  -fisher_feature match_prior -prior_library ${UPRIOR9} \
	  -fisher_feature simple >fisher1.fsv

fisher2.fsv: gseg4.mod ${DEMOSRC}/gseg4.seq
	${GET_FISHER_SCORES} unused -i gseg4.mod -db ${DEMOSRC}/gseg4.seq \
	-prior_library ${UPRIOR9} \
	  -fisher_feature match -fisher_feature trans >fisher2.fsv

fisher3.fsv: gseg4.mod ${DEMOSRC}/gseg4.seq
	${GET_FISHER_SCORES} unused -i gseg4.mod -db ${DEMOSRC}/gseg4.seq \
	  -fisher_feature match_prior -prior_library ${UPRIOR9} \
	  -fisher_feature simple -binary_output 1 >fisher3.fsv

fisher4.fisher-rdb: gseg4.mod ${DEMOSRC}/gseg4.seq
	${GET_FISHER_SCORES} fisher4 -i gseg4.mod -db ${DEMOSRC}/gseg4.seq \
	  -fisher_feature match_prior -prior_library ${UPRIOR9} \
	  -fisher_feature simple -rdb 1

fisher5.fisher-rdb: gseg4.mod ${DEMOSRC}/gseg4.seq
	${GET_FISHER_SCORES} fisher5 -i gseg4.mod -db ${DEMOSRC}/gseg4.seq \
	  -fisher_feature match_prior -prior_library ${UPRIOR9}  \
	  -fisher_feature simple -write_dist 1  -rdb 1
clean:
	rm -rf ${RMFILES} *.fsv *.fisher-rdb

distclean: clean
	rm -f Makefile

# Install target for demo files

install:
	test -d "${DEMODIST}" || ${INSTALL} -m 755 -d ${DEMODIST}
	for f in ${INST_FILES} ; do \
	    echo installing $$f ;\
	    ${INSTALL} -m 444 -c $$f ${DEMODIST} ;\
	done
	rm -f ${DEMODIST}/Makefile
	sed -e 's%^BINDIR =.*$$%BINDIR = @EXECBIN@%' \
	    -e 's%^T2KDIR =.*$$%T2KDIR = @SCRIPTBIN@%' \
	    -e 's%^LIBDIR =.*$$%LIBDIR = @LIBDIR@%' \
	    -e 's%^TSD.*=.*$$%%' \
	    -e 's%^DEMOSRC =.*$$%DEMOSRC = .%' ${srcdir}/Makefile.in > ${DEMODIST}/Makefile
	 chmod 444 ${DEMODIST}/Makefile
