#!/bin/sh

#	Set this to -verbose to see wigAsciiToBinary at work
#
VERBOSE="-verbose"

TEST_PL=~/kent/src/utils/wigAsciiToBinary/test_data
export TEST_PL

echo "There are individual experiments here that are not appropriate"
echo -e "\tto run all at once.  And you do not want to load DBs anyway"
echo -e "\texcept with known care."

exit 0

#	Create a data set with holes in the data.
#	This will be 1K data values at 1 value per base, frequency 1
#	64 x 1K blocks of data separated by 1K holes
#	Frequency of 16 will give us a cycle for every four 1K blocks
#                      # points
#                      |    frequency
#                      |    | Data Span
#                      |    | | Skip every N points
#                      |    | | |    Skip this many
#${TEST_PL}/testData.pl 65536 16 1 1024 1024 > 1K_feature.ascii

#	Cover the entire chrUn chrom with 1K blocks separated by 1K
#	missing data.  Half of the chrUn 109,025,926 bases is
#	54,512,963 bases, at a frequency of 196 will give us a cycle
#	for every 16 1K blocks.  Should end up with 53,235 data table
#	rows for the 1 base zoom view, and 51 data table rows for
#	the 1K base zoom view.
${TEST_PL}/testData.pl 54512963 196 1 1024 1024 > 1K_feature.ascii
${TEST_PL}/zoom1K.pl 1K_feature.ascii > 1K_Z_feature.ascii

wigAsciiToBinary ${VERBOSE} -chrom=chrUn -name=1Kx1K_MissingData \
	-offset=0 -wibFile=chrUn1Kx1K_0 -binsize=1024 1K_feature.ascii
wigAsciiToBinary ${VERBOSE} -chrom=chrUn -name=1Kx1K_MissingData \
	-offset=0 -wibFile=chrUn1Kx1K_1 -dataSpan=1024 \
	-binsize=1024 1K_Z_feature.ascii
hgLoadWiggle -verbose -tab cb1 chrUn_wig_missing chrUn1Kx1K_0.wig
hgLoadWiggle -oldTable -verbose -tab cb1 chrUn_wig_missing chrUn1Kx1K_1.wig
cp -p chrUn1Kx1K_0.wib /cluster/data/cb1/wib
cp -p chrUn1Kx1K_1.wib /cluster/data/cb1/wib
ln -s /cluster/data/cb1/wib/chrUn1Kx1K_[01].wib /gbdb/cb1/wib

exit 0
#	Then, load that data multiple times, each with a different
#		offset.  We will end up with duplicate feature
#		names, but that shouldn't be a problem.
#	The holes are 1K in size, thus each 1K set of data will be
#	separated by a 1K missing section, three data sets, two holes
wigAsciiToBinary ${VERBOSE} -chrom=chrUn -name=1Kx1K_MissingData \
	-offset=0 -wibFile=chrUn1Kx1K_0 -binsize=1024 1K_feature.ascii
hgLoadWiggle -verbose -tab cb1 chrUn_wig_missing chrUn1Kx1K_0.wig

wigAsciiToBinary ${VERBOSE} -chrom=chrUn -name=1Kx1K_MissingData \
	-offset=2048 -wibFile=chrUn1Kx1K_1 -binsize=1024 1K_feature.ascii
hgLoadWiggle -oldTable -verbose -tab cb1 chrUn_wig_missing chrUn1Kx1K_1.wig

wigAsciiToBinary ${VERBOSE} -chrom=chrUn -name=1Kx1K_MissingData \
	-offset=4096 -wibFile=chrUn1Kx1K_2 -binsize=1024 1K_feature.ascii
hgLoadWiggle -oldTable -verbose -tab cb1 chrUn_wig_missing chrUn1Kx1K_2.wig

cp -p chrUn1Kx1K*.wib /cluster/data/cb1/wib
ln -s /cluster/data/cb1/wib/chrUn1Kx1K*.wib /gbdb/cb1/wib

exit 0

#	Create a 20 Million test data set for a cb1 browser view
#	centered around its default location.
#	location.  20000768 points is 1024*19532,
#	frequency of 76 will give us one cycle for every 256 bins of 1K
#	data
${TEST_PL}/testData.pl 20000768 76 > 20Mb_feature.ascii
wigAsciiToBinary ${VERBOSE} -chrom=chrUn -name=20MegaBases \
	-offset=64989367 -wibFile=chrUn20M -binsize=1024 20Mb_feature.ascii

hgLoadWiggle -verbose -tab cb1 20Mb_feature chrUn20M.wig

#	Then, create the same dataset zoomed by 1K
${TEST_PL}/testData.pl 19532 76 1024 > 20Mb_1K_feature.ascii
wigAsciiToBinary ${VERBOSE} -chrom=chrUn -name=20MegaBases \
	-offset=64989367 -wibFile=chrUn20M_1K -dataSpan=1024 \
	-binsize=1024 20Mb_1K_feature.ascii

hgLoadWiggle -oldTable -verbose -tab cb1 20Mb_feature chrUn20M_1K.wig

exit 0

#	Create a test data set for a cb1 browser view at its default
#	location.  18432 points, frequency of 5
${TEST_PL}/testData.pl 18432 5 > test_feature.ascii

wigAsciiToBinary ${VERBOSE} -chrom=chrUn -name=test_feature \
	-offset=74980669 -wibFile=chrUn1b -binsize=4096 test_feature.ascii
hgLoadWiggle -verbose -tab cb1 chrUn_wig_test chrUn1b.wig

#	Then, assume we have zoomed that data to 1024 bases per
#	data point.  Load it up into the same table
${TEST_PL}/testData.pl 18 3 1024 > test_feature.1K.ascii
wigAsciiToBinary ${VERBOSE} -chrom=chrUn -name=test_feature \
	-offset=74980669 -wibFile=chrUn1K -dataSpan=1024 -binsize=8 \
	test_feature.1K.ascii
hgLoadWiggle -oldTable -verbose -tab cb1 chrUn_wig_test chrUn1K.wig

cp -p chrUn1K.wib /cluster/data/cb1/wib
cp -p chrUn1b.wib /cluster/data/cb1/wib

#	A second feature in the same place

${TEST_PL}/testData.pl 18432 13 > second_wig.ascii

wigAsciiToBinary ${VERBOSE} -chrom=chrUn -name=second_wig \
	-offset=74980669 -wibFile=chrUn1b_2 -binsize=8192 second_wig.ascii
hgLoadWiggle -verbose -tab cb1 chrUn_second_wig chrUn1b_2.wig

#	Its first level of zoom is at 2K
#	data point.  Load it up into the same table
${TEST_PL}/testData.pl 9 3 2048 > second_wig.1K.ascii
wigAsciiToBinary ${VERBOSE} -chrom=chrUn -name=second_wig \
	-offset=74980669 -wibFile=chrUn1K_2 -dataSpan=2048 -binsize=2 \
	second_wig.1K.ascii
hgLoadWiggle -oldTable -verbose -tab cb1 chrUn_second_wig chrUn1K_2.wig

cp -p chrUn1b_2.wib /cluster/data/cb1/wib
cp -p chrUn1K_2.wib /cluster/data/cb1/wib

exit 0

hgsql -e "drop database wiggleTest;" test
hgsql -e "create database wiggleTest;" test

#       16570 data values, frequency of 4 - simple single base coverage
#       of chrM, with test of -chrom option to set output file names
rm -f chrM.ascii chr0.wib chrM.wib
${TEST_PL}/testData.pl 16570 4 > chrM.ascii
wigAsciiToBinary ${VERBOSE} chrM.ascii

hgLoadWiggle -verbose -tab wiggleTest chrM chrM.wig

#	Create a chr1 data set.  Length of hg16 chr1 is
#	246127941 bases
#	With a middle run of 1024 data points each representing
#	240359 bases that accounts for 246127616 bases leaving
#	325 bases.  Divide the 325 bases into two smaller parts for
#	a begin and end run of 162 and 163 bases respectively and
#	we thus have enough data points to cover the whole thing.
#
${TEST_PL}/testData.pl 162 > chr1_begin.ascii
${TEST_PL}/testData.pl 163 > chr1_end.ascii
${TEST_PL}/testData.pl 1024 16 240359 > chr1_middle.ascii

wigAsciiToBinary ${VERBOSE} -chrom=chr1_0 -name=begin chr1_begin.ascii
wigAsciiToBinary ${VERBOSE} -chrom=chr1_2 -name=end -offset=246127778 chr1_end.ascii
wigAsciiToBinary ${VERBOSE} -chrom=chr1_1 -offset=162 -name=middle -binsize=1 \
	-dataSpan=240359 chr1_middle.ascii
hgLoadWiggle -verbose -tab wiggleTest chr1 chr1_0.wig chr1_1.wig \
	chr1_2.wig

#	Create a test data set for a cb1 browser view at its default
#	location.  18,162 points, frequency of 5
${TEST_PL}/testData.pl 18162 5 > cb1.test.ascii

wigAsciiToBinary ${VERBOSE} -chrom=chrUn -name=wig_test \
	-offset=74980670 -binsize=1 cb1.test.ascii

