extract.hapmap.haplotypes {genomic}R Documentation

Function to convert hapmap data to gemonic type data

Description

Function to convert lists of hapmap data read through read.hapmap.phasing into the format useable by haploview.

Usage

extract.hapmap.haplotypes(h, usepos, start = 0, finish = 1)

Arguments

h The list of haplotype data
usepos Use these rows
start The starting position (in MB)
finish The fijnishing position (in MB)

Value

A list of class GenomicHaplotype

Author(s)

Ian J Wilson <I.J.Wilson@ncl.ac.uk>

Examples

##---- Should be DIRECTLY executable !! ----
##-- ==>  Define data, use random,
##--    or do  help(data=index)  for the standard data sets.

## The function is currently defined as
function (h, usepos, start = 0, finish = 1) 
{
    if (missing(usepos)) {
        pos <- lapply(h$positions, function(x) x[x > start * 
            10^6 & x <= finish * 10^6])
        usepos <- pos[[1]]
        for (i in 2:length(pos)) {
            u <- match(usepos, pos[[i]])
            u <- u[!is.na(u)]
            usepos <- pos[[i]][u]
        }
        pos <- h$positions[[1]]
        posa <- pos[pos > start * 10^6 & pos <= finish * 10^6]
    }
    res <- NULL
    loc <- NULL
    for (i in 1:length(h$d)) {
        m <- match(usepos, h$positions[[i]])
        if (sum(is.na(m)) > 0) {
            stop(paste("missing positions", paste(usepos[is.na(m)], 
                collapse = " "), "in population", names(h$positions)[i]))
        }
        res <- rbind(res, h$d[[i]][, m])
        loc <- c(loc, rep(names(h$positions)[i], nrow(h$d[[i]])))
    }
    m <- match(usepos, h$positions[[1]])
    SNP = h$SNP[[1]][m]
    if (length(h$d) == 1) {
        res <- list(d = res, positions = usepos, SNP = SNP)
        class(res) <- "GenomicHaplotypes"
    }
    else {
        res <- list(d = res, positions = usepos, locations = factor(loc), 
            SNP = SNP)
        class(res) <- c("simapop", "GenomicHaplotypes")
    }
    res
  }

[Package genomic version 1.0 Index]