我正在努力将R中的多个条件组合起来。我能够使它适用于单个条件但我不断遇到多个条件错误。这是一个例子..
#!/usr/bin/Rscript
library(getopt)
args<-commandArgs(TRUE)
options<-matrix(c('lincRNA', 'l', 1, "character",
'lincRNAbed', 'b', 1, "character",
'overlap', 'v', 2, "character",
'tss', 't', 2, "character",
'help', 'h', 0, "logical"),
ncol=4,byrow=TRUE)
ret.opts<-getopt(options,args)
# No TSS file here
if(is.null(ret.opts$tss)) {
# All lincRNA's
fastaFile <- readDNAStringSet(ret.opts$lincRNA)
lincRNA_ID = names(fastaFile)
sequence = paste(fastaFile)
size = width(fastaFile)
df <- data.frame(lincRNA_ID, size)
# No overlap file here
} else if(is.null(ret.opts$overlap)) {
# All lincRNA's
fastaFile <- readDNAStringSet(ret.opts$lincRNA)
lincRNA_ID = names(fastaFile)
sequence = paste(fastaFile)
size = width(fastaFile)
df <- data.frame(lincRNA_ID, size)
# Both not present
} else if(is.null(ret.opts$tss) && is.null(ret.opts$overlap)){
# All lincRNA's
fastaFile <- readDNAStringSet(ret.opts$lincRNA)
lincRNA_ID = names(fastaFile)
sequence = paste(fastaFile)
size = width(fastaFile)
df <- data.frame(lincRNA_ID, size)
# Both present
} else {
# All lincRNA's
fastaFile <- readDNAStringSet(ret.opts$lincRNA)
lincRNA_ID = names(fastaFile)
sequence = paste(fastaFile)
size = width(fastaFile)
df <- data.frame(lincRNA_ID, size)
}
适用于条件1,2和4.这是一个例子
Rscript test.R --lincRNA lincRNAs.fa --lincRNAbed lincRNAs.bed --tss lincRNAs.with.CAGE.support.annotated.fa
Rscript test.R --lincRNA lincRNAs.fa --lincRNAbed lincRNAs.bed --overlap lincRNAs.overlapping.known.lincs.fa
Rscript test.R --lincRNA lincRNAs.fa --lincRNAbed lincRNAs.bed --overlap lincRNAs.overlapping.known.lincs.fa --tss lincRNAs.with.CAGE.support.annotated.fa
但是当我用多个条件运行它时,我不断收到错误。
Rscript test.R --lincRNA lincRNAs.fa --lincRNAbed lincRNAs.bed
Error in .normarg_input_filepath(filepath) :
'filepath' must be a character vector with no NAs
Calls: readDNAStringSet ... fasta.index -> <Anonymous> -> .normarg_input_filepath
Execution halted
我知道多个条件的语法是错误的,但我无法弄清楚它是什么。我尝试了不同的方法但没有成功。