我想寫一個腳本,應該像下面這樣工作,但不知何故我無法獲得寫入方式來放置語法。如何匹配以下模式的正則表達式?
我有像S_12_O_319_K4me1
這樣的文件夾。
雖然在每個文件夾中的內容是S_12_O_319_K4me1_S12816.sorted.bam
。
所以我想編寫一個腳本,我的腳本在一個循環中進入我的同名文件夾,然後標識*.bam
文件並執行操作,但我無法放置正則表達式。這是我試過的:
#!/bin/bash
#$ -S /bin/bash
spp_run=/path/phantompeakqualtools/run_spp.R
bam_loc=/path/ChIP-Seq/output
samples="S_12_O_319_K27me3
S_12_O_319_K4me1
S_12_O_319_K4me3
S_12_O_319_K27ac"
for s in $samples; do
echo "Running SPP on $s ..."
Rscript $spp_run -c=$bam_loc/$s/${s}_S[[0-9]+\.sorted.bam -savp -out=$bam_loc/$s/${s}".run_spp.out"
done
我無法識別上述正則表達式匹配的數字。
我在哪裏弄錯了?
編輯: 下面我試過它仍然不會在RSCRIPT工作,問題解析,但爲什麼會這樣是
#!/bin/bash
#$ -S /bin/bash
spp_run=/path/tools/phantompeakqualtools/run_spp.R
bam_loc=/path/ChIP-Seq/output
samples="S_12_O_319_K27me3
S_12_O_319_K4me1
S_12_O_319_K4me3"
for s in $samples; do
echo "Running SPP on $s ..."
echo $bam_loc/$s/${s}_S*.sorted.bam
inbam=$bam_loc/$s/${s}_S*.sorted.bam
echo $inbam
Rscript $spp_run -c=$inbam -savp -out=$bam_loc/$s/${s}".run_spp.out"
done
echo "done"
錯誤
Error in parse.arguments(args) :
ChIP File:/path/ChIP-Seq/output/S_12_O_319_K27me3/S_12_O_319_K27me3_S*.sorted.bam does not exist
Execution halted
不認識的文件有問題即使$inbam
的值爲/path/ChIP-Seq/output/S_12_O_319_K27me3/S_12_O_319_K27me3_S12815.sorted.bam
你在期待什麼是在命令中解釋該位置的正則表達式? (你似乎錯過了你正則表達式的嘗試。) –
你只是試圖將'$ {s} _S * sorted.bam'文件放在一起嗎? –
正試圖讓Rscript拿起目錄'$ s'中的bam文件,並且識別出'S_12_O_319_K4me1_S12816.sorted.bam',其中正則表達式將理解字母數字的'S12816',它對文件夾內的每個bam文件都有所不同 –