aboutsummaryrefslogtreecommitdiff
path: root/gn3
diff options
context:
space:
mode:
authorArun Isaac2022-06-17 14:12:25 +0530
committerArun Isaac2022-06-17 14:13:54 +0530
commit9c98575e712d623083347271389395b2a90a6484 (patch)
treee9b7cbb81f7d8b8f407028b9d4e2ad25a4d1b123 /gn3
parentb480e1e4f98bfab66168811201eb541f965be554 (diff)
downloadgenenetwork3-9c98575e712d623083347271389395b2a90a6484.tar.gz
gn3: genodb: Allow retrieval of the entire genotype matrix.
* gn3/genodb.py: Document nparray in the module docstring. (nparray): New function.
Diffstat (limited to 'gn3')
-rw-r--r--gn3/genodb.py7
1 files changed, 7 insertions, 0 deletions
diff --git a/gn3/genodb.py b/gn3/genodb.py
index ba668d2..7ffaf8b 100644
--- a/gn3/genodb.py
+++ b/gn3/genodb.py
@@ -5,6 +5,7 @@ database. It exports the following functions.
* open - Open a genotype database
* matrix - Get current matrix
+* nparray - Get matrix as a 2D numpy array
* row - Get row of matrix
* column - Get column of matrix
@@ -15,6 +16,7 @@ from gn3 import genodb
with genodb.open('/tmp/bxd') as db:
matrix = genodb.matrix(db)
+ print(genodb.nparray(matrix))
print(genodb.row(matrix, 17))
print(genodb.column(matrix, 13))
'''
@@ -58,6 +60,11 @@ def matrix(db):
np.reshape(np.frombuffer(read_optimized_blob[nrows*ncols :], dtype=np.uint8),
(nrows, ncols)))
+def nparray(matrix):
+ '''Get matrix as a 2D numpy array.'''
+ # pylint: disable=redefined-outer-name
+ return matrix.array
+
def row(matrix, index):
'''Get row of matrix.'''
# pylint: disable=redefined-outer-name