snpgdsSNPListIntersect {SNPRelate} | R Documentation

## Get a common SNP list between/among SNP list objects

### Description

Get a common SNP list by comparing their snp id, chromosome, positions and allele frequency if needed.

### Usage

    snpgdsSNPListIntersect(snplist1, snplist2, ..., method=c("position", "exact"),
        na.rm=TRUE, same.strand=FALSE, verbose=TRUE)

### Arguments

`snplist1` | the SNP list object `snpgdsSNPListClass`
`snplist2` | the SNP list object `snpgdsSNPListClass`
`...` | the other SNP list objects
`method` | `"exact"`: matching by all snp.id, chromosomes, positions and alleles; `"position"`: matching by chromosomes and positions
`na.rm` | if TRUE, remove mismatched alleles
`same.strand` | if TRUE, assuming the alleles on the same strand
`verbose` | if TRUE, show information

### Value

Return a list of `snpgdsSNPListClass` including the following components:

`idx1` | the indices of common SNPs in the first GDS file
`idx2` | the indices of common SNPs in the second GDS file
`idx...` |
`idx`n`` | the indices of common SNPs in the n-th GDS file
`flag2` | an integer vector, flip flag for each common SNP for the second GDS file (assuming a value `v`): `bitwAnd(v, 1)`: 0 – no flip of allele names, 1 – flip of allele names; `bitwAnd(v, 2)`: 0 – on the same strand, 2 – on the different strands, comparing with the first GDS file; `bitwAnd(v, 4)`: 0 – no strand ambiguity, 4 – ambiguous allele names, determined by allele frequencies; `NA` – mismatched allele names (there is no NA if `na.rm=TRUE`)
`flag...` |
`flag`n`` | flip flag for each common SNP for the n-th GDS file

### Author(s)

Xiuwen Zheng

### See Also

`snpgdsSNPList`

### Examples

    # open an example dataset (HapMap)
    genofile <- snpgdsOpen(snpgdsExampleFileName())

    # to get a snp list object
    snplist1 <- snpgdsSNPList(genofile)
    snplist2 <- snpgdsSNPList(genofile)

    # a common snp list, exactly matching
    v <- snpgdsSNPListIntersect(snplist1, snplist2)
    names(v)
    # "idx1" "idx2"

    # a common snp list, matching by position
    v <- snpgdsSNPListIntersect(snplist1, snplist2, method="pos")
    names(v)
    # "idx1"  "idx2"  "flag2"

    table(v$flag2, exclude=NULL)

    # close the file
    snpgdsClose(genofile)

[Package SNPRelate version 1.28.0 Index]