(this will be a supposition because the number are higher but to make things easier)
Imagine that you have genotyped 10 persons and you have 3 SNIPS each one with 2 alels. then you end up with a matrix like this:
, , 1
[,1] | [,2] | [,3] | [,4] | [,5] | [,6] | [,7] | [,8] | [,9] | [,10] | |
---|---|---|---|---|---|---|---|---|---|---|
[1,] | 0 | 0 | 0 | 0 | 1 | 1 | 0 | 1 | 0 | 0 |
[2,] | 0 | 0 | 0 | 1 | 0 | 1 | 0 | 1 | 0 | 0 |
, , 2
[,1] | [,2] | [,3] | [,4] | [,5] | [,6] | [,7] | [,8] | [,9] | [,10] | |
---|---|---|---|---|---|---|---|---|---|---|
[1,] | 1 | 0 | 0 | 0 | 1 | 1 | 0 | 1 | 0 | 0 |
[2,] | 1 | 0 | 1 | 1 | 0 | 1 | 0 | 1 | 0 | 0 |
, , 3
[,1] | [,2] | [,3] | [,4] | [,5] | [,6] | [,7] | [,8] | [,9] | [,10] | |
---|---|---|---|---|---|---|---|---|---|---|
[1,] | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 1 | 0 | 0 |
[2,] | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 1 | 0 | 0 |
I would transform my array and put: something like:
I think is more easy to understand with visually.
, , 1
[,1] | [,2] | [,3] | [,4] | [,5] | [,6] | [,7] | [,8] | [,9] | [,10] | |
---|---|---|---|---|---|---|---|---|---|---|
[1,] | 0 | 0 | 0 | 1 | 1 | 2 | 0 | 2 | 0 | 0 |
, , 2
[,1] | [,2] | [,3] | [,4] | [,5] | [,6] | [,7] | [,8] | [,9] | [,10] | |
---|---|---|---|---|---|---|---|---|---|---|
[1,] | 2 | 0 | 1 | 1 | 1 | 2 | 0 | 2 | 0 | 0 |
, , 3
[,1] | [,2] | [,3] | [,4] | [,5] | [,6] | [,7] | [,8] | [,9] | [,10] | |
---|---|---|---|---|---|---|---|---|---|---|
[1,] | 0 | 0 | 0 | 0 | 0 | 2 | 0 | 2 | 0 | 0 |
And then transform it into a matrix like this (persons x SNIPS)
[,1] | [,2] | [,3] | [,4] | [,5] | [,6] | [,7] | [,8] | [,9] | [,10] | |
---|---|---|---|---|---|---|---|---|---|---|
[1,] | 0 | 0 | 0 | 1 | 1 | 2 | 0 | 2 | 0 | 0 |
[2,] | 2 | 0 | 1 | 1 | 1 | 2 | 0 | 2 | 0 | 0 |
[3,] | 0 | 0 | 0 | 0 | 0 | 2 | 0 | 2 | 0 | 0 |
I usually use R but if someone do this with pyton i can handle it. If someone can help me it will be really helpfull. Thankyou.
Apply colSums
on margin 3.
t(apply(A, 3, colSums))
# [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10]
# [1,] 0 0 0 1 1 2 0 2 0 0
# [2,] 2 0 1 1 1 2 0 2 0 0
# [3,] 0 0 0 0 0 2 0 2 0 0
Data:
A <- structure(c(0L, 0L, 0L, 0L, 0L, 0L, 0L, 1L, 1L, 0L, 1L, 1L, 0L,
0L, 1L, 1L, 0L, 0L, 0L, 0L, 1L, 1L, 0L, 0L, 0L, 1L, 0L, 1L, 1L,
0L, 1L, 1L, 0L, 0L, 1L, 1L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L,
0L, 0L, 0L, 0L, 0L, 1L, 1L, 0L, 0L, 1L, 1L, 0L, 0L, 0L, 0L), dim = c(2L,
10L, 3L))