我有几个文件,我想使用这些文件名中存在的数字作为样本ID,并匹配包含特定数字的所有文件。下面是我正在尝试的代码。
underscore <- "_0.005"
sampleid_underscored <- gsub(" ", "", paste(sample_id, underscore))
pattern <- paste0("(S", sample_id, "\\.)", "|", sampleid_underscored)
matching_files <- summaryvcffiles[grepl(pattern, summaryvcffiles)]
当我从命令行使用样本ID 1时,它会打印所有包含11_,21_,31_的文件。我只想打印带有1_和S1的文件。对于样本ID 2也是如此。
对于以下文件:
c("./protocol12/1_0.005_consensus.vardict.summary.tab",
"./protocol12/11_0.005_consensus.vardict.summary.tab",
"./protocol12/21_0.005_consensus.vardict.summary.tab",
"./protocol12/31_0.005_consensus.vardict.summary.tab",
"./protocol12/twiceSort/1_0.005_consensus.vardict.summary.tab",
"./protocol12/twiceSort/11_0.005_consensus.vardict.summary.tab",
"./protocol12/twiceSort/21_0.005_consensus.vardict.summary.tab",
"./protocol12/twiceSort/31_0.005_consensus.vardict.summary.tab",
"./test_S1.vardict.summary.tab",
"./fwd-protocol12/1_0.005_consensus.vardict.summary.tab",
"./fwd-protocol12/11_0.005_consensus.vardict.summary.tab",
"./fwd-protocol12/21_0.005_consensus.vardict.summary.tab",
"./fwd-protocol12/31_0.005_consensus.vardict.summary.tab",
"./fwd-protocol12/twiceSort/1_0.005_consensus.vardict.summary.tab",
"./fwd-protocol12/twiceSort/11_0.005_consensus.vardict.summary.tab",
"./fwd-protocol12/twiceSort/21_0.005_consensus.vardict.summary.tab",
"./fwd-protocol12/twiceSort/31_0.005_consensus.vardict.summary.tab",
"./rev-protocol12/1_0.005_consensus.vardict.summary.tab",
"./rev-protocol12/11_0.005_consensus.vardict.summary.tab",
"./rev-protocol12/21_0.005_consensus.vardict.summary.tab",
"./rev-protocol12/31_0.005_consensus.vardict.summary.tab",
"./rev-protocol12/twiceSort/1_0.005_consensus.vardict.summary.tab",
"./rev-protocol12/twiceSort/11_0.005_consensus.vardict.summary.tab",
"./rev-protocol12/twiceSort/21_0.005_consensus.vardict.summary.tab",
"./rev-protocol12/twiceSort/31_0.005_consensus.vardict.summary.tab")
我只想得到下面的文件:
**"./protocol12/1_0.005_consensus.vardict.summary.tab"**
**"./protocol12/twiceSort/1_0.005_consensus.vardict.summary.tab"**
**"./test_S1.vardict.summary.tab"**
**"./fwd-protocol12/1_0.005_consensus.vardict.summary.tab"**
**"./fwd-protocol12/twiceSort/1_0.005_consensus.vardict.summary.tab"**
**"./rev-protocol12/1_0.005_consensus.vardict.summary.tab"**
**"./rev-protocol12/twiceSort/1_0.005_consensus.vardict.summary.tab"**
3条答案
按热度按时间h43kikqp1#
怎么样:
hivapdat2#
下面的代码应该工作
注意:注意regex模式。如果将来您的模式会有所不同,请尝试查看regex101以检查您的模式。不要忘记在regexp函数中添加一个额外的“\”用于转义。
quhf5bfb3#
这些命令起作用了