@@ -113,21 +113,30 @@ scan1snps <-
113113 genoprobs <- genoprobs [,cchr ]
114114 map <- map [cchr ]
115115
116- # check inputs
117- if (length(genoprobs ) != length(map )) {
118- stop(" length(genoprobs) != length(map)" )
119- }
120- if (any(dim(genoprobs )[3 ,] != vapply(map , length , 1 ))) {
121- stop(" genoprobs and map have different numbers of markers" )
122- }
123- dn <- dimnames(genoprobs )[[3 ]]
124- different_names <- FALSE
125- for (i in seq_along(dn )) {
126- if (any(dn [[i ]] != names(map [[i ]]))) different_names <- TRUE
127- }
128- if (different_names ) { # different marker names...give a warning (maybe should be an error)
129- warning(" genoprobs and map have different marker names" )
116+ # check genoprobs and map have same markers in same order
117+ # - subset to common markers if different
118+ # - stop with error if different order
119+ subset_markers <- FALSE
120+ for (ichr in names(genoprobs )) {
121+ markers_genoprobs <- dimnames(genoprobs [[ichr ]])[[3 ]]
122+ markers_map <- names(map [[ichr ]])
123+
124+ if (length(markers_genoprobs ) != length(markers_map ) ||
125+ any(markers_genoprobs != markers_map )) {
126+ subset_markers <- TRUE # later give warning
127+ markers <- markers_genoprobs [markers_genoprobs %in% markers_map ]
128+ if (length(markers )== 0 ) stop(" No markers in common between genoprobs and map on chr " , ichr )
129+ genoprobs [[ichr ]] <- genoprobs [[ichr ]][,,markers_genoprobs %in% markers ,drop = FALSE ]
130+ map [[ichr ]] <- map [[ichr ]][markers_map %in% markers ]
131+
132+ markers_genoprobs <- dimnames(genoprobs [[ichr ]])[[3 ]]
133+ markers_map <- names(map [[ichr ]])
134+ if (any(markers_genoprobs != markers_map ))
135+ stop(" Markers in different order between genoprobs and map on chr " , ichr )
136+ }
130137 }
138+ if (subset_markers ) warning(" Subset to common markers between genoprobs and map" )
139+
131140 if (! is.null(snpinfo ) && ! is.null(query_func )) {
132141 warning(" If snpinfo is provided, chr, start, end, and query_func are all ignored" )
133142 }
0 commit comments