forked from cran/PopGenome
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcount.unknowns.R
84 lines (45 loc) · 2.18 KB
/
count.unknowns.R
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
78
79
80
81
82
setGeneric("count.unknowns", function(object) standardGeneric("count.unknowns"))
setMethod("count.unknowns","GENOME",function(object){
region.names <- [email protected]
n.region.names <- length(region.names)
if([email protected]){region.names <- NULL} # because of memory space
npops <- length(object@populations) # N Populations
#########################################
# INIT
#########################################
nam <- paste("pop",1:npops)
init1 <- matrix(0,n.region.names,npops)
missing.nucleotides <- init1
missing.frequencies <- vector("list",n.region.names) # region stats
change <- [email protected]
#--------------------------------------------------
# Names ----------------------------------------
rownames(missing.nucleotides) <- region.names
colnames(missing.nucleotides) <- nam
# ----------------------------------------------
## PROGRESS #########################
progr <- progressBar()
#####################################
for(xx in 1:n.region.names){
### if Subsites ----------------------------------
bial <- popGetBial(object,xx)
if(length(bial)!=0){ # if a biallelic position exists
populations <- [email protected]@populations[[xx]] # Pop
if(length([email protected]@popmissing[[xx]])!=0){popmissing <- [email protected]@popmissing[[xx]];respop <- (1:npops)[-popmissing]}else{respop <- 1:npops}
res <- calc_miss(bial,populations)
# fill detailed Slots --------------------------------#
missing.frequencies[[xx]] <- res$miss.freq
# ----------------------------------------------------#
missing.nucleotides[xx,respop] <- res$miss.nuc
# PROGRESS #######################################################
progr <- progressBar(xx,n.region.names, progr)
###################################################################
}
}
[email protected] <- missing.frequencies
[email protected] <- change
rm(change)
gc()
[email protected] <- missing.nucleotides
return(object)
})