JPRED-2 Initial commit of software for the Jpred website (some files excluded due...
[jpred.git] / websoft / bin / Makefile
diff --git a/websoft/bin/Makefile b/websoft/bin/Makefile
new file mode 100755 (executable)
index 0000000..40b398f
--- /dev/null
@@ -0,0 +1,139 @@
+# Makefile for construction of databases that Jpred uses.
+# The pdb make target has been over documented so as to provide
+# explanation of the method behind the madness.
+# All variables are defined at the top of the file, and then targets
+# are defined afterwards
+
+# Suffixes created by BLAST, ptm is also created, but I think this is
+# a temporary file, so is mentioned explicitly in the clean target
+BLAST_SUFFIX = .phr .pin .psd .psi .psq
+
+# Specifically add path for some of the commands so we know we'll
+# find them
+PATH := $(PATH):/r0/www_servers/jpred/jpred_bin:/site/Linux/bin
+
+# Define commands that occur multiple times
+# The wget command means that you have to give the output location first,
+# then the target
+WGET = wget -N -t 10
+FORMATDB = formatdb -o T -i
+
+# Variables specific for PDB stuff
+# URL to get the file from
+PDB_URL = ftp://ftp.ebi.ac.uk/pub/databases/msd/pdb_aa.fasta
+PDB_FILE = $(notdir $(PDB_URL))
+# Target path to download to
+PDB_FASTA = pdb.fasta
+# Files created by running formatdb on $(PDB_FASTA)
+PDB_BLAST = $(addprefix $(PDB_FASTA), $(BLAST_SUFFIX))
+# Directory to install the files into
+#PDB_TARGET = /r0/www_servers/jpred/databases/pdb
+PDB_TARGET = /tmp/jpred/databases/pdb
+# The target paths of the files that are to be installed
+PDB_INSTALL =  $(addprefix $(PDB_TARGET)/, $(PDB_BLAST) $(PDB_FASTA))
+
+# Variables specific for SWALL
+SP_URL = ftp://ftp.ebi.ac.uk/pub/databases/sp_tr_nrdb/fasta/sprot.fas.gz
+SP_FILE = $(notdir $(SP_URL))
+TREMBL_URL = ftp://ftp.ebi.ac.uk/pub/databases/sp_tr_nrdb/fasta/trembl.fas.gz 
+TREMBL_FILE = $(notdir $(TREMBL_URL))
+
+SWALL_FASTA = swall.fasta
+SWALL_INDX = swall.jidx
+SWALL_FILT = swall.filt
+SWALL_BLAST = $(addprefix $(SWALL_FILT), $(BLAST_SUFFIX))
+SWALL_TARGET = /tmp/jpred/cluster/packages/jpred_swall
+SWALL_INSTALL = $(addprefix $(SWALL_TARGET)/, $(SWALL_BLAST) $(SWALL_FASTA) $(SWALL_FILT))
+
+######################################################################
+all: pdb.db swall.db
+
+######################################################################
+# PDB FASTA seqeunce database
+
+# Heirarchy of dependancies (indentation denotes dependancy):
+# /installation/dir/pdb.fasta{,.{phr,pin,psd,psi,psq}}
+#      pdb_wget
+#      pdb.fasta{.{phr,pin,psd,psi,psq}}
+#              pdb.fasta
+#                      pdb_aa.fasta
+# pdb_wget creates pdb_aa.fasta
+
+# This states that the PDB target depends upon the pdb_wget target and
+# the files in the variable $(PDB_INSTALL), this is the group of formatdb
+# index files and the original FASTA file used to create them in the
+# installation directory
+pdb.db: pdb_wget $(PDB_INSTALL)
+
+# This installs the files into the final directory
+$(PDB_INSTALL): $(PDB_BLAST)
+       mkdir -p $(PDB_TARGET)
+       install -m 644 $(PDB_BLAST) $(PDB_FASTA) $(PDB_TARGET)
+
+# Do BLAST DB formating. This depends on a group of files, so if any of
+# them are deleted/too old, then they're reformated.
+$(PDB_BLAST): $(PDB_FASTA)
+       $(FORMATDB) $(PDB_FASTA)
+
+$(PDB_FASTA): $(PDB_FILE)
+       cp $(PDB_FILE) $(PDB_FASTA)
+
+# This is a phony rule that's always executed, in this case it's to check
+# whether a newer version of the PDB FASTA file has been deposited on the
+# FTP site.
+# It has to be a phony rule as if it's made a normal rule that depends
+# on the file that's downloaded, its always considered upto date and the
+# wget command isn't run.
+.PHONY: pdb_wget
+pdb_wget:
+       $(WGET) $(PDB_FASTA) $(PDB_URL)
+       
+######################################################################
+
+swall.db: sp_wget trembl_wget $(SWALL_INSTALL)
+
+$(SWALL_INSTALL): $(SWALL_BLAST) $(SWALL_FASTA) $(SWALL_FILT) $(SWALL_INDX)
+       mkdir -p $(SWALL_TARGET)
+       install -m 644 $(SWALL_BLAST) $(SWALL_FASTA) $(SWALL_FILT) $(SWALL_INDX) $(SWALL_TARGET)
+
+$(SWALL_BLAST): $(SWALL_FILT)
+       $(FORMATDB) $(SWALL_FILT)
+
+# This next line defines a temporary variable for the target
+$(SWALL_FILT): TMP_FILE := $(shell tempfile -d /r0/scratch) 
+$(SWALL_FILT): $(SWALL_FASTA)
+       seg $(SWALL_FASTA) 12 2.2 2.5 -x > $(TMP_FILE)
+       ~/src/helixfilt/helixfilt $(TMP_FILE) > $(SWALL_FILT)
+       rm $(TMP_FILE)
+
+$(SWALL_INDX): $(SWALL_FASTA)
+       db_dbmindex $(SWALL_FASTA) $(SWALL_INDX)
+
+$(SWALL_FASTA): $(SP_FILE) $(TREMBL_FILE)
+       gzip -c -d $(SP_FILE) > $(SWALL_FASTA)
+       gzip -c -d $(TREMBL_FILE) >> $(SWALL_FASTA)
+
+$(SP_FILE): sp_wget
+
+$(TREMBL_FILE): trembl_wget
+
+.PHONY: sp_wget
+sp_wget:
+       $(WGET) $(SP_URL)
+
+.PHONY: trembl_wget
+trembl_wget:
+       $(WGET) $(TREMBL_URL)
+
+######################################################################
+clean:
+       -rm $(SWALL_FASTA) $(SWALL_INDX) $(SWALL_FILT) $(SWALL_BLAST)
+       -rm $(PDB_FASTA) $(PDB_BLAST)
+       -rm formatdb.log *.ptm
+
+distclean: clean
+       -rm $(PDB_FILE) $(SP_FILE) $(TREMBL_FILE)
+
+installclean:
+       -rm -r $(SWALL_TARGET)
+       -rm -r $(PDB_TARGET)