I have a bash script which outputs calls to my make file.

    'SAMPLES_OUT=$(call list_samples,AON_9,NT_1,SC_17) GFF=/data/DIV5/SASC/project-013-motor/analysis/runs/BWA_chipcap/BAMS/GFF/H3K4me1‌​.gff'
    'SAMPLES_OUT=$(call list_samples,AON_10,NT_2,SC_18) GFF=/data/DIV5/SASC/project-013-motor/analysis/runs/BWA_chipcap/BAMS/GFF/H3K4me2​.gff'
    'SAMPLES_OUT=$(call list_samples,AON_11,NT_3,SC_19) GFF=/data/DIV5/SASC/project-013-motor/analysis/runs/BWA_chipcap/BAMS/GFF/H3K4me3​.gff'
    'SAMPLES_OUT=$(call list_samples,AON_12,NT_4,SC_20) GFF=/data/DIV5/SASC/project-013-motor/analysis/runs/BWA_chipcap/BAMS/GFF/H3K4me4​.gff'
    'SAMPLES_OUT=$(call list_samples,AON_13,NT_5,SC_21) GFF=/data/DIV5/SASC/project-013-motor/analysis/runs/BWA_chipcap/BAMS/GFF/H3K4me5​.gff'

for SAMPLES_out in "${mylist[@]}";
make -f make_gene_read_count.mk -n SAMPLES_OUT=\'${SAMPLES_out}\'

This is the makefile:

IN_DIR = /data/DIV5/SASC/project-013-motor/analysis/runs/BWA_chipcap/BAMS/namesorted_bams
list_samples = $(shell ls $(IN_DIR)/*$(1)* $(IN_DIR)/*$(2)* $(IN_DIR)/*$(3)* | sed 's/\.namesorted\.bam/\.gene\.read\.count/g')
#SAMPLES_OUT := $(call list_samples,AON_9,NT_1,SC_17)


GFF := /data/DIV5/SASC/project-013-motor/analysis/runs/BWA_chipcap/BAMS/GFF/H3K4me1.gff
GFF_TEMP := $(GFF).temp.gff

    sed 's/\*/./g' $< > $@

%.gene.read.count: %.namesorted.bam $(GFF_TEMP)
    htseq-count -t exon -m intersection-strict -f bam -r name -s no $^ > $@

I am trying to pass 2 variables out of the same array to my makefile but this does not seem to work properly as well if I do it like this in my bash scripts array list:

'$(call list_samples,AON_9,NT_1,SC_17) GFF=/data/DIV5/SASC/project-013-motor/analysis/runs/BWA_chipcap/BAMS/GFF/H3K4me1‌​.gff'

Unfortunately it seems that makefile cannot deal with this kind of constructs. How can i pass both variables to my makefile without any command line problems. So how to circumvent $(call) been seen as a command line call. The 2 variables i want to pass to the makefile are GFF and SAMPLES_OUT.


Bash doesn't support nested arrays or any other complicated data structures.

As the number of arguments is known, though, you can create two arrays, one for each argument:


    '$(call list_samples,AON_9,NT_1,SC_17)'
    '$(call list_samples,AON_10,NT_2,SC_18)'
    '$(call list_samples,AON_11,NT_3,SC_19)'
    '$(call list_samples,AON_12,NT_4,SC_20)'
    '$(call list_samples,AON_13,NT_5,SC_21)'


for (( idx=0; idx<${#samples[@]}; ++idx )) ; do
    make -f make_gene_read_count.mk -n SAMPLES_OUT="${samples[idx]}" GFF="${gff[idx]}"
  • Thanks again for this clear explanation and help. Can i assume that the first gff file will be linked to the first sample file? Since i need to make sure they match otherwise a wrong file may be created by the makefile. – Sander Van der Zeeuw Feb 16 '15 at 12:14
  • @SanderVanderZeeuw: Yes, they are linked by the position in the array (represented by the $idx variable). – choroba Feb 16 '15 at 13:09
  • sure, nice and clear as always :) Thank you! – Sander Van der Zeeuw Feb 16 '15 at 13:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.