我有一个 bash 脚本,它输出对我的 make 文件的调用。
#!/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
这是生成文件:
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 $^ > $@
我试图将同一个数组中的 2 个变量传递给我的 makefile,但如果我在 bash 脚本数组列表中这样做,这似乎也无法正常工作:
'$(call list_samples,AON_9,NT_1,SC_17) GFF=/data/DIV5/SASC/project-013-motor/analysis/runs/BWA_chipcap/BAMS/GFF/H3K4me1.gff'
不幸的是,makefile 似乎无法处理这种结构。我怎样才能将这两个变量传递到我的 makefile 而没有任何命令行问题。那么如何规避$(call)就被视为命令行调用了。我想传递给 makefile 的 2 个变量是 GFF 和 SAMPLES_OUT。
答案1
Bash 不支持嵌套数组或任何其他复杂的数据结构。
不过,由于参数数量已知,您可以创建两个数组,每个参数一个数组:
#!/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