standardize_bam: Standardize object names in bam files (dat, tpl, and cxx)

View source: R/standardize_bam.r

standardize_bamR Documentation

Standardize object names in bam files (dat, tpl, and cxx)

Description

This script reads in BAM dat, tpl, and cxx files, and converts them to R objects (character vectors of each line of the code). It then runs a set of gsub() functions to replace object names with preferred naming conventions and returns dat, tpl, and cxx character vectors to use to rewrite the corresponding files with writeLines)

Usage

standardize_bam(
  CommonName = NULL,
  bam = NULL,
  dat_file = NULL,
  tpl_file = NULL,
  cxx_file = NULL,
  dat_obj = NULL,
  tpl_obj = NULL,
  cxx_obj = NULL,
  nm_pattern = NULL,
  nm_replace = NULL,
  match_whole_words = TRUE,
  fleet_key = list(sCT = c("CVT"), sTV = c("CVID", "Mcvt", "mcvt"), sVD = c("VID"), sBT =
    c("Mbft"), sBL = c("sM"), sVL = c("vll"), sFT = c("FST"), sAN = c("nad"), sAM =
    c("mad"), sAS = c("sad"), sJA = c("jai"), sME = c("mareco"), cDV = c("cD"), cHL =
    c("cH", "cHl"), cLL = c("cL"), cOT = c("cO"), cPT = c("cp", "cP"), cTW = c("cT",
    "cTw", "cHTR"), cGN = c("comm"), cRN = c("cRn"), cRS = c("cRs"), cBN = c("cBn"), cBS
    = c("cBs"), rHB = c("HB", "hb", "rHb"), rHD = c("hbd", "HBD"), rGN = c("GR", "mrip",
    "rGe", "rA")),
  fleet_replace = TRUE
)

Arguments

CommonName

Common name of species modeled in BAM files. Only used when accessing dat, tpl, and cxx character vectors named as e.g. dat_CommonName

bam

Output of bam2r.

dat_file

dat file path

tpl_file

tpl file path

cxx_file

cxx file path

dat_obj

dat file read in as a character vector with readLines(con=dat_file)

tpl_obj

tpl file read in as a character vector with readLines(con=tpl_file)

cxx_obj

cxx file read in as a character vector with readLines(con=cxx_file)

nm_pattern

Character vector of additional object names (i.e. patterns) to be replaced

nm_replace

Character vector of of replacements for nm1

match_whole_words

Should patterns replace whole words only (pattern is regex enclosed by \b)

fleet_key

key to fleet names as a names list of character vectors. names of list items are the replacements while the character vectors are sets of old fleet names to replace

Examples

## Not run: 
# Read in and standardize of the current BAM models
bam_AtMe <- standardize_bam("AtlanticMenhaden")
bam_BlSB <- standardize_bam("BlackSeaBass")
bam_BlTi <- standardize_bam("BluelineTilefish")
bam_Cobi <- standardize_bam("Cobia")
bam_GagG <- standardize_bam("GagGrouper")
bam_GrTr <- standardize_bam("GrayTriggerfish")
bam_GrAm <- standardize_bam("GreaterAmberjack")
bam_ReGr <- standardize_bam("RedGrouper")
bam_RePo <- standardize_bam("RedPorgy")
bam_ReSn <- standardize_bam("RedSnapper")
bam_ScGr <- standardize_bam("ScampGrouper")
bam_SnGr <- standardize_bam("SnowyGrouper")
bam_Tile <- standardize_bam("Tilefish")
bam_VeSn <- standardize_bam("VermilionSnapper")

# Run a bam model and assign rdat output to object
rdat_RePo <- run_bam(bam=bam_RePo,fileName="RePo")

## End(Not run)

nikolaifish/bamExtras documentation built on July 21, 2023, 8:26 a.m.