#!/bin/tcsh -efx
# Script to create a relational version of UniProt database.  Should be run on
# hgwdev.

# Set up working directory
mkdir -p /hive/data/outside/swissprot/090821/build

# Download swissprot. This will take about 90 minutes.
cd /hive/data/outside/swissprot/090821/build
wget ftp://ftp.expasy.org/databases/uniprot/current_release/knowledgebase/complete/uniprot_sprot.dat.gz
wget ftp://ftp.expasy.org/databases/uniprot/current_release/knowledgebase/complete/uniprot_trembl.dat.gz
wget ftp://ftp.expasy.org/databases/uniprot/current_release/knowledgebase/complete/uniprot_sprot_varsplic.fasta.gz

# Turn flat file into relational tab-separated files.  The -dupeOk flag was
# needed this time for spToDb since their were things in swissProt that had
# not been removed from trEMBL.   This step takes about 20 minutes.
zcat *.dat.gz | spToDb stdin ../tabFiles

# Create the database.  
hgsql mysql <<end
create database sp090821;
end

# Load it up with table definitions from source directory
hgsql sp090821 < ~/kent/src/hg/protein/spToDb/spDb.sql

# Load up the data from tab files.  This takes about an hour.
cd /hive/data/outside/swissprot/090821/tabFiles
foreach i (*.txt)
    hgsqlimport --local sp090821 $i
end

# Add varsplice info 
zcat ../build/uniprot_sprot_varsplic.fasta.gz | spDbAddVarSplice sp090821 stdin .
hgLoadSqlTab sp090821 -append varProtein /dev/null varProtein.txt
hgLoadSqlTab sp090821 -append protein /dev/null varProtein.txt
hgLoadSqlTab sp090821 -append varAcc /dev/null varAcc.txt
hgLoadSqlTab sp090821 -append displayId /dev/null varDisplayId.txt
hgLoadSqlTab sp090821 -append accToTaxon /dev/null varAccToTaxon.txt
hgLoadSqlTab sp090821 -append geneLogic /dev/null varGeneLogic.txt
hgLoadSqlTab sp090821 -append gene /dev/null varGene.txt
hgLoadSqlTab sp090821 -append description /dev/null varDescription.txt

# Add table descriptions
makeTableDescriptions sp090821 ~/kent/src/hg/protein/spToDb/spDbTables.as

# Zip up tab files for people who prefer them to database.
gzip *.txt


