@@ -41,6 +41,81 @@ standardizeColnames <- function(df, verbose = FALSE) {
4141
4242 return (df )
4343}
44+ # ' Restore Original Column Names in a Pedigree Dataframe
45+ # '
46+ # ' This function restores the original column names of a pedigree dataframe
47+ # ' based on user-specified names. It is useful for reverting standardized column
48+ # ' names back to their original names after processing.
49+ # ' @param ped A pedigree dataframe with standardized column names.
50+ # ' @param famID The original name for the family ID column. Default is "fam
51+ # ' ID".
52+ # ' @param personID The original name for the person ID column. Default is "ID".
53+ # ' @param momID The original name for the mother ID column. Default is "momID".
54+ # ' @param dadID The original name for the father ID column. Default is "dadID".
55+ # ' @param gen The original name for the generation column. Default is "gen".
56+ # ' @param patID The original name for the paternal ID column. Default is "patID".
57+ # ' @param matID The original name for the maternal ID column. Default is "matID".
58+ # ' @param spID The original name for the spouse ID column. Default is "spID".
59+ # ' @param twinID The original name for the twin ID column. Default is "twinID".
60+ # ' @param zygosity The original name for the zygosity column. Default is "zygosity".
61+ # ' @param sex The original name for the sex column. Default is "sex".
62+ # ' @param verbose A logical indicating whether to print progress messages.
63+ # ' @return A pedigree dataframe with restored original column names.
64+ restorePedColnames <- function (ped ,
65+ famID = " famID" ,
66+ personID = " ID" ,
67+ momID = " momID" ,
68+ dadID = " dadID" ,
69+ gen = " gen" ,
70+ patID = " patID" ,
71+ matID = " matID" ,
72+ spID = " spID" ,
73+ twinID = " twinID" ,
74+ zygosity = " zygosity" ,
75+ sex = " sex" ,
76+ verbose = FALSE ) {
77+ if (verbose == TRUE ) {
78+ message(" Restoring original column names..." )
79+ }
80+ if (! inherits(ped , " data.frame" )) {
81+ stop(" ped should be a data.frame or inherit to a data.frame" )
82+ }
83+ if (! is.null(personID ) && ! is.null(ped $ ID )) {
84+ names(ped )[names(ped ) == " ID" ] <- personID
85+ }
86+ if (! is.null(momID ) && ! is.null(ped $ momID )) {
87+ names(ped )[names(ped ) == " momID" ] <- momID
88+ }
89+ if (! is.null(dadID ) && ! is.null(ped $ dadID )) {
90+ names(ped )[names(ped ) == " dadID" ] <- dadID
91+ }
92+
93+ if (! is.null(famID ) && ! is.null(ped $ famID )) {
94+ names(ped )[names(ped ) == " famID" ] <- famID
95+ }
96+ if (! is.null(gen ) && ! is.null(ped $ gen )) {
97+ names(ped )[names(ped ) == " gen" ] <- gen
98+ }
99+ if (! is.null(patID ) && ! is.null(ped $ patID )) {
100+ names(ped )[names(ped ) == " patID" ] <- patID
101+ }
102+ if (! is.null(matID ) && ! is.null(ped $ matID )) {
103+ names(ped )[names(ped ) == " matID" ] <- matID
104+ }
105+ if (! is.null(spID ) && ! is.null(ped $ spID )) {
106+ names(ped )[names(ped ) == " spID" ] <- spID
107+ }
108+ if (! is.null(twinID ) && ! is.null(ped $ twinID )) {
109+ names(ped )[names(ped ) == " twinID" ] <- twinID
110+ }
111+ if (! is.null(zygosity ) && ! is.null(ped $ zygosity )) {
112+ names(ped )[names(ped ) == " zygosity" ] <- zygosity
113+ }
114+ if (! is.null(sex ) && ! is.null(ped $ sex )) {
115+ names(ped )[names(ped ) == " sex" ] <- sex
116+ }
117+ ped
118+ }
44119
45120
46121# Repair Pedigree
0 commit comments