SlideShare uma empresa Scribd logo
1 de 54
Baixar para ler offline
Programming for Evolutionary Biology
         March 17th - April 1st 2012
             Leipzig, Germany




Introduction to Unix systems
Extra: writing simple pipelines
           with make
         Giovanni Marco Dall'Olio
         Universitat Pompeu Fabra
             Barcelona (Spain)
GNU/make
   make is a tool to store command­line instructions 
     and re­execute them quickly, along with all their 
     parameters
   It is a declarative programming language
   It belongs to a class of softwares called 'automated 
       build tools'
Simplest Makefile example
   The simplest Makefile contains just the name of a task and 
      the commands associated with it:




   print_hello is a makefile 'rule': it stores the commands
    needed to say 'Hello, world!' to the screen.
Simplest Makefile example




                                          Makefile rule
Target of the
rule


                    Commands associated
  This is a         with the rule
  tabulation (not
  8 spaces)
Simplest Makefile example
   Create a file in your 
      computer and save it as 
      'Makefile'.
   Write these instructions in it:

      print_hello:
          echo 'Hello, world!!'
                                      This is a tabulation
   Then, open a terminal and         (<Tab> key)
      type:
    make -f Makefile print_hello
Simplest Makefile example
Simplest Makefile example
            –
       explanation




   When invoked, the program 'make' looks for a file in the 
     current directory called 'Makefile'
   When we type 'make print_hello', it executes any procedure 
     (target) called 'print_hello' in the makefile
   It then shows the commands executed and their output
Tip1: the 'Makefile' file
   The '­f' option allows you to define the file which 
     contains the instructions for make
   If you omit this option, make will look for any file 
       called 'Makefile' in the current directory

      make -f Makefile all

      is equivalent to:

      make all
A sligthly longer example
   You can add as many 
     commands you like 
     to a rule
   For example, this 
      'print_hello' rule 
      contains 5 commands
   Note: ignore the '@' 
     thing, it is only to 
     disable verbose mode 
     (explained later)
A more complex example
Make - advantages
   Make allows you to save shell commands along 
     with their parameters and re­execute them;
   It allows you to use command­line tools which are 
       more flexible;
   Combined with a revision control software, it 
     makes possible to reproduce all the operations 
     made to your data;
Second part



A closer look at make syntax (target and
               commands)
The target syntax
   Makefile syntax:
         <target>: (prerequisites)
            <commands associated to the
          rule>
The target syntax
   The target of a rule can be either a title for the task, or a file 
      name.
   Everytime you call a make rule (example: 'make all'), the 
      program looks for a file called like the target name (e.g. 
      'all', 'clean', 'inputdata.txt', 'results.txt')
   The rule is executed only if that file doesn't exists.
Filename as target names
                     In this
                      makefile, we
                      have two rules:
                      'testfile.txt' and
                      'clean'
Filename as target names
                     In this
                      makefile, we
                      have two rules:
                      'testfile.txt' and
                      'clean'

                     When we call
                      'make
                      testfile.txt',
                      make checks if
                      a file called
                      'testfile.txt'
                      already exists.
Filename as target names




                  The commands
                  associated with the
                  rule 'testfile.txt' are
                  executed only if
                  that file doesn't
                  exists already
Multiple target definition
   A target can also be a 
      list of files
   You can retrieve the 
      matched target with 
      the special variable 
      $@
Special characters
   The % character can be used as a wild card
   For example, a rule with the target:
     %.txt:
         ....
     would be activated by any file ending with '.txt'
          'make 1.txt', 'make 2.txt', etc..
   We will be able to retrieve the matched expression 
     with '$*'
Special character % /
creating more than a file at
           a time
Makefile – cluster support
   Note that in the previous 
      example we created three 
      files at the same time, by 
      executing three times the 
      command 'touch'
   If we use the '­j' option when 
       invoking make, the three 
       processess will be launched 
       in parallel
The commands syntax
   Makefile syntax:
         <target>: (prerequisites)
            <commands associated to the
          rule>
Inactivating verbose mode
    You can disactivate the verbose mode for a line by 
      adding '@' at its beginning:




Differences here
Skipping errors
   The modifiers '­' tells make to ignore errors returned 
     by a command
   Example: 
          'mkdir /var' will cause an error (the '/var' directory 
             already exists) and cause gnu/make to exit
          '­mkdir /var' will cause an error anyway, but 
             gnu/make will ignore it
Moving throught directories
   A big issue with make is that every line is executed as a 
      different shell process.
   So, this:

      lsvar:
         cd /var
         ls 
    Won't work (it will list only the files in the current 
     directory, not /var)
   The solution is to put everything in a single process:
    lsvar:
          (cd /var; ls)
Third part




Prerequisites and conditional execution
The commands syntax
   Makefile syntax:
         <target>: (prerequisites)
            <commands associated to the
          rule>
   We will look at the 'prerequisites' part of a make 
     rule, that I had skipped before
Real Makefile-rule syntax
   Complete syntax for a Makefile rule:
          <target>: <list of prerequisites>
             <commands associated to the rule>


   Example:
          result1.txt: data1.txt data2.txt
            cat data1.txt data2.txt > result1.txt
            @echo 'result1.txt' has been calculated'


   Prerequisites are files (or rules) that need to exists already in 
      order to create the target file.
   If 'data1.txt' and 'data2.txt' don't exist, the rule 'result1.txt' will 
       exit with an error (no rule to create them)
Piping Makefile rules
             together
   You can pipe two Makefile rules together by 
     defining prerequisites
Piping Makefile rules
              together
   The rule 'result1.txt' depends on the rule 'data1.txt', 
     which should be executed first
Piping Makefile rules
                together
   Let's look at this 
      example 
      again:
    what happens if 
      we remove the 
      file 'result1.txt' 
      we just 
      created?
Piping Makefile rules
                together
   Let's look at this 
      example 
      again:
    what happens if 
      we remove the 
      file 'result1.txt' 
      we just 
      created?
   The second time 
      we run the 
      'make 
      result1.txt' 
      command, it is 
      not necessary 
      to create 
      data1.txt 
Other pipe example
   all: result1.txt result2.txt

      result1.txt: data1.txt
      calculate_result.py
        python calculate_result.txt --input
      data1.txt

      result2.txt: data2.txt
        cut -f 1, 3 data2.txt > result2.txt
   Make all will calculate result1.txt and result2.txt, if 
     they don't exist already (and they are older than 
     their prerequisites)
Conditional execution by
       modification date
   We have seen how make can be used to create a 
     file, if it doesn't exists.

      file.txt:
         # if file.txt doesn't exists, then create it:
         echo 'contents of file.txt' > file.txt

   We can do better: create or update a file only if it is 
     newer than its prerequisites
Conditional execution by
       modification date
   Let's have a better look at this example:

      result1.txt: data1.txt
      calculate_result.py
        python calculate_result.txt --input
      data1.txt
   A great feature of make is that it execute a rule not 
     only if the target file doesn't exist, but also if it 
     has a 'last modification date' earlier than all of its 
     prerequisites
Conditional execution by
       modification date
    result1.txt: data1.txt
        @sed 's/b/B/i' data1.txt > result1.txt
        @echo 'result1.txt has been calculated'
   In this example, result1.txt will be recalculated 
      every time 'data1.txt' is modified
    $: touch data1.txt calculate_result.py
      $: make result1.txt
      result1.txt has been calculated
      $: make result1.txt
      result1.txt is already up-to-date
      $: touch data1.txt
      $: make result1.txt
      result1.txt has been calculated
Conditional execution -
          applications
   This 'conditional execution by modification date 
     comparison' feature of make is very useful
   Let's say you discover an error in one of your input 
     data: you will be able to repeat the analysis by 
     executing only the operations needed
   You can also use it to re­calculate results every time 
     you modify a script:

      result.txt: scripts/calculate_result.py
        python calculate_result.py > result.py
Another example
Fourth part




Variables and functions
Variables and functions
   You may have already noticed that Make's syntax is 
     really old :)
   In fact, it is a ~40 years old language
   It uses special variables like $@, $^, and it can be 
       worst than perl!!! 
   (perl developers – please don't get mad at me :­) )
Variables
      Variables are declared with a '=' and by convention 
        are upper case.
      They are called by including their name in '$()'
         

WORKING_DIR
is a variable
Special variables - $@
   Make uses some custom variables, with a syntax 
     similar to perl
   '$@' always corresponds to the target name:

     $: cat >Makefile

     %.txt:
        echo $@

     $: make filename.txt        $@ took the value of
     echo filename.txt           'filename.txt'
     filename.txt
Other special variables


$@           The rule's target
$<           The rule's first
             prerequisite
$?           All the rule's out of
             date prerequisites
$^           All Prerequisites
Functions
   Usually you don't want to declare functions in 
     make, but there are some built­in utilities that can 
     be useful 
   Most frequently used functions:
       $(addprefix <prefix>, list)
         → add a prefix to a space­separated list 

      example:
       FILES = file1 file2 file3
       $(addprefix /home/user/data, $(FILES)
   $(addsuffix) work similarly
Full makefile example
INPUTFILES = lower_DAF lower_maf upper_maf 
                               lower_daf upper_daf
RESULTSDIR = ./results
RESULTFILES = $(addprefix $(RESULTSDIR)/, 
              $(addsuffix _filtered.txt,$(INPUTFILES)
help:
        @echo 'type "make filter" to calculate results'
all: $(RESULTFILES)
$(RESULTSDIR)/%_filtered.txt: data/%.txt
    src/filter_genes.py
    python src/filter_genes.py --genes 
            data/Genes.txt --window $< --output $@
   It looks like very complicated, but in the end
    you always use the same Makefile structure
Fifth part




Testing, discussion, other examples and
              alternatives
Testing a makefile
   make ­n: only shows the commands to be executed
   You can pass variables to make:
     $: make say_hello MYNAME=”Giovanni”
     hello, Giovanni
   Strongly suggested: use a Revision Control 
      Software with support for branching (git, hg, 
      bazaar) and create a branch for testing
Another complex Makefile
               example
         # make masked sequence                   our starting point is the 
         myseq.m: myseq                            file myseq, the end point 
           rmask myseq > myseq.m
                                                   is the blast results blastout
         # run blast on masked seq
         blastout: mydb.psq myseq.m               we first want to mask out 
            blastx mydb myseq.m > blastout         any repeats using rmask to 
            echo “ran blast!”                      create myseq.m
         # index blastable db                     we then blastx myseq.m 
         mydb.psq: mydb
                                                   against a protein db called 
           formatdb -p T mydb
                                                   mydb
         # rules follow this pattern:
         target: subtarget1, ..., subtargetN
                                                  before blastx is run the 
             shell command 1                       protein db must be 
             shell command 2...                    indexed using formatdb
(slide taken from biomake web site)
The “make” command
                                     % make blastout
   # run blast on masked seq
                                     formatdb -p T mydb
   blastout: mydb.psq myseq.m        rmask myseq.fst > myseq.m
      blastx mydb myseq.m > blastout blastx mydb myseq.m > blastout
       echo “ran blast!”
                                      % make blastout
   # index blastable db               make: 'blastout' is up to date
   mydb.psq: mydb
                                      % cat newseqs >> mydb
     formatdb -p T mydb               % make blastout
                                      formatdb -p T mydb
   # make masked sequence             blastx mydb myseq.m > blastout
   myseq.m: myseq
     rmask myseq > myseq.m               make uses unix file 
                                          modification timestamps when 
                                          checking dependencies
                                              if a subtarget is more recent 
                                               than the goal target, then 
(slide taken from biomake web site)            re­execute action
BioMake and alternatives
   BioMake is an alternative to make, thought to be 
     used in bioinformatics
   Developed to annotate the Drosophila 
     melanogaster genome (Berkeley university)
   Cleaner syntax,derived from prolog
   Separates the rule's name from the name of the 
      target files
A BioMake example
       formatdb(DB)
          req: DB
          run: formatdb DB
          comment: prepares blastdb for blasting (wublast)
       rmask(Seq)
          flat: masked_seqs/Seq.masked
          req: Seq
          srun: RepeatMasker -lib $(LIB) Seq
          comment: masks out repeats from input sequence
       mblastx(Seq,DB)
          flat: blast_results/Seq.DB.blastx
          req: formatdb(DB) rmask(Seq)
          srun: blastx -filter SEG+XNU DB rmask(Seq)
          comment: this target is for the results of running blastx on
                       a masked input genomic sequence (wublast)
(slide taken from biomake web site)
Other alternatives
   There are other many alternatives to make:
           BioMake (prolog?)
           o/q/dist/etc.. make
           Ant (Java)
           Scons (python)
           Paver (python)
           Waf (python)
   This list is biased because I am a python programmer :)
   These tools are more oriented to software development
Conclusions
   Make is very basic for bioinformatics
   It is useful for the simpler tasks:
            Logging the operations made to your data files
            Working with clusters
            Avoid re­calculations
            Apply a pipeline to different datasets
   It is installed in almost any unix system and has a standard 
       syntax (interchangeable, reproducible)
   Study it and understand its logic. Use it in the most basic way, 
      without worrying about prerequisites and special variables. 
      Later you can look for easier tools (biomake, rake, taverna, 
Suggested readings
   Software Carpentry for bioinformatics 
         http://swc.scipy.org/lec/build.html
   A Makefile is a pipeline
        http://www.nodalpoint.org/2007/03/18/a_pipeline_is_a_makefil
   BioMake and SKAM 
        http://skam.sourceforge.net/
   BioWiki Make Manifesto 
        http://biowiki.org/MakefileManifesto
   Discussion on the BIP mailing list
         http://www.mail­archive.com/biology­in­python@lists.idyll.org
   Gnu/Make manual by R.Stallman and R.MacGrath
          http://theory.uwinnipeg.ca/gnu/make/make_toc.html 

Mais conteúdo relacionado

Mais procurados

PYTHON -Chapter 2 - Functions, Exception, Modules and Files -MAULIK BOR...
PYTHON -Chapter 2 - Functions,   Exception, Modules  and    Files -MAULIK BOR...PYTHON -Chapter 2 - Functions,   Exception, Modules  and    Files -MAULIK BOR...
PYTHON -Chapter 2 - Functions, Exception, Modules and Files -MAULIK BOR...Maulik Borsaniya
 
C++ prgms io file unit 7
C++ prgms io file unit 7C++ prgms io file unit 7
C++ prgms io file unit 7Ananda Kumar HN
 
Programming in Computational Biology
Programming in Computational BiologyProgramming in Computational Biology
Programming in Computational BiologyAtreyiB
 
Introduction to GNU Make Programming Language
Introduction to GNU Make Programming LanguageIntroduction to GNU Make Programming Language
Introduction to GNU Make Programming LanguageShih-Hsiang Lin
 
Python Programming Essentials - M25 - os and sys modules
Python Programming Essentials - M25 - os and sys modulesPython Programming Essentials - M25 - os and sys modules
Python Programming Essentials - M25 - os and sys modulesP3 InfoTech Solutions Pvt. Ltd.
 
Introduction To Makefile
Introduction To MakefileIntroduction To Makefile
Introduction To MakefileWaqqas Jabbar
 
Using Unix
Using UnixUsing Unix
Using UnixDr.Ravi
 
Unit 3
Unit  3Unit  3
Unit 3siddr
 
Java 7 - short intro to NIO.2
Java 7 - short intro to NIO.2Java 7 - short intro to NIO.2
Java 7 - short intro to NIO.2Martijn Verburg
 
Course 102: Lecture 8: Composite Commands
Course 102: Lecture 8: Composite Commands Course 102: Lecture 8: Composite Commands
Course 102: Lecture 8: Composite Commands Ahmed El-Arabawy
 

Mais procurados (20)

Introduction to Makefile
Introduction to MakefileIntroduction to Makefile
Introduction to Makefile
 
PYTHON -Chapter 2 - Functions, Exception, Modules and Files -MAULIK BOR...
PYTHON -Chapter 2 - Functions,   Exception, Modules  and    Files -MAULIK BOR...PYTHON -Chapter 2 - Functions,   Exception, Modules  and    Files -MAULIK BOR...
PYTHON -Chapter 2 - Functions, Exception, Modules and Files -MAULIK BOR...
 
C++ prgms io file unit 7
C++ prgms io file unit 7C++ prgms io file unit 7
C++ prgms io file unit 7
 
Inheritance
InheritanceInheritance
Inheritance
 
Linux shell scripting
Linux shell scriptingLinux shell scripting
Linux shell scripting
 
Programming in Computational Biology
Programming in Computational BiologyProgramming in Computational Biology
Programming in Computational Biology
 
Introduction to GNU Make Programming Language
Introduction to GNU Make Programming LanguageIntroduction to GNU Make Programming Language
Introduction to GNU Make Programming Language
 
Python Programming Essentials - M25 - os and sys modules
Python Programming Essentials - M25 - os and sys modulesPython Programming Essentials - M25 - os and sys modules
Python Programming Essentials - M25 - os and sys modules
 
Ch3 gnu make
Ch3 gnu makeCh3 gnu make
Ch3 gnu make
 
Python course Day 1
Python course Day 1Python course Day 1
Python course Day 1
 
Shellscripting
ShellscriptingShellscripting
Shellscripting
 
Mysql
MysqlMysql
Mysql
 
Introduction To Makefile
Introduction To MakefileIntroduction To Makefile
Introduction To Makefile
 
Systemcall1
Systemcall1Systemcall1
Systemcall1
 
Using Unix
Using UnixUsing Unix
Using Unix
 
Unit 3
Unit  3Unit  3
Unit 3
 
Day3
Day3Day3
Day3
 
Java 7 - short intro to NIO.2
Java 7 - short intro to NIO.2Java 7 - short intro to NIO.2
Java 7 - short intro to NIO.2
 
File in C language
File in C languageFile in C language
File in C language
 
Course 102: Lecture 8: Composite Commands
Course 102: Lecture 8: Composite Commands Course 102: Lecture 8: Composite Commands
Course 102: Lecture 8: Composite Commands
 

Destaque

Unix Operating System
Unix Operating SystemUnix Operating System
Unix Operating Systemsubhsikha
 
Machine Learning and Hadoop: Present and Future
Machine Learning and Hadoop: Present and FutureMachine Learning and Hadoop: Present and Future
Machine Learning and Hadoop: Present and FutureData Science London
 
Nigerian design and digital marketing agency
Nigerian design and digital marketing agencyNigerian design and digital marketing agency
Nigerian design and digital marketing agencySamson Aligba
 
Intro to linux performance analysis
Intro to linux performance analysisIntro to linux performance analysis
Intro to linux performance analysisChris McEniry
 
History of L0phtCrack
History of L0phtCrackHistory of L0phtCrack
History of L0phtCrackcwysopal
 
VideoLan VLC Player App Artifact Report
VideoLan VLC Player App Artifact ReportVideoLan VLC Player App Artifact Report
VideoLan VLC Player App Artifact ReportAziz Sasmaz
 
脆弱性診断って何をどうすればいいの?(おかわり)
脆弱性診断って何をどうすればいいの?(おかわり)脆弱性診断って何をどうすればいいの?(おかわり)
脆弱性診断って何をどうすればいいの?(おかわり)脆弱性診断研究会
 
Open Source Security Testing Methodology Manual - OSSTMM by Falgun Rathod
Open Source Security Testing Methodology Manual - OSSTMM by Falgun RathodOpen Source Security Testing Methodology Manual - OSSTMM by Falgun Rathod
Open Source Security Testing Methodology Manual - OSSTMM by Falgun RathodFalgun Rathod
 
Thesis defence of Dall'Olio Giovanni Marco. Applications of network theory to...
Thesis defence of Dall'Olio Giovanni Marco. Applications of network theory to...Thesis defence of Dall'Olio Giovanni Marco. Applications of network theory to...
Thesis defence of Dall'Olio Giovanni Marco. Applications of network theory to...Giovanni Marco Dall'Olio
 
Nmap not only a port scanner by ravi rajput comexpo security awareness meet
Nmap not only a port scanner by ravi rajput comexpo security awareness meet Nmap not only a port scanner by ravi rajput comexpo security awareness meet
Nmap not only a port scanner by ravi rajput comexpo security awareness meet Ravi Rajput
 
Hacking in shadows By - Raghav Bisht
Hacking in shadows By - Raghav BishtHacking in shadows By - Raghav Bisht
Hacking in shadows By - Raghav BishtRaghav Bisht
 
Learning sed and awk
Learning sed and awkLearning sed and awk
Learning sed and awkYogesh Sawant
 
Nmap 9 truth "Nothing to say any more"
Nmap 9 truth "Nothing to say  any more"Nmap 9 truth "Nothing to say  any more"
Nmap 9 truth "Nothing to say any more"abend_cve_9999_0001
 
Hacking With Nmap - Scanning Techniques
Hacking With Nmap - Scanning TechniquesHacking With Nmap - Scanning Techniques
Hacking With Nmap - Scanning Techniquesamiable_indian
 

Destaque (20)

Linux intro 1 definitions
Linux intro 1  definitionsLinux intro 1  definitions
Linux intro 1 definitions
 
Unix Operating System
Unix Operating SystemUnix Operating System
Unix Operating System
 
Machine Learning and Hadoop: Present and Future
Machine Learning and Hadoop: Present and FutureMachine Learning and Hadoop: Present and Future
Machine Learning and Hadoop: Present and Future
 
Nigerian design and digital marketing agency
Nigerian design and digital marketing agencyNigerian design and digital marketing agency
Nigerian design and digital marketing agency
 
Intro to linux performance analysis
Intro to linux performance analysisIntro to linux performance analysis
Intro to linux performance analysis
 
History of L0phtCrack
History of L0phtCrackHistory of L0phtCrack
History of L0phtCrack
 
Samsung mobile root
Samsung mobile rootSamsung mobile root
Samsung mobile root
 
VideoLan VLC Player App Artifact Report
VideoLan VLC Player App Artifact ReportVideoLan VLC Player App Artifact Report
VideoLan VLC Player App Artifact Report
 
脆弱性診断って何をどうすればいいの?(おかわり)
脆弱性診断って何をどうすればいいの?(おかわり)脆弱性診断って何をどうすればいいの?(おかわり)
脆弱性診断って何をどうすればいいの?(おかわり)
 
Open Source Security Testing Methodology Manual - OSSTMM by Falgun Rathod
Open Source Security Testing Methodology Manual - OSSTMM by Falgun RathodOpen Source Security Testing Methodology Manual - OSSTMM by Falgun Rathod
Open Source Security Testing Methodology Manual - OSSTMM by Falgun Rathod
 
Dangerous google dorks
Dangerous google dorksDangerous google dorks
Dangerous google dorks
 
How to Setup A Pen test Lab and How to Play CTF
How to Setup A Pen test Lab and How to Play CTF How to Setup A Pen test Lab and How to Play CTF
How to Setup A Pen test Lab and How to Play CTF
 
Thesis defence of Dall'Olio Giovanni Marco. Applications of network theory to...
Thesis defence of Dall'Olio Giovanni Marco. Applications of network theory to...Thesis defence of Dall'Olio Giovanni Marco. Applications of network theory to...
Thesis defence of Dall'Olio Giovanni Marco. Applications of network theory to...
 
Nmap not only a port scanner by ravi rajput comexpo security awareness meet
Nmap not only a port scanner by ravi rajput comexpo security awareness meet Nmap not only a port scanner by ravi rajput comexpo security awareness meet
Nmap not only a port scanner by ravi rajput comexpo security awareness meet
 
Hacking in shadows By - Raghav Bisht
Hacking in shadows By - Raghav BishtHacking in shadows By - Raghav Bisht
Hacking in shadows By - Raghav Bisht
 
Learning sed and awk
Learning sed and awkLearning sed and awk
Learning sed and awk
 
Nmap Basics
Nmap BasicsNmap Basics
Nmap Basics
 
Nmap 9 truth "Nothing to say any more"
Nmap 9 truth "Nothing to say  any more"Nmap 9 truth "Nothing to say  any more"
Nmap 9 truth "Nothing to say any more"
 
Hacking With Nmap - Scanning Techniques
Hacking With Nmap - Scanning TechniquesHacking With Nmap - Scanning Techniques
Hacking With Nmap - Scanning Techniques
 
Intermediate PHP
Intermediate PHPIntermediate PHP
Intermediate PHP
 

Semelhante a Linux intro 5 extra: makefiles

Linux basic commands with examples
Linux basic commands with examplesLinux basic commands with examples
Linux basic commands with examplesabclearnn
 
1 CMPS 12M Data Structures Lab Lab Assignment 1 .docx
1 CMPS 12M Data Structures Lab Lab Assignment 1 .docx1 CMPS 12M Data Structures Lab Lab Assignment 1 .docx
1 CMPS 12M Data Structures Lab Lab Assignment 1 .docxtarifarmarie
 
Can someone put this code in a zip file. I tried running it last tim.pdf
Can someone put this code in a zip file. I tried running it last tim.pdfCan someone put this code in a zip file. I tried running it last tim.pdf
Can someone put this code in a zip file. I tried running it last tim.pdffedosys
 
Basic shell programs assignment 1_solution_manual
Basic shell programs assignment 1_solution_manualBasic shell programs assignment 1_solution_manual
Basic shell programs assignment 1_solution_manualKuntal Bhowmick
 
CMake Tutorial
CMake TutorialCMake Tutorial
CMake TutorialFu Haiping
 
Integration Group - Robot Framework
Integration Group - Robot Framework Integration Group - Robot Framework
Integration Group - Robot Framework OpenDaylight
 
LOSS_C11- Programming Linux 20221006.pdf
LOSS_C11- Programming Linux 20221006.pdfLOSS_C11- Programming Linux 20221006.pdf
LOSS_C11- Programming Linux 20221006.pdfThninh2
 
LMP1 IO and Filesystems=========================Welcome .docx
LMP1 IO and Filesystems=========================Welcome .docxLMP1 IO and Filesystems=========================Welcome .docx
LMP1 IO and Filesystems=========================Welcome .docxmanningchassidy
 
The program reads data from two files, itemsList-0x.txt and .docx
The program reads data from two files, itemsList-0x.txt and .docxThe program reads data from two files, itemsList-0x.txt and .docx
The program reads data from two files, itemsList-0x.txt and .docxoscars29
 
2023comp90024_linux2.pdf
2023comp90024_linux2.pdf2023comp90024_linux2.pdf
2023comp90024_linux2.pdfLevLafayette1
 
Terminalcommandsubuntu1 170123133631 (1)
Terminalcommandsubuntu1 170123133631 (1)Terminalcommandsubuntu1 170123133631 (1)
Terminalcommandsubuntu1 170123133631 (1)SteveEvans551344
 
Description 1) Create a Lab2 folder for this project2.docx
Description       1)  Create a Lab2 folder for this project2.docxDescription       1)  Create a Lab2 folder for this project2.docx
Description 1) Create a Lab2 folder for this project2.docxtheodorelove43763
 
Some useful tips with qtp
Some useful tips with qtpSome useful tips with qtp
Some useful tips with qtpSandeep
 
Terminal Commands (Linux - ubuntu) (part-1)
Terminal Commands  (Linux - ubuntu) (part-1)Terminal Commands  (Linux - ubuntu) (part-1)
Terminal Commands (Linux - ubuntu) (part-1)raj upadhyay
 

Semelhante a Linux intro 5 extra: makefiles (20)

Makefiles Bioinfo
Makefiles BioinfoMakefiles Bioinfo
Makefiles Bioinfo
 
Introduction to Makefile
Introduction to MakefileIntroduction to Makefile
Introduction to Makefile
 
Linux basic commands with examples
Linux basic commands with examplesLinux basic commands with examples
Linux basic commands with examples
 
1 CMPS 12M Data Structures Lab Lab Assignment 1 .docx
1 CMPS 12M Data Structures Lab Lab Assignment 1 .docx1 CMPS 12M Data Structures Lab Lab Assignment 1 .docx
1 CMPS 12M Data Structures Lab Lab Assignment 1 .docx
 
Can someone put this code in a zip file. I tried running it last tim.pdf
Can someone put this code in a zip file. I tried running it last tim.pdfCan someone put this code in a zip file. I tried running it last tim.pdf
Can someone put this code in a zip file. I tried running it last tim.pdf
 
Basic Make
Basic MakeBasic Make
Basic Make
 
Matlab m files
Matlab m filesMatlab m files
Matlab m files
 
Basic shell programs assignment 1_solution_manual
Basic shell programs assignment 1_solution_manualBasic shell programs assignment 1_solution_manual
Basic shell programs assignment 1_solution_manual
 
CMake Tutorial
CMake TutorialCMake Tutorial
CMake Tutorial
 
Examples -partII
Examples -partIIExamples -partII
Examples -partII
 
Integration Group - Robot Framework
Integration Group - Robot Framework Integration Group - Robot Framework
Integration Group - Robot Framework
 
Linux commands
Linux commandsLinux commands
Linux commands
 
LOSS_C11- Programming Linux 20221006.pdf
LOSS_C11- Programming Linux 20221006.pdfLOSS_C11- Programming Linux 20221006.pdf
LOSS_C11- Programming Linux 20221006.pdf
 
LMP1 IO and Filesystems=========================Welcome .docx
LMP1 IO and Filesystems=========================Welcome .docxLMP1 IO and Filesystems=========================Welcome .docx
LMP1 IO and Filesystems=========================Welcome .docx
 
The program reads data from two files, itemsList-0x.txt and .docx
The program reads data from two files, itemsList-0x.txt and .docxThe program reads data from two files, itemsList-0x.txt and .docx
The program reads data from two files, itemsList-0x.txt and .docx
 
2023comp90024_linux2.pdf
2023comp90024_linux2.pdf2023comp90024_linux2.pdf
2023comp90024_linux2.pdf
 
Terminalcommandsubuntu1 170123133631 (1)
Terminalcommandsubuntu1 170123133631 (1)Terminalcommandsubuntu1 170123133631 (1)
Terminalcommandsubuntu1 170123133631 (1)
 
Description 1) Create a Lab2 folder for this project2.docx
Description       1)  Create a Lab2 folder for this project2.docxDescription       1)  Create a Lab2 folder for this project2.docx
Description 1) Create a Lab2 folder for this project2.docx
 
Some useful tips with qtp
Some useful tips with qtpSome useful tips with qtp
Some useful tips with qtp
 
Terminal Commands (Linux - ubuntu) (part-1)
Terminal Commands  (Linux - ubuntu) (part-1)Terminal Commands  (Linux - ubuntu) (part-1)
Terminal Commands (Linux - ubuntu) (part-1)
 

Mais de Giovanni Marco Dall'Olio (16)

Fehrman Nat Gen 2014 - Journal Club
Fehrman Nat Gen 2014 - Journal ClubFehrman Nat Gen 2014 - Journal Club
Fehrman Nat Gen 2014 - Journal Club
 
Agile bioinf
Agile bioinfAgile bioinf
Agile bioinf
 
Version control
Version controlVersion control
Version control
 
Wagner chapter 5
Wagner chapter 5Wagner chapter 5
Wagner chapter 5
 
Wagner chapter 4
Wagner chapter 4Wagner chapter 4
Wagner chapter 4
 
Wagner chapter 3
Wagner chapter 3Wagner chapter 3
Wagner chapter 3
 
Wagner chapter 2
Wagner chapter 2Wagner chapter 2
Wagner chapter 2
 
Wagner chapter 1
Wagner chapter 1Wagner chapter 1
Wagner chapter 1
 
Hg for bioinformatics, second part
Hg for bioinformatics, second partHg for bioinformatics, second part
Hg for bioinformatics, second part
 
Hg version control bioinformaticians
Hg version control bioinformaticiansHg version control bioinformaticians
Hg version control bioinformaticians
 
The true story behind the annotation of a pathway
The true story behind the annotation of a pathwayThe true story behind the annotation of a pathway
The true story behind the annotation of a pathway
 
Plotting data with python and pylab
Plotting data with python and pylabPlotting data with python and pylab
Plotting data with python and pylab
 
Pycon
PyconPycon
Pycon
 
Web 2.0 e ricerca scientifica - Web 2.0 and scientific research
Web 2.0 e ricerca scientifica - Web 2.0 and scientific researchWeb 2.0 e ricerca scientifica - Web 2.0 and scientific research
Web 2.0 e ricerca scientifica - Web 2.0 and scientific research
 
Perl Bioinfo
Perl BioinfoPerl Bioinfo
Perl Bioinfo
 
(draft) perl e bioinformatica - presentazione per ipw2008
(draft) perl e bioinformatica - presentazione per ipw2008(draft) perl e bioinformatica - presentazione per ipw2008
(draft) perl e bioinformatica - presentazione per ipw2008
 

Último

Testing tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examplesTesting tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examplesKari Kakkonen
 
Manual 508 Accessibility Compliance Audit
Manual 508 Accessibility Compliance AuditManual 508 Accessibility Compliance Audit
Manual 508 Accessibility Compliance AuditSkynet Technologies
 
Emixa Mendix Meetup 11 April 2024 about Mendix Native development
Emixa Mendix Meetup 11 April 2024 about Mendix Native developmentEmixa Mendix Meetup 11 April 2024 about Mendix Native development
Emixa Mendix Meetup 11 April 2024 about Mendix Native developmentPim van der Noll
 
So einfach geht modernes Roaming fuer Notes und Nomad.pdf
So einfach geht modernes Roaming fuer Notes und Nomad.pdfSo einfach geht modernes Roaming fuer Notes und Nomad.pdf
So einfach geht modernes Roaming fuer Notes und Nomad.pdfpanagenda
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity PlanDatabarracks
 
(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...
(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...
(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...AliaaTarek5
 
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyesHow to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyesThousandEyes
 
A Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersA Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersNicole Novielli
 
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...Wes McKinney
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxLoriGlavin3
 
Decarbonising Buildings: Making a net-zero built environment a reality
Decarbonising Buildings: Making a net-zero built environment a realityDecarbonising Buildings: Making a net-zero built environment a reality
Decarbonising Buildings: Making a net-zero built environment a realityIES VE
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024Lonnie McRorey
 
Modern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better StrongerModern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better Strongerpanagenda
 
Scale your database traffic with Read & Write split using MySQL Router
Scale your database traffic with Read & Write split using MySQL RouterScale your database traffic with Read & Write split using MySQL Router
Scale your database traffic with Read & Write split using MySQL RouterMydbops
 
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024BookNet Canada
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsSergiu Bodiu
 
Assure Ecommerce and Retail Operations Uptime with ThousandEyes
Assure Ecommerce and Retail Operations Uptime with ThousandEyesAssure Ecommerce and Retail Operations Uptime with ThousandEyes
Assure Ecommerce and Retail Operations Uptime with ThousandEyesThousandEyes
 
[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality Assurance[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality AssuranceInflectra
 
Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024Hiroshi SHIBATA
 
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24Mark Goldstein
 

Último (20)

Testing tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examplesTesting tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examples
 
Manual 508 Accessibility Compliance Audit
Manual 508 Accessibility Compliance AuditManual 508 Accessibility Compliance Audit
Manual 508 Accessibility Compliance Audit
 
Emixa Mendix Meetup 11 April 2024 about Mendix Native development
Emixa Mendix Meetup 11 April 2024 about Mendix Native developmentEmixa Mendix Meetup 11 April 2024 about Mendix Native development
Emixa Mendix Meetup 11 April 2024 about Mendix Native development
 
So einfach geht modernes Roaming fuer Notes und Nomad.pdf
So einfach geht modernes Roaming fuer Notes und Nomad.pdfSo einfach geht modernes Roaming fuer Notes und Nomad.pdf
So einfach geht modernes Roaming fuer Notes und Nomad.pdf
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity Plan
 
(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...
(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...
(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...
 
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyesHow to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
 
A Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersA Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software Developers
 
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
 
Decarbonising Buildings: Making a net-zero built environment a reality
Decarbonising Buildings: Making a net-zero built environment a realityDecarbonising Buildings: Making a net-zero built environment a reality
Decarbonising Buildings: Making a net-zero built environment a reality
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024
 
Modern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better StrongerModern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
 
Scale your database traffic with Read & Write split using MySQL Router
Scale your database traffic with Read & Write split using MySQL RouterScale your database traffic with Read & Write split using MySQL Router
Scale your database traffic with Read & Write split using MySQL Router
 
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platforms
 
Assure Ecommerce and Retail Operations Uptime with ThousandEyes
Assure Ecommerce and Retail Operations Uptime with ThousandEyesAssure Ecommerce and Retail Operations Uptime with ThousandEyes
Assure Ecommerce and Retail Operations Uptime with ThousandEyes
 
[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality Assurance[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality Assurance
 
Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024
 
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
 

Linux intro 5 extra: makefiles

  • 1. Programming for Evolutionary Biology March 17th - April 1st 2012 Leipzig, Germany Introduction to Unix systems Extra: writing simple pipelines with make Giovanni Marco Dall'Olio Universitat Pompeu Fabra Barcelona (Spain)
  • 2. GNU/make  make is a tool to store command­line instructions  and re­execute them quickly, along with all their  parameters  It is a declarative programming language  It belongs to a class of softwares called 'automated  build tools'
  • 3. Simplest Makefile example  The simplest Makefile contains just the name of a task and  the commands associated with it:  print_hello is a makefile 'rule': it stores the commands needed to say 'Hello, world!' to the screen.
  • 4. Simplest Makefile example Makefile rule Target of the rule Commands associated This is a with the rule tabulation (not 8 spaces)
  • 5. Simplest Makefile example  Create a file in your  computer and save it as  'Makefile'.  Write these instructions in it: print_hello: echo 'Hello, world!!' This is a tabulation  Then, open a terminal and  (<Tab> key) type: make -f Makefile print_hello
  • 7. Simplest Makefile example – explanation  When invoked, the program 'make' looks for a file in the  current directory called 'Makefile'  When we type 'make print_hello', it executes any procedure  (target) called 'print_hello' in the makefile  It then shows the commands executed and their output
  • 8. Tip1: the 'Makefile' file  The '­f' option allows you to define the file which  contains the instructions for make  If you omit this option, make will look for any file  called 'Makefile' in the current directory make -f Makefile all is equivalent to: make all
  • 9. A sligthly longer example  You can add as many  commands you like  to a rule  For example, this  'print_hello' rule  contains 5 commands  Note: ignore the '@'  thing, it is only to  disable verbose mode  (explained later)
  • 10. A more complex example
  • 11. Make - advantages  Make allows you to save shell commands along  with their parameters and re­execute them;  It allows you to use command­line tools which are  more flexible;  Combined with a revision control software, it  makes possible to reproduce all the operations  made to your data;
  • 12. Second part A closer look at make syntax (target and commands)
  • 13. The target syntax  Makefile syntax: <target>: (prerequisites) <commands associated to the rule>
  • 14. The target syntax  The target of a rule can be either a title for the task, or a file  name.  Everytime you call a make rule (example: 'make all'), the  program looks for a file called like the target name (e.g.  'all', 'clean', 'inputdata.txt', 'results.txt')  The rule is executed only if that file doesn't exists.
  • 15. Filename as target names  In this makefile, we have two rules: 'testfile.txt' and 'clean'
  • 16. Filename as target names  In this makefile, we have two rules: 'testfile.txt' and 'clean'  When we call 'make testfile.txt', make checks if a file called 'testfile.txt' already exists.
  • 17. Filename as target names The commands associated with the rule 'testfile.txt' are executed only if that file doesn't exists already
  • 18. Multiple target definition  A target can also be a  list of files  You can retrieve the  matched target with  the special variable  $@
  • 19. Special characters  The % character can be used as a wild card  For example, a rule with the target: %.txt: .... would be activated by any file ending with '.txt'  'make 1.txt', 'make 2.txt', etc..  We will be able to retrieve the matched expression  with '$*'
  • 20. Special character % / creating more than a file at a time
  • 21. Makefile – cluster support  Note that in the previous  example we created three  files at the same time, by  executing three times the  command 'touch'  If we use the '­j' option when  invoking make, the three  processess will be launched  in parallel
  • 22. The commands syntax  Makefile syntax: <target>: (prerequisites) <commands associated to the rule>
  • 23. Inactivating verbose mode  You can disactivate the verbose mode for a line by  adding '@' at its beginning: Differences here
  • 24. Skipping errors  The modifiers '­' tells make to ignore errors returned  by a command  Example:   'mkdir /var' will cause an error (the '/var' directory  already exists) and cause gnu/make to exit  '­mkdir /var' will cause an error anyway, but  gnu/make will ignore it
  • 25. Moving throught directories  A big issue with make is that every line is executed as a  different shell process.  So, this: lsvar: cd /var ls  Won't work (it will list only the files in the current  directory, not /var)  The solution is to put everything in a single process: lsvar: (cd /var; ls)
  • 26. Third part Prerequisites and conditional execution
  • 27. The commands syntax  Makefile syntax: <target>: (prerequisites) <commands associated to the rule>  We will look at the 'prerequisites' part of a make  rule, that I had skipped before
  • 28. Real Makefile-rule syntax  Complete syntax for a Makefile rule: <target>: <list of prerequisites> <commands associated to the rule>  Example: result1.txt: data1.txt data2.txt cat data1.txt data2.txt > result1.txt @echo 'result1.txt' has been calculated'  Prerequisites are files (or rules) that need to exists already in  order to create the target file.  If 'data1.txt' and 'data2.txt' don't exist, the rule 'result1.txt' will  exit with an error (no rule to create them)
  • 29. Piping Makefile rules together  You can pipe two Makefile rules together by  defining prerequisites
  • 30. Piping Makefile rules together  The rule 'result1.txt' depends on the rule 'data1.txt',  which should be executed first
  • 31. Piping Makefile rules together  Let's look at this  example  again: what happens if  we remove the  file 'result1.txt'  we just  created?
  • 32. Piping Makefile rules together  Let's look at this  example  again: what happens if  we remove the  file 'result1.txt'  we just  created?  The second time  we run the  'make  result1.txt'  command, it is  not necessary  to create  data1.txt 
  • 33. Other pipe example  all: result1.txt result2.txt result1.txt: data1.txt calculate_result.py python calculate_result.txt --input data1.txt result2.txt: data2.txt cut -f 1, 3 data2.txt > result2.txt  Make all will calculate result1.txt and result2.txt, if  they don't exist already (and they are older than  their prerequisites)
  • 34. Conditional execution by modification date  We have seen how make can be used to create a  file, if it doesn't exists. file.txt: # if file.txt doesn't exists, then create it: echo 'contents of file.txt' > file.txt  We can do better: create or update a file only if it is  newer than its prerequisites
  • 35. Conditional execution by modification date  Let's have a better look at this example: result1.txt: data1.txt calculate_result.py python calculate_result.txt --input data1.txt  A great feature of make is that it execute a rule not  only if the target file doesn't exist, but also if it  has a 'last modification date' earlier than all of its  prerequisites
  • 36. Conditional execution by modification date result1.txt: data1.txt @sed 's/b/B/i' data1.txt > result1.txt @echo 'result1.txt has been calculated'  In this example, result1.txt will be recalculated  every time 'data1.txt' is modified $: touch data1.txt calculate_result.py $: make result1.txt result1.txt has been calculated $: make result1.txt result1.txt is already up-to-date $: touch data1.txt $: make result1.txt result1.txt has been calculated
  • 37. Conditional execution - applications  This 'conditional execution by modification date  comparison' feature of make is very useful  Let's say you discover an error in one of your input  data: you will be able to repeat the analysis by  executing only the operations needed  You can also use it to re­calculate results every time  you modify a script: result.txt: scripts/calculate_result.py python calculate_result.py > result.py
  • 40. Variables and functions  You may have already noticed that Make's syntax is  really old :)  In fact, it is a ~40 years old language  It uses special variables like $@, $^, and it can be  worst than perl!!!   (perl developers – please don't get mad at me :­) )
  • 41. Variables  Variables are declared with a '=' and by convention  are upper case.  They are called by including their name in '$()'   WORKING_DIR is a variable
  • 42. Special variables - $@  Make uses some custom variables, with a syntax  similar to perl  '$@' always corresponds to the target name: $: cat >Makefile %.txt: echo $@ $: make filename.txt $@ took the value of echo filename.txt 'filename.txt' filename.txt
  • 43. Other special variables $@ The rule's target $< The rule's first prerequisite $? All the rule's out of date prerequisites $^ All Prerequisites
  • 44. Functions  Usually you don't want to declare functions in  make, but there are some built­in utilities that can  be useful   Most frequently used functions:  $(addprefix <prefix>, list) → add a prefix to a space­separated list  example: FILES = file1 file2 file3 $(addprefix /home/user/data, $(FILES)  $(addsuffix) work similarly
  • 45. Full makefile example INPUTFILES = lower_DAF lower_maf upper_maf lower_daf upper_daf RESULTSDIR = ./results RESULTFILES = $(addprefix $(RESULTSDIR)/, $(addsuffix _filtered.txt,$(INPUTFILES) help: @echo 'type "make filter" to calculate results' all: $(RESULTFILES) $(RESULTSDIR)/%_filtered.txt: data/%.txt src/filter_genes.py python src/filter_genes.py --genes data/Genes.txt --window $< --output $@  It looks like very complicated, but in the end you always use the same Makefile structure
  • 46. Fifth part Testing, discussion, other examples and alternatives
  • 47. Testing a makefile  make ­n: only shows the commands to be executed  You can pass variables to make: $: make say_hello MYNAME=”Giovanni” hello, Giovanni  Strongly suggested: use a Revision Control  Software with support for branching (git, hg,  bazaar) and create a branch for testing
  • 48. Another complex Makefile example # make masked sequence  our starting point is the  myseq.m: myseq file myseq, the end point  rmask myseq > myseq.m is the blast results blastout # run blast on masked seq blastout: mydb.psq myseq.m  we first want to mask out  blastx mydb myseq.m > blastout any repeats using rmask to  echo “ran blast!” create myseq.m # index blastable db  we then blastx myseq.m  mydb.psq: mydb against a protein db called  formatdb -p T mydb mydb # rules follow this pattern: target: subtarget1, ..., subtargetN  before blastx is run the  shell command 1 protein db must be  shell command 2... indexed using formatdb (slide taken from biomake web site)
  • 49. The “make” command % make blastout # run blast on masked seq formatdb -p T mydb blastout: mydb.psq myseq.m rmask myseq.fst > myseq.m blastx mydb myseq.m > blastout blastx mydb myseq.m > blastout echo “ran blast!” % make blastout # index blastable db make: 'blastout' is up to date mydb.psq: mydb % cat newseqs >> mydb formatdb -p T mydb % make blastout formatdb -p T mydb # make masked sequence blastx mydb myseq.m > blastout myseq.m: myseq rmask myseq > myseq.m  make uses unix file  modification timestamps when  checking dependencies  if a subtarget is more recent  than the goal target, then  (slide taken from biomake web site) re­execute action
  • 50. BioMake and alternatives  BioMake is an alternative to make, thought to be  used in bioinformatics  Developed to annotate the Drosophila  melanogaster genome (Berkeley university)  Cleaner syntax,derived from prolog  Separates the rule's name from the name of the  target files
  • 51. A BioMake example formatdb(DB) req: DB run: formatdb DB comment: prepares blastdb for blasting (wublast) rmask(Seq) flat: masked_seqs/Seq.masked req: Seq srun: RepeatMasker -lib $(LIB) Seq comment: masks out repeats from input sequence mblastx(Seq,DB) flat: blast_results/Seq.DB.blastx req: formatdb(DB) rmask(Seq) srun: blastx -filter SEG+XNU DB rmask(Seq) comment: this target is for the results of running blastx on a masked input genomic sequence (wublast) (slide taken from biomake web site)
  • 52. Other alternatives  There are other many alternatives to make:  BioMake (prolog?)  o/q/dist/etc.. make  Ant (Java)  Scons (python)  Paver (python)  Waf (python)  This list is biased because I am a python programmer :)  These tools are more oriented to software development
  • 53. Conclusions  Make is very basic for bioinformatics  It is useful for the simpler tasks:  Logging the operations made to your data files  Working with clusters  Avoid re­calculations  Apply a pipeline to different datasets  It is installed in almost any unix system and has a standard  syntax (interchangeable, reproducible)  Study it and understand its logic. Use it in the most basic way,  without worrying about prerequisites and special variables.  Later you can look for easier tools (biomake, rake, taverna, 
  • 54. Suggested readings  Software Carpentry for bioinformatics  http://swc.scipy.org/lec/build.html  A Makefile is a pipeline http://www.nodalpoint.org/2007/03/18/a_pipeline_is_a_makefil  BioMake and SKAM  http://skam.sourceforge.net/  BioWiki Make Manifesto  http://biowiki.org/MakefileManifesto  Discussion on the BIP mailing list http://www.mail­archive.com/biology­in­python@lists.idyll.org  Gnu/Make manual by R.Stallman and R.MacGrath http://theory.uwinnipeg.ca/gnu/make/make_toc.html