First complete Projects/Tasks build.
[htsworkflow.git] / htswanalysis / scripts / LibrariesMakefile
1 #
2 # Makefile to bring new flowcells ointo the repository. A few bits of computation are done upfront:
3 #
4 #  qPCR -- checks in-silico to see if the lane looks like a factor we know about
5 #  count -- counts the number of (not adapter) aligned reads in the lane
6 #  complexity -- looks for isolated peaks that are a symptom of low-complexity libraries (or sequencing of a restriction enzyme)
7 #  profile -- profile of read density relative to the TSS
8 #  libfiles -- the configure files for the libraries
9 #
10 # Once the makefile has run once (please, for your sanity, use make -j N (where N is the number of CPU cores you have),
11 # then you need to run it again to actually make the libraries proper. This will be (needs to be fixed).
12 #
13 # Upon completion, all the above preprocessing is placed in all the flowcell directories, and the libraries are up-to-date.
14
15
16 #
17 # HTSW_ANALYSIS_ROOT is the location of all the programs used and 
18 #    should be defined in the environment
19 # DATA_DIR is the base directory of the flowcells repoitory
20 #
21 ROOT_DIR=$(HTSW_ANALYSIS_ROOT)
22 DATA_DIR=/Users/Data
23 HTML_DIR=/Library/WebServer/Documents/SequencingSummaries
24
25 # Error messages are collected so as not to bug the user. (if there are no matching files, ls errors.)
26 FILES=$(shell ls -1d $(DATA_DIR)/Flowcells/**/*.align*.txt 2>> LibrariesMakefile.err)
27 QPCR_FILES=$(shell ls -1d $(DATA_DIR)/Flowcells/**/*.align*.txt 2>> LibrariesMakefile.err | sed -e s/txt/txt.qPCR/)
28 COUNT_FILES=$(shell ls -1d $(DATA_DIR)/Flowcells/**/*.align*.txt 2>> LibrariesMakefile.err | sed -e s/txt/txt.count/)
29 CMPLX_FILES=$(shell ls -1d $(DATA_DIR)/Flowcells/**/*.align*.txt 2>> LibrariesMakefile.err | sed -e s/txt/txt.complexity/)
30 PROFILE_FILES=$(shell ls -1d $(DATA_DIR)/Flowcells/**/*.align*.txt 2>> LibrariesMakefile.err | sed -e s/txt/txt.profile/)
31 LIBFILES=$(shell ls -1d $(DATA_DIR)/Libraries/.*.config 2>> LibrariesMakefile.err | sed -e s/config/txt/ -e "s/\/\./\//")
32
33 all: $(QPCR_FILES) $(COUNT_FILES) $(FILES) $(DATA_DIR)/qPCR_summary.txt $(DATA_DIR)/LibraryInfo.xml $(LIBFILES) $(DATA_DIR)/SequencingSummary.html Distribute
34
35 %.txt.complexity: %.txt
36         $(ROOT_DIR)/bin/complexity_count `basename $<` $< > $@
37
38 %.txt.count: %.txt
39         grep -v contam $< | awk '{if(NF > 3) {print $$1} }' | wc -l > $@;
40
41 %.txt.qPCR: %.txt
42         $(ROOT_DIR)/bin/qPCR $(subst .txt.qPCR,.txt,$@) $(ROOT_DIR)/reference_data/GenericBackground $(ROOT_DIR)/reference_data/qPCR_Tests/ | sort -k 2 -g -r > $@
43
44 %.txt.profile: %.txt
45         $(ROOT_DIR)/profile_reads/profile_reads_against_features `echo $@ | sed -e s/\.profile//` $(ROOT_DIR)/reference_data/`basename $@ | awk -F\. '{ print $$3 }'`_tx_start_sites > $@
46         $(ROOT_DIR)/profile_reads/profile_to_svg.pm $@ > $@.svg
47
48 $(DATA_DIR)/Libraries/%.txt: $(DATA_DIR)/Libraries/.%.config | LibraryInfo.xml
49         cat `cat $<` > $@;
50
51 $(DATA_DIR)/qPCR_summary.txt: $(QPCR_FILES)
52         rm -f $@;
53         for f in $^; do echo `echo $$f`       `cat $$f | head -n 1` >> $@; done;
54         cat $@ | sort -k 2,1 -g -r > t && mv t $@;
55
56 $(DATA_DIR)/LibraryInfo.xml: $(COUNT_FILES) $(CMPLX_FILES)
57         $(ROOT_DIR)/scripts/CollectLibraries.pm $(DATA_DIR) > $@;
58         $(ROOT_DIR)/scripts/RecompileLibraries.pm $@ $(DATA_DIR)
59
60 $(DATA_DIR)/SequencingSummary.html: $(DATA_DIR)/LibraryInfo.xml
61         $(ROOT_DIR)/scripts/SummarizeLibrary.pm $< > $@;
62
63 Distribute: SequencingSummary.html qPCR_summary.txt
64         cp $^ $(HTML_DIR);
65
66 Libraries: $(LIBFILES)