Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.
Make                      Pierre Lindenbaum              http://plindenbaum.blogspot.com          @yokofakun(http://twitte...
Problem
Build a C program
Make a protein#!/bin/bashTRANSCRIPT=catTRANSLATE=catrm -f merge.proteinfor DNA in file1.dna file2.dna file3.dnado echo "AT...
What if file1.pep already exists ?
Solution: Test if file exists#!/bin/bashTRANSCRIPT=catTRANSLATE=catrm -f merge.proteinfor DNA in file1.dna file2.dna file3...
What if file1.pep is outdated ?
Parallelization ?
GNU make
"a utility that automaticallybuilds executable programs and libraries from source code by reading files called makefiles"
1977
TARGET1: DEPENDENCIES            COMMAND-LINES1            COMMAND-LINES2            COMMAND-LINES3
MakefileTRANSCRIPT=catTRANSLATE=catmerged.protein: file1.pep file2.pep file3.pep    cat file1.pep file2.pep         file3....
Outputecho "ATGCTAGTAGATGC" > file1.dnacat file1.dna > file1.rnacat file1.rna > file1.pepecho "ATGCTAGTAGATGC" > file2.dna...
If one file is removed$ rm file2.rna$ makecat file2.dna   > file2.rnacat file2.rna   > file2.pepcat file1.pep   file2.pep ...
If one file is changed$ touch file1.dna file3.pep$ makecat file1.dna   > file1.rnacat file1.rna   > file1.pepcat file1.pep...
Special variables
"name of the target" : $@TRANSCRIPT=catTRANSLATE=catmerged.protein: file1.pep file2.pep file3.pep    cat file1.pep file2.p...
"name of the first dependency" : $<TRANSCRIPT=catTRANSLATE=catmerged.protein: file1.pep file2.pep file3.pep    cat file1.p...
"all the dependencies" : $^TRANSCRIPT=catTRANSLATE=catmerged.protein: file1.pep file2.pep file3.pep    cat $^ > $@file1.pe...
Rules
How to create a *.pep or a *.rna ?TRANSCRIPT=catTRANSLATE=cat%.pep:%.rna    ${TRANSLATE} $< > $@%.rna:%.dna    ${TRANSCRIP...
Outputecho "ATGCTAGTAGATGC" > file1.dnacat file1.dna > file1.rnacat file1.rna > file1.pepecho "ATGCTAGTAGATGC" > file2.dna...
Useful options
-B "Unconditionally make all targets"
-f FILE "Read FILE as a makefile"
-j [N] "Allow N jobs at once"
-n "Dont actually run any commands; just print them"
.PHONY targets.PHONY: all cleanall: file1.dnafile1.dna:       echo "ATGCTAGTAGATGC" > $@clean:       rm -f file1.dna
Function Call Syntax$(function arg1,arg2,arg3...)
Loops: $(foreach var,list,...)merged.protein:    $(foreach INDEX,1 2 3,file${INDEX}.pep ) cat $^ > $@
$(eval )TRANSCRIPT=catTRANSLATE=catINDEXES=1 2 3%.pep:%.rna    ${TRANSLATE} $< > $@%.rna:%.dna    ${TRANSCRIPT} $< > $@mer...
$(subst ee,EE,feet on the street) ‘fEEt on the strEEt’.$(patsubst %.c,%.o,x.c.c bar.c) ‘x.c.o bar.o’. $(strip a b c )‘a b c’
$(filter %.c,src1.c src2.c src3.c file.txt) $(filter-out %.c,src1.c src2.c src3.c file.txt)$(sort foo bar lose)$(word 2, f...
$(dir src/foo.c hacks)‘src/ ./’$(notdir src/foo.c hacks)‘foo.c hacks’$(suffix src/foo.c src-1.0/bar.c hacks)‘.c .c’$(basen...
(join a b,.c .o)‘a.c b.o’$(shell cat file1.txt)
END
Upcoming SlideShare
Loading in …5
×

Make

1,203 views

Published on

My short course about "Make"/"Makefile" and bioinformatics. January 2013

Published in: Technology
  • Be the first to comment

Make

  1. 1. Make Pierre Lindenbaum http://plindenbaum.blogspot.com @yokofakun(http://twitter.com/yokofakun) INSERM-UMR1087 Nantes January 2013https://github.com/lindenb/courses/tree/master/about.make
  2. 2. Problem
  3. 3. Build a C program
  4. 4. Make a protein#!/bin/bashTRANSCRIPT=catTRANSLATE=catrm -f merge.proteinfor DNA in file1.dna file2.dna file3.dnado echo "ATGCTAGTAGATGC" > ${DNA} ${TRANSCRIPT} ${DNA} > ${DNA/%.dna/.rna} ${TRANSLATE} ${DNA/%.dna/.rna} > ${DNA/%.dna/.pep} cat ${DNA/%.dna/.pep} >> merge.proteindone
  5. 5. What if file1.pep already exists ?
  6. 6. Solution: Test if file exists#!/bin/bashTRANSCRIPT=catTRANSLATE=catrm -f merge.proteinfor DNA in file1.dna file2.dna file3.dnado echo "ATGCTAGTAGATGC" > ${DNA} ${TRANSCRIPT} ${DNA} > ${DNA/%.dna/.rna} if [ ! -f ${DNA/%.dna/.pep} ] then ${TRANSLATE} ${DNA/%.dna/.rna} > ${DNA/%.dna/.pep} fi cat ${DNA/%.dna/.pep} >> merge.proteindone
  7. 7. What if file1.pep is outdated ?
  8. 8. Parallelization ?
  9. 9. GNU make
  10. 10. "a utility that automaticallybuilds executable programs and libraries from source code by reading files called makefiles"
  11. 11. 1977
  12. 12. TARGET1: DEPENDENCIES COMMAND-LINES1 COMMAND-LINES2 COMMAND-LINES3
  13. 13. MakefileTRANSCRIPT=catTRANSLATE=catmerged.protein: file1.pep file2.pep file3.pep cat file1.pep file2.pep file3.pep > merged.proteinfile1.pep: file1.rna ${TRANSLATE} file1.rna > file1.pepfile1.rna : file1.dna ${TRANSCRIPT} file1.dna > file1.rnafile1.dna: echo "ATGCTAGTAGATGC" > file1.dna
  14. 14. Outputecho "ATGCTAGTAGATGC" > file1.dnacat file1.dna > file1.rnacat file1.rna > file1.pepecho "ATGCTAGTAGATGC" > file2.dnacat file2.dna > file2.rnacat file2.rna > file2.pepecho "ATGCTAGTAGATGC" > file3.dnacat file3.dna > file3.rnacat file3.rna > file3.pepcat file1.pep file2.pep file3.pep > merged.protein
  15. 15. If one file is removed$ rm file2.rna$ makecat file2.dna > file2.rnacat file2.rna > file2.pepcat file1.pep file2.pep file3.pep > merged.protein
  16. 16. If one file is changed$ touch file1.dna file3.pep$ makecat file1.dna > file1.rnacat file1.rna > file1.pepcat file1.pep file2.pep file3.pep > merged.protein
  17. 17. Special variables
  18. 18. "name of the target" : $@TRANSCRIPT=catTRANSLATE=catmerged.protein: file1.pep file2.pep file3.pep cat file1.pep file2.pep file3.pep > $@file1.pep: file1.rna ${TRANSLATE} file1.rna > $@file1.rna : file1.dna ${TRANSCRIPT} file1.dna > $@file1.dna: echo "ATGCTAGTAGATGC" > $@
  19. 19. "name of the first dependency" : $<TRANSCRIPT=catTRANSLATE=catmerged.protein: file1.pep file2.pep file3.pep cat file1.pep file2.pep file3.pep > $@file1.pep: file1.rna ${TRANSLATE} $< > $@file1.rna : file1.dna ${TRANSCRIPT} $< > $@file1.dna: echo "ATGCTAGTAGATGC" > $@
  20. 20. "all the dependencies" : $^TRANSCRIPT=catTRANSLATE=catmerged.protein: file1.pep file2.pep file3.pep cat $^ > $@file1.pep: file1.rna ${TRANSLATE} $< > $@file1.rna : file1.dna ${TRANSCRIPT} $< > $@file1.dna: echo "ATGCTAGTAGATGC" > $@file2.pep: file2.rna
  21. 21. Rules
  22. 22. How to create a *.pep or a *.rna ?TRANSCRIPT=catTRANSLATE=cat%.pep:%.rna ${TRANSLATE} $< > $@%.rna:%.dna ${TRANSCRIPT} $< > $@merged.protein: file1.pep file2.pep file3.pep cat $^ > $@file1.dna: echo "ATGCTAGTAGATGC" > $@file2.dna: echo "ATGCTAGTAGATGC" > $@file3.dna: echo "ATGCTAGTAGATGC" > $@
  23. 23. Outputecho "ATGCTAGTAGATGC" > file1.dnacat file1.dna > file1.rnacat file1.rna > file1.pepecho "ATGCTAGTAGATGC" > file2.dnacat file2.dna > file2.rnacat file2.rna > file2.pepecho "ATGCTAGTAGATGC" > file3.dnacat file3.dna > file3.rnacat file3.rna > file3.pepcat file1.pep file2.pep file3.pep > merged.prot
  24. 24. Useful options
  25. 25. -B "Unconditionally make all targets"
  26. 26. -f FILE "Read FILE as a makefile"
  27. 27. -j [N] "Allow N jobs at once"
  28. 28. -n "Dont actually run any commands; just print them"
  29. 29. .PHONY targets.PHONY: all cleanall: file1.dnafile1.dna: echo "ATGCTAGTAGATGC" > $@clean: rm -f file1.dna
  30. 30. Function Call Syntax$(function arg1,arg2,arg3...)
  31. 31. Loops: $(foreach var,list,...)merged.protein: $(foreach INDEX,1 2 3,file${INDEX}.pep ) cat $^ > $@
  32. 32. $(eval )TRANSCRIPT=catTRANSLATE=catINDEXES=1 2 3%.pep:%.rna ${TRANSLATE} $< > $@%.rna:%.dna ${TRANSCRIPT} $< > $@merged.protein: $(foreach INDEX,${INDEXES},file${INDEX} cat $^ > $@$(foreach INDEX,${INDEXES},$(eval file${INDEX}: echo "ATGCTAGTAGATGC" > $$@ ))
  33. 33. $(subst ee,EE,feet on the street) ‘fEEt on the strEEt’.$(patsubst %.c,%.o,x.c.c bar.c) ‘x.c.o bar.o’. $(strip a b c )‘a b c’
  34. 34. $(filter %.c,src1.c src2.c src3.c file.txt) $(filter-out %.c,src1.c src2.c src3.c file.txt)$(sort foo bar lose)$(word 2, foo bar baz) bar$(wordlist 2, 3, foo bar baz)‘bar baz’.$(firstword foo bar)‘foo’.$(lastword foo bar)‘bar’.
  35. 35. $(dir src/foo.c hacks)‘src/ ./’$(notdir src/foo.c hacks)‘foo.c hacks’$(suffix src/foo.c src-1.0/bar.c hacks)‘.c .c’$(basename src/foo.c src-1.0/bar hacks)‘src/foo src-1.0/bar hacks’$(addsuffix .c,foo bar)‘foo.c bar.c’.$(addprefix src/,foo bar)‘src/foo src/bar’
  36. 36. (join a b,.c .o)‘a.c b.o’$(shell cat file1.txt)
  37. 37. END

×