File: test_mapIds.R

package info (click to toggle)
r-bioc-annotationdbi 1.68.0-2
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 8,476 kB
  • sloc: sql: 10,876; makefile: 3; sh: 2
file content (77 lines) | stat: -rw-r--r-- 2,345 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
## unit test to just check that mapIds is behaving itself
require(org.Hs.eg.db)

## constants
k <- head(keys(org.Hs.eg.db, 'ENTREZID'))

# trace("mapIds", tracer=browser, signature ="AnnotationDb")

### The actual tests.

## Default is currently 'first'
test_mapIds_default <- function(){
    res <- mapIds(org.Hs.eg.db, keys=k, column='ALIAS', keytype='ENTREZID')
    checkTrue(length(res) == length(k))
    checkTrue(res[[1]] == "A1B")
    checkTrue(class(res)=='character')
}

## test other return types.

## "list"
test_mapIds_CharacterList <- function(){
    res <- mapIds(org.Hs.eg.db, keys=k, column='ALIAS', keytype='ENTREZID', 
                  multiVals="list")
    checkTrue(length(res) == length(k))
    checkTrue(res[[1]][1] == "A1B")
    checkTrue(class(res)=='list')
}

## "CharacterList"
test_mapIds_CharacterList <- function(){
    res <- mapIds(org.Hs.eg.db, keys=k, column='ALIAS', keytype='ENTREZID', 
       multiVals="CharacterList")
    checkTrue(length(res) == length(k))
    checkTrue(res[[1]][1] == "A1B")
    checkTrue(class(res)=='SimpleCharacterList')
}

## "NAMultiples"
test_mapIds_NAMultiples <- function(){
    res <- mapIds(org.Hs.eg.db, keys=k, column='PFAM', keytype='ENTREZID', 
       multiVals="asNA")
    checkTrue(length(res) == length(k))
    checkTrue(res[['10']] == "PF00797")
    checkTrue(class(res)=='character')

    res <- mapIds(org.Hs.eg.db, "2", "PFAM", "ENTREZID", multiVals = "asNA")
    checkTrue(is.character(res))
    checkIdentical(length(res), 1L)
}

## "filterMultiples"
test_mapIds_filterMultiples <- function(){
    res <- mapIds(org.Hs.eg.db, keys=k, column='PFAM', keytype='ENTREZID', 
       multiVals="filter")
    checkTrue(length(res) < length(k)) ## multi matchers means should be shorter
    checkTrue(res[['10']] == "PF00797")
    checkTrue(res[['1']] == "PF13895")
    checkTrue(class(res)=='character')

    res <- mapIds(org.Hs.eg.db, "2", "PFAM", "ENTREZID", multiVals = "filter")
    checkTrue(is.character(res))
    checkIdentical(length(res), 0L)
}


## CUSTOM function
test_mapIds_FUN <- function(){
    last <- function(x){
    x[[length(x)]]
    }
    res <- mapIds(org.Hs.eg.db, keys=k, column='ALIAS', keytype='ENTREZID', 
       multiVals=last)
    checkTrue(length(res) == length(k))
    checkTrue(res[[1]] == "A1BG")
    checkTrue(class(res)=='character')
}