snpgdsHCluster: Hierarchical cluster analysis

Description Usage Arguments Details Value Author(s) See Also Examples

View source: R/AllUtilities.R

Description

Perform hierarchical cluster analysis on the dissimilarity matrix.

Usage

1
snpgdsHCluster(dist, sample.id=NULL, need.mat=TRUE, hang=0.25)

Arguments

dist

an object of "snpgdsDissClass" from snpgdsDiss, an object of "snpgdsIBSClass" from snpgdsIBS, or a square matrix for dissimilarity

sample.id

to specify sample id, only work if dist is a matrix

need.mat

if TRUE, store the dissimilarity matrix in the result

hang

The fraction of the plot height by which labels should hang below the rest of the plot. A negative value will cause the labels to hang down from 0.

Details

Call the function hclust to perform hierarchical cluster analysis, using method="average".

Value

Return a list (class "snpgdsHCClass"):

sample.id

the sample ids used in the analysis

hclust

an object returned from hclust

dendrogram
dist

the dissimilarity matrix, if need.mat = TRUE

Author(s)

Xiuwen Zheng

See Also

snpgdsIBS, snpgdsDiss, snpgdsCutTree

Examples

 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
# open an example dataset (HapMap)
genofile <- snpgdsOpen(snpgdsExampleFileName())

pop.group <- read.gdsn(index.gdsn(genofile, "sample.annot/pop.group"))
pop.group <- as.factor(pop.group)
pop.level <- levels(pop.group)

diss <- snpgdsDiss(genofile)
hc <- snpgdsHCluster(diss)
rv <- snpgdsCutTree(hc)
rv

# call 'plot' to draw a dendrogram
plot(rv$dendrogram, leaflab="none", main="HapMap Phase II")


# the distribution of Z scores
snpgdsDrawTree(rv, type="z-score", main="HapMap Phase II")

# draw dendrogram
snpgdsDrawTree(rv, main="HapMap Phase II",
    edgePar=list(col=rgb(0.5,0.5,0.5, 0.75), t.col="black"))


# close the file
snpgdsClose(genofile)

Example output

Loading required package: gdsfmt
SNPRelate -- supported by Streaming SIMD Extensions 2 (SSE2)
Individual dissimilarity analysis on genotypes:
Excluding 365 SNPs on non-autosomes
Excluding 1 SNP (monomorphic: TRUE, MAF: NaN, missing rate: NaN)
    # of samples: 279
    # of SNPs: 8,722
    using 1 thread
Dissimilarity:    the sum of all selected genotypes (0,1,2) = 2446510
Dissimilarity:	Wed Jan  6 22:17:21 2021	0%
Dissimilarity:	Wed Jan  6 22:17:22 2021	100%
Determine groups by permutation (Z threshold: 15, outlier threshold: 5):
Create 3 groups.
$sample.id
  [1] "NA19152"     "NA19139"     "NA18912"     "NA19160"     "NA07034"    
  [6] "NA07055"     "NA12814"     "NA10847"     "NA18532"     "NA18561"    
 [11] "NA18942"     "NA18940"     "NA18515"     "NA19222"     "NA18508"    
 [16] "NA19129"     "NA12056"     "NA10863"     "NA10857"     "NA12006"    
 [21] "NA18605"     "NA18542"     "NA18945"     "NA18949"     "NA19238"    
 [26] "NA19194"     "NA19142"     "NA18913"     "NA12145"     "NA12763"    
 [31] "NA07357"     "NA12144"     "NA18550"     "NA18608"     "NA18964"    
 [36] "NA18953"     "NA19154"     "NA19138"     "NA18852"     "NA19120"    
 [41] "NA07019"     "NA10831"     "NA07000"     "NA11832"     "NA18564"    
 [46] "NA18961"     "NA18972"     "NA19210"     "NA19204"     "NA18507"    
 [51] "NA19159"     "NA06991"     "NA11840"     "NA12802"     "NA12813"    
 [56] "NA18571"     "NA18620"     "NA18967"     "NA18976"     "NA19211"    
 [61] "NA18516"     "NA18523"     "NA12761"     "NA10830"     "NA10855"    
 [66] "NA18623"     "NA18576"     "NA18981"     "NA18971"     "NA18862"    
 [71] "NA19205"     "NA19101"     "NA19102"     "NA06994"     "NA11993"    
 [76] "NA11995"     "NA12891"     "NA18582"     "NA18633"     "NA18994"    
 [81] "NA18872"     "NA19192"     "NA19172"     "NA19092"     "NA12864"    
 [86] "NA12751"     "NA10839"     "NA12717"     "NA18637"     "NA18594"    
 [91] "NA18998"     "NA19000"     "NA12753"     "NA12707"     "NA11839"    
 [96] "NA10859"     "NA18526"     "NA18524"     "NA18529"     "NA18558"    
[101] "NA18502"     "NA19145"     "NA18505"     "NA18856"     "NA12875"    
[106] "NA12156.dup" "NA12156"     "NA07056"     "NA18562"     "NA18537"    
[111] "NA18603"     "NA18540"     "NA19153"     "NA19137"     "NA19202"    
[116] "NA19239"     "NA12044"     "NA11992"     "NA11829"     "NA07022"    
[121] "NA18545"     "NA18572"     "NA18547"     "NA18609.dup" "NA18857"    
[126] "NA19238.dup" "NA18501"     "NA19240"     "NA06993.dup" "NA12239"    
[131] "NA12154"     "NA12762"     "NA18609"     "NA18552"     "NA18611"    
[136] "NA18555"     "NA19223"     "NA18500"     "NA18861"     "NA12716"    
[141] "NA12878"     "NA10856"     "NA12874"     "NA18566"     "NA18563"    
[146] "NA18570"     "NA18612"     "NA19201"     "NA19144"     "NA19193"    
[151] "NA18503"     "NA12760"     "NA11993.dup" "NA06985"     "NA12003"    
[156] "NA18621"     "NA18594.dup" "NA18622"     "NA18573"     "NA18504"    
[161] "NA19203"     "NA19143"     "NA18871"     "NA07348"     "NA12750"    
[166] "NA11831"     "NA10835"     "NA18577"     "NA18624"     "NA18579"    
[171] "NA18632"     "NA18870"     "NA19200"     "NA18517"     "NA19221"    
[176] "NA12146"     "NA11882"     "NA18635"     "NA18592"     "NA18636"    
[181] "NA18593"     "NA18863"     "NA18855"     "NA18862.dup" "NA19209"    
[186] "NA18951.dup" "NA18943"     "NA18947"     "NA18944"     "NA18521"    
[191] "NA18858"     "NA19141"     "NA19093"     "NA10861"     "NA12005"    
[196] "NA10851"     "NA12234"     "NA18948"     "NA18951"     "NA18952"    
[201] "NA18956"     "NA19099"     "NA18854"     "NA19132"     "NA12004"    
[206] "NA07345"     "NA07029"     "NA12892"     "NA18968"     "NA18959"    
[211] "NA18969"     "NA18960"     "NA19206"     "NA18506"     "NA19098"    
[216] "NA19130"     "NA07048"     "NA10854"     "NA12248"     "NA10846"    
[221] "NA18965"     "NA18973"     "NA18966"     "NA18975"     "NA19128"    
[226] "NA19131"     "NA18522"     "NA19208"     "NA12801"     "NA12872"    
[231] "NA12155"     "NA06993"     "NA18978"     "NA18970"     "NA18980"    
[236] "NA18995.dup" "NA18859.dup" "NA19116"     "NA18914"     "NA19127"    
[241] "NA11830"     "NA12865"     "NA10838"     "NA12249"     "NA18974"    
[246] "NA18987"     "NA18990"     "NA18991"     "NA19094"     "NA19161"    
[251] "NA18853"     "NA19173"     "NA12057"     "NA10860"     "NA12812"    
[256] "NA11881"     "NA18992"     "NA18995"     "NA18997"     "NA19012"    
[261] "NA19171"     "NA19140"     "NA18859"     "NA19119"     "NA11994"    
[266] "NA12873"     "NA12815"     "NA19005"     "NA18999"     "NA19007"    
[271] "NA19003"     "NA18860"     "NA19207"     "NA19100"     "NA19103"    
[276] "NA12740"     "NA12752"     "NA12043"     "NA12264"    

$z.threshold
[1] 15

$outlier.n
[1] 5

$samp.order
  [1]  83 252 261   1  37 113  50  15 214 227  62 190 251  39 203 139 182  70
 [19] 184 226 204 216  82  26 150 237 263 191 272 114   2  38 193  84 249  72
 [37]  73 275 162 102 149  48  60 185 240  16 225  51   4 250 104 125 183 262
 [55]  27 192 273 213 228 215 202 274   3 116 128  25 126  28 239 137  14 175
 [73] 101 127 138 173 115 148 172  81 163 238  40 264 161  49  71 103 151 160
 [91]  61  13 174 198 171 180  78   9  33 124 133 110 144  56 269  24 257  91
[109] 233 212 260  11 247 146 147  99 109  67 111 169  34  21 178  89 168 156
[127]  10  22  98 100 145 179 136  79 121  57 181 112 246 201 268 245 122 259
[145] 158 187  47  92  46 270  35 234 224  90 157  68 222 200  97 134 248 235
[163] 186 199 170 223  36 189 221 188 210  58  12 209  80 236 258  23 271  69
[181] 211 123  45  59 135  66 159 265  76 194 152  63 277 205 155 243  53  95
[199] 218  30  93 132   5   6 217  75 153 118 254 129 232  52 154 108  41 120
[217] 208  77 141   7  54 267  86 165 276  20  87 195 117  19 278 105 143 242
[235] 140  88  94 197  18 279 106 107  42 231  74  43 207 241 119 142 253  17
[253] 196 130   8 176  64 131 166  44  65  32  29 220  55 229 255 177  96 256
[271] 230  85 266 219 167 244  31 164 206

$samp.group
  [1] G001 G001 G001 G001 G003 G003 G003 G003 G002 G002 G002 G002 G001 G001 G001
 [16] G001 G003 G003 G003 G003 G002 G002 G002 G002 G001 G001 G001 G001 G003 G003
 [31] G003 G003 G002 G002 G002 G002 G001 G001 G001 G001 G003 G003 G003 G003 G002
 [46] G002 G002 G001 G001 G001 G001 G003 G003 G003 G003 G002 G002 G002 G002 G001
 [61] G001 G001 G003 G003 G003 G002 G002 G002 G002 G001 G001 G001 G001 G003 G003
 [76] G003 G003 G002 G002 G002 G001 G001 G001 G001 G003 G003 G003 G003 G002 G002
 [91] G002 G002 G003 G003 G003 G003 G002 G002 G002 G002 G001 G001 G001 G001 G003
[106] G003 G003 G003 G002 G002 G002 G002 G001 G001 G001 G001 G003 G003 G003 G003
[121] G002 G002 G002 G002 G001 G001 G001 G001 G003 G003 G003 G003 G002 G002 G002
[136] G002 G001 G001 G001 G003 G003 G003 G003 G002 G002 G002 G002 G001 G001 G001
[151] G001 G003 G003 G003 G003 G002 G002 G002 G002 G001 G001 G001 G001 G003 G003
[166] G003 G003 G002 G002 G002 G002 G001 G001 G001 G001 G003 G003 G002 G002 G002
[181] G002 G001 G001 G001 G001 G002 G002 G002 G002 G001 G001 G001 G001 G003 G003
[196] G003 G003 G002 G002 G002 G002 G001 G001 G001 G003 G003 G003 G003 G002 G002
[211] G002 G002 G001 G001 G001 G001 G003 G003 G003 G003 G002 G002 G002 G002 G001
[226] G001 G001 G001 G003 G003 G003 G003 G002 G002 G002 G002 G001 G001 G001 G001
[241] G003 G003 G003 G003 G002 G002 G002 G002 G001 G001 G001 G001 G003 G003 G003
[256] G003 G002 G002 G002 G002 G001 G001 G001 G001 G003 G003 G003 G002 G002 G002
[271] G002 G001 G001 G001 G001 G003 G003 G003 G003
Levels: G001 G002 G003

$dmat
          G001      G002      G003
G001 0.9532539 1.0965483 1.0956439
G002 1.0965483 0.8313777 0.9752263
G003 1.0956439 0.9752263 0.8966300

$dendrogram
'dendrogram' with 2 branches and 279 members total, at height 1.096101 

$merge
              z n1  n2
1     0.0000000  1   1
2     0.0000000  1   1
3     0.0000000  1   1
4     0.0000000  1   1
5     0.0000000  1   1
6     0.0000000  1   1
7     0.0000000  1   1
8     0.0000000  1   1
9     0.0000000  1   1
10    0.0000000  1   1
11    0.0000000  1   1
12    0.0000000  1   1
13    0.0000000  1   1
14    0.0000000  1   1
15    0.0000000  1   1
16    0.0000000  1   1
17    0.0000000  1   1
18    0.0000000  1   1
19    0.0000000  1   1
20    0.0000000  1   1
21    0.0000000  1   1
22    0.0000000  1   1
23    0.0000000  1   1
24    0.0000000  1   1
25    0.0000000  1   1
26    0.0000000  1   1
27    0.0000000  1   1
28    0.0000000  1   1
29    0.0000000  1   1
30    0.0000000  1   1
31    0.0000000  1   1
32    0.0000000  1   1
33    0.0000000  1   1
34    0.0000000  1   1
35    0.0000000  1   1
36    0.0000000  1   1
37    0.0000000  1   1
38    0.0000000  1   1
39    0.0000000  1   1
40    0.0000000  1   1
41    0.0000000  1   1
42    0.0000000  1   1
43    0.0000000  1   1
44    0.0000000  1   1
45    0.0000000  1   1
46    0.0000000  1   1
47    0.0000000  1   1
48    0.0000000  1   1
49    0.0000000  1   1
50    0.0000000  1   1
51    0.0000000  1   1
52    0.0000000  1   1
53    0.0000000  1   1
54    0.0000000  1   1
55    0.0000000  1   1
56    0.0000000  1   1
57    0.0000000  1   1
58    0.0000000  1   1
59    0.0000000  1   1
60    0.0000000  1   1
61    1.4569172  1   2
62    0.0000000  1   1
63    0.0000000  1   1
64    0.0000000  1   1
65    0.0000000  1   1
66    0.0000000  1   1
67    0.0000000  1   1
68    0.0000000  1   1
69    0.0000000  1   1
70    0.0000000  1   1
71    1.4449585  2   2
72    0.7117858  1   2
73    0.7275347  1   2
74    0.7273380  1   2
75    0.7689553  1   2
76    0.7365853  1   2
77    0.7152495  1   2
78    0.7148537  1   2
79    0.7575992  1   2
80    0.7248823  1   2
81    0.7261343  1   2
82    0.7107089  1   2
83    0.7059547  1   2
84    0.7305831  1   2
85    0.7347306  1   2
86    0.7132183  1   2
87    1.4562490  2   2
88    0.7089801  1   2
89    1.4037253  2   2
90    0.7220267  1   2
91    0.7411477  1   2
92    0.7144521  1   2
93    0.7300025  1   2
94    0.7045788  1   2
95    0.7546066  1   2
96    0.0000000  1   1
97    0.7352917  1   2
98    1.4616206  2   2
99    0.0000000  1   1
100   0.7559686  1   2
101   1.3981013  1   2
102   0.7381826  1   2
103   0.7343906  1   2
104   0.0000000  1   1
105   1.1946910  1   2
106   0.0000000  1   1
107   0.0000000  1   1
108   0.0000000  1   1
109   0.0000000  1   1
110   0.0000000  1   1
111   0.0000000  1   1
112   1.0286414  1   3
113   0.0000000  1   1
114   0.0000000  1   1
115   0.0000000  1   1
116   1.4075217  1   2
117   1.5224299  1   3
118   0.0000000  1   1
119   0.0000000  1   1
120   1.4159969  1   2
121   1.1568291  2   2
122   1.2851068  1   4
123   1.4106846  1   2
124   0.0000000  1   1
125   0.7365791  1   2
126   0.0000000  1   1
127   0.0000000  1   1
128   1.7649724  2   3
129   1.4247622  4   5
130   0.9086049  1   2
131   1.4267748  1   2
132   1.3227807  1   2
133   0.0000000  1   1
134   0.0000000  1   1
135   1.2308343  2   2
136   1.3195131  3   4
137   0.9744259  1   3
138   1.2650334  3   5
139   0.0000000  1   1
140   0.0000000  1   1
141   0.9992920  1   2
142   1.0842204  9   2
143   0.0000000  1   1
144   0.0000000  1   1
145   0.0000000  1   1
146   2.1751247  8  11
147   0.0000000  1   1
148   2.2765449  4   3
149   0.7394863  1   2
150   1.6351464  1   3
151   1.2667413  2   2
152   0.0000000  1   1
153   1.3825202  3   7
154   0.0000000  1   1
155   3.0150189 19  10
156   2.7530660  3   4
157   0.0000000  1   1
158   0.9375641  1   2
159   2.0899315  4  29
160   1.3014662  1   2
161   2.0923566  4  33
162   1.4105440  1   7
163   2.2398236  2   7
164   0.7574411  1   2
165   0.7208835  1   2
166   1.3677347  1   2
167   2.2370415  2   9
168   2.0779231  2  37
169   4.8159240  8  11
170   0.7307508  1   2
171   1.4902405  1  39
172   2.0252288  2  40
173   5.7537895 19  42
174   0.7088630  1   2
175   2.2755079  2   3
176   2.0754548  3   3
177   1.5814525  2   5
178   3.1017651 61   6
179   0.0000000  1   1
180   0.7477703  1   2
181   3.3386462  7  67
182   1.8425567  2  74
183   0.7069893  1   2
184   1.8007846  2  76
185   0.0000000  1   1
186   0.0000000  1   1
187   0.7016553  1   2
188   1.4183228  1   2
189   2.2511535  2  78
190   2.2389373  2  80
191   0.7226110  1   2
192   2.2803096  2  82
193   0.7720612  1   2
194   2.2921206  2  84
195   0.7535293  1   2
196   2.9210921  3  86
197   1.6847157  1  89
198   1.7432102  1  90
199   0.7366455  1   2
200   0.7909925  1   2
201   2.9225612  2  91
202   0.7402145  1   2
203   0.7336314  1   2
204   0.7505889  1   2
205   2.3536143  1  93
206   0.7304067  1   2
207   0.7459735  1   2
208   0.8230214  1   2
209   0.6878292  1   2
210   0.7262134  1   2
211   0.7362767  1   2
212   1.3722708  2   2
213   0.7618462  1   2
214   0.7509534  1   2
215   0.7545973  1   2
216   0.7232046  1   2
217   2.2960758  2   4
218   1.7252188  1   3
219   2.3883671  3   3
220   2.2283869  3   3
221   2.8784643  3   6
222   2.8331170  4   3
223   2.0016060  2   3
224   2.3135630  3   3
225   3.2453311  3   9
226   3.0184727  4   6
227   3.4032258  3  12
228   2.3782695  3   3
229   2.2881827  3   3
230   3.6066056  3  15
231   3.2112973  3  10
232   4.2035537  5  18
233   4.4105249  6  23
234   2.8293170  3   6
235   6.1157980 13  29
236   4.3706686  6  42
237   2.8807091  3   4
238   5.0223996  9  48
239   3.0813581  3  57
240   2.3128117  3   3
241   2.9343107  3  60
242   4.8898994  7  63
243   4.3931075  7  70
244   2.9684581  3  77
245   3.0939511  3  80
246   5.5139037  6  83
247   1.5821956  1   6
248   4.7342949  3  89
249   2.1376020  3   3
250   3.5820692  3   7
251   2.3026921  3   3
252   2.2823732  3   3
253   4.3477018 10   6
254   2.3248296  3   3
255   2.2649940  3   3
256   2.3643592  3   3
257   3.1261532  3  16
258   2.7716230  3   6
259   3.1030904  3  19
260   2.8211907  3   6
261   4.3375448  6  22
262   2.7931292  3   6
263   3.3149933  4   6
264   5.2136192 28   9
265   3.3228278  4   9
266   4.9736823  9  37
267   5.9978223 13  46
268   5.7140441 10  59
269   2.3251032  3   3
270   2.8953113  3  69
271   2.7992312  3   6
272   5.3914263 72   9
273   3.0700506  3  81
274   3.0014295  3  84
275   2.9772642  3  87
276   3.7140769  3  90
277 122.2690280 94  92
278  61.0609703 93 186

$clust.count
cluster
G001 G002 G003 
  93   94   92 

SNPRelate documentation built on Nov. 8, 2020, 5:31 p.m.