R/bwaSamse.R

###########################################################################/**
# @RdocDefault bwaSamse
#
# @title "Generates BWA-backtrack single-end (SE) alignments via 'bwa samse'"
#
# \description{
#  @get "title".
# }
#
# @synopsis
#
# \arguments{
#   \item{pathnameSAI}{The SAI file to be aligned.}
#   \item{pathnameFQ}{The FASTQ file to be aligned.}
#   \item{indexPrefix}{The pathname prefix to the BWA index files.}
#   \item{pathnameD}{The destination pathname.}
#   \item{...}{Additional arguments specifying BWA 'samse' switches
#     passed to @see "systemBWA".}
#   \item{verbose}{See @see "R.utils::Verbose".}
# }
#
# \examples{\dontrun{
#   pathnameFA <- "annotationData/organisms/Lambda_phage/lambda_virus.fa"
#   bwaIndex(pathnameFA)
#
#   pathnameSAI <- "bwaData/LambdaVirusExample/Lambda_phage/reads_1.sai"
#   pathnameFQ <- "fastqData/LambdaVirusExample/Lambda_phage/reads_1.fq"
#   pathnameD <- "bwaData/LambdaVirusExample/Lambda_phage/reads_1.sam"
#   bwaSamse(pathnameSAI=pathnameSAI, pathnameFQ=pathnameFQ,
#            pathnameFA=pathnameFA, pathnameD=pathnameD)
# }}
#
# @author "HB"
#
# @keyword internal
#*/###########################################################################
setMethodS3("bwaSamse", "default", function(pathnameSAI, pathnameFQ, indexPrefix, pathnameD, ..., verbose=FALSE) {
  # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  # Validate arguments
  # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  # Argument 'pathnameSAI':
  pathnameSAI <- Arguments$getReadablePathname(pathnameSAI)

  # Argument 'pathnameFQ':
  pathnameFQ <- Arguments$getReadablePathname(pathnameFQ)

  # Argument 'indexPrefix':
  dummy <- Arguments$getReadablePath(getParent(indexPrefix))

  # Argument 'pathnameD':
  pathnameD <- Arguments$getWritablePathname(pathnameD)

  # Argument 'verbose':
  verbose <- Arguments$getVerbose(verbose)
  if (verbose) {
    pushState(verbose)
    on.exit(popState(verbose))
  }

  verbose && enter(verbose, "Running BWA 'samse'")

  # Assert that input files are not overwritten
  .stop_if_not(getAbsolutePath(pathnameD) != getAbsolutePath(pathnameSAI))
  .stop_if_not(getAbsolutePath(pathnameD) != getAbsolutePath(pathnameFQ))
##  .stop_if_not(getAbsolutePath(pathnameD) != getAbsolutePath(pathnameFA))

  res <- systemBWA("samse", "f"=shQuote(pathnameD), shQuote(indexPrefix), shQuote(pathnameSAI), shQuote(pathnameFQ), ..., verbose=less(verbose, 10))

  verbose && exit(verbose)

  res
}) # bwaSamse()
HenrikBengtsson/aroma.seq documentation built on Feb. 15, 2021, 2:21 a.m.