Main pedigree curation function that performs basic quality control on pedigree information
Usage
qcStudbook(
sb,
minSireAge = NULL,
minDamAge = NULL,
minParentAge = lifecycle::deprecated(),
reportChanges = FALSE,
reportErrors = FALSE
)Arguments
- sb
A dataframe containing a table of pedigree and demographic information.
The function recognizes the following columns (optional columns will be used if present, but are not required):
id— Character vector with Unique identifier for all individualssire— Character vector with unique identifier for the father of the current iddam— Character vector with unique identifier for the mother of the current idsex— Factor (levels: "M", "F", "U") Sex specifier for an individualbirth— Date orNA(optional) with the individual's birth datedeparture— Date orNA(optional) an individual was sold or shipped from the colonydeath— date orNA(optional) Date of death, if applicablestatus— Factor (levels: ALIVE, DECEASED, SHIPPED, UNKNOWN) (optional) Status of an individual (seeconvertStatusCodes)origin— Character orNA(optional) Facility an individual originated from, if other than ONPRCancestry— Character orNA(optional) Geographic population to which the individual belongsspf— Character orNA(optional) Specific pathogen-free status of an individualvasxOvx— Character orNA(optional) Indicator of the vasectomy/ovariectomy status of an animal;NAif animal is intact, assume all other values indicate surgical alterationcondition— Character orNA(optional) Indicator of the restricted status of an animal. "Nonrestricted" animals are generally assumed to be naive.placeholder— Logical orNA(optional)TRUEmarks a made-up stand-in for an unknown parent,FALSEa real animal.TRUE,true,True,Tand1count asTRUE;FALSE,false,False,Fand0asFALSE; a blank as unmarked. Any other value is an error (listed inerrorLst$invalidPlaceholderRowswithreportErrors == TRUE, otherwise the function throws an error naming the rows).
- minSireAge
numeric minimum age in years for a male to have sired an offspring.
NULL(default) looks up the floor for each sire's species viagetSpeciesMinBreedingAge(falling back to 2 years when the species is missing or unknown); a supplied value overrides that floor.- minDamAge
numeric minimum age in years for a female to have borne an offspring.
NULL(default) looks up the floor for each dam's species viagetSpeciesMinBreedingAge(falling back to 2 years when the species is missing or unknown); a supplied value overrides that floor.- minParentAge
Deprecated scalar minimum parent age. Supplying it sets both
minSireAgeandminDamAge; use those sex-specific parameters instead.- reportChanges
logical value that if
TRUE, theerrorLstcontains the list of changes made to the column names. Default isFALSE.- reportErrors
logical value if
TRUEwill scan the entire file and report back changes made to input and errors in a list of list where each sublist is a type of change or error found. Changes will include column names, case of categorical values (male, female, unknown), etc. Errors will include missing columns, invalid date rows, male dams, female sires, an ID that is both a sire and a dam, duplicated IDs, IDs with invalid characters, invalidplaceholdervalues, and records with one or more parents below minimum age of parents.The following changes are made to the column names.
Column names are converted to all lower case
Spaces, periods (".") and underscores ("_") within column names are removed
egoidandegoare converted toidsireidis converted tosiredamidis converted todambirthdateanddeathdateare converted tobirthanddeathrecordstatus,fromcenterandgeographicoriginare converted torecordStatus,fromCenterandgeographicOrigin
If the dataframe (
sb) does not contain the five required columns (id,sire,dam,sex, andbirth) andreportErrors == FALSE, the function throws an error by callingstop(). WithreportErrors == TRUEthe missing names are returned inerrorLst$missingColumns.Animal IDs (
id,sire,dam) must not contain a period ("."); other characters are accepted. Periods cause problems across software environments (R column-name and formula parsing, file-name extensions, programming-language namespaces, and regular expressions), so anyid,sire, ordamvalue containing a period is treated as an error. WithreportErrors == TRUEthe offending values are returned inerrorLst$invalidIdChars; otherwise the function throws an error. All automatically generated IDs (seeaddUIds) honor this rule.If the
idfield has the string UNKNOWN (any case), the record is removed. A record whosesireanddamare bothNAor UNKNOWN (any case) is kept as a founder; UNKNOWN in either field becomesNA. If only one of the fieldssireordamis missing, the missing parent is replaced with a unique identifier with the formUnnnn, wherennnnrepresents one of a series of sequential integers representing the number of missing sires and dams right justified in a pattern of0000. SeeaddUIdsfunction.The function
addParentsis used to add records for parents missing their own record in the pedigree.The function
convertSexCodesis used withignoreHerm == TRUEto convert sex codes according to the following factors of standardized codes:F– replacing "FEMALE" or "2"M– replacing "MALE" or "1"H– replacing "HERMAPHRODITE" or "4", if ignoreHerm == FALSEU– replacing "HERMAPHRODITE" or "4", if ignoreHerm == TRUEU– replacing "UNKNOWN" or "3"U– replacing a missing, blank or unrecognized value
Case and any spaces around a code are ignored.
qcStudbookalways uses the defaultignoreHerm == TRUE, soHis never assigned, although the returned factor keeps the levelH.The function
correctParentSexis used to ensure no parent is both a sire and a dam. If this error is detected andreportErrors == FALSE, the function throws an error and halts the program (withreportErrors == TRUEthe IDs are returned inerrorLst$sireAndDam). It also recodes a female sire as male and a male dam as female; withreportErrors == FALSEthis is silent, otherwise the IDs are reported inerrorLst$femaleSiresanderrorLst$maleDams.The function
convertStatusCodesconverts status indicators to the following factors of standardized codes. Case of the original status value is ignored."ALIVE"— replacing "alive", "A" and "1""DECEASED"— replacing "deceased", "DEAD", "D", "2""SHIPPED"— replacing "shipped", "sold", "sale", "s", "3""UNKNOWN"— replacing is.na(status)"UNKNOWN"— replacing "unknown", "U", "4"
The function
convertAncestryconverts ancestry indicators using regular expressions such that the following conversions are made from character strings that match selected substrings to the following factors."INDIAN"— replacing "ind" and not "chin""CHINESE"— replacing "chin" and not "ind""HYBRID"— replacing "hyb" or "chin" and "ind""JAPANESE"— replacing "jap""UNKNOWN"— replacingNA"OTHER"— replacing not matching any of the above
The function
convertDateconverts character representations of dates in the columnsbirth,death,departure, andexitto dates using theas.Datefunction.The function
setExituses heuristics and the columnsdeathanddepartureto setexitif it is not already defined.The function
calcAgeuses thebirthand theexitcolumns to define theagecolumn. The numerical value is rounded to the nearest 0.1 of a year. Ifexitis not defined, the current system date (Sys.Date()) is used.The function
findGenerationis used to define the generation number for each animal in the pedigree.The function
removeDuplicateschecks for any duplicated records and removes the duplicates. It also throws an error and stops the program if an ID appears in more than one record where one or more of the other columns have a difference.The standard columns come first, followed by any unrecognized columns, which are retained. The rows are ordered by generation number and then ID.
Finally the columns
id,sire, anddamare coerced to character.The returned pedigree always has a logical
placeholdercolumn with noNA:TRUEfor the stand-ins made here (seeaddUIds), the value the input gave for any other row that had one, and for the restTRUEwhen the ID looks like a stand-in (seeremoveAutoGenIds). A center can mark a real animal whose ID looks like a stand-in (for example"U1234") asFALSE.
Value
With reportErrors == FALSE, a data.frame with standardized and
quality controlled pedigree information. With reportErrors == TRUE,
an nprcgenekeeprErr list of the changes and errors found, or
NULL when there are no errors and no column changes to report.
Examples
examplePedigree <- nprcgenekeepr::examplePedigree
ped <- qcStudbook(examplePedigree,
minSireAge = 2.0, minDamAge = 2.0, reportChanges = FALSE,
reportErrors = FALSE
)
names(ped)
#> [1] "id" "sire" "dam" "sex" "gen"
#> [6] "birth" "exit" "age" "ancestry" "origin"
#> [11] "status" "recordStatus" "fromCenter" "placeholder"
