1

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

#!/bin/bash mylist=( '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[@]}"; do make -f make_gene_read_count.mk -n SAMPLES_OUT=\'${SAMPLES_out}\' done 

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) all: $(SAMPLES_OUT) GFF := /data/DIV5/SASC/project-013-motor/analysis/runs/BWA_chipcap/BAMS/GFF/H3K4me1.gff GFF_TEMP := $(GFF).temp.gff $(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.

1 Answer 1

2

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:

#!/bin/bash samples=( '$(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)' ) gff=( /data/DIV5/SASC/project-013-motor/analysis/runs/BWA_chipcap/BAMS/GFF/H3K4me1‌​.gff /data/DIV5/SASC/project-013-motor/analysis/runs/BWA_chipcap/BAMS/GFF/H3K4me2​.gff /data/DIV5/SASC/project-013-motor/analysis/runs/BWA_chipcap/BAMS/GFF/H3K4me3​.gff /data/DIV5/SASC/project-013-motor/analysis/runs/BWA_chipcap/BAMS/GFF/H3K4me4​.gff /data/DIV5/SASC/project-013-motor/analysis/runs/BWA_chipcap/BAMS/GFF/H3K4me5​.gff ) for (( idx=0; idx<${#samples[@]}; ++idx )) ; do make -f make_gene_read_count.mk -n SAMPLES_OUT="${samples[idx]}" GFF="${gff[idx]}" done 
3
  • 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. Commented Feb 16, 2015 at 12:14
  • @SanderVanderZeeuw: Yes, they are linked by the position in the array (represented by the $idx variable). Commented Feb 16, 2015 at 13:09
  • sure, nice and clear as always :) Thank you! Commented Feb 16, 2015 at 13:48

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.