aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorArun Isaac2022-06-08 17:49:42 +0530
committerArun Isaac2022-06-08 17:49:42 +0530
commit2edd7e65a373e3037c554af4b196016ace154d5a (patch)
tree7e627cd8bb317ac93f201bcee3a197157819fa00
parent832cc7c44a163ccb156c45e547d0cac90fe29593 (diff)
downloadgenenetwork3-2edd7e65a373e3037c554af4b196016ace154d5a.tar.gz
gn3: genodb: Support reading columns.
* gn3/genodb.py (Matrix.__init__): Retrieve column pointers from database. (row): Abstract out vector access code to ... (Matrix.__vector): ... here. (Matrix.column): New method.
-rw-r--r--gn3/genodb.py12
1 files changed, 9 insertions, 3 deletions
diff --git a/gn3/genodb.py b/gn3/genodb.py
index 96bded6..c2decb8 100644
--- a/gn3/genodb.py
+++ b/gn3/genodb.py
@@ -24,10 +24,16 @@ class Matrix():
def __init__(self, db, hash):
self.nrows = int.from_bytes(db.get_metadata(hash, 'nrows'), byteorder='little')
self.ncols = int.from_bytes(db.get_metadata(hash, 'ncols'), byteorder='little')
- self.row_pointers = db.get(hash)
+ row_column_pointers = db.get(hash)
+ self.row_pointers = row_column_pointers[0 : self.nrows*db.hash_length]
+ self.column_pointers = row_column_pointers[self.nrows*db.hash_length :]
self.db = db
- def row(self, index):
+ def __vector(self, index, pointers):
start = index * self.db.hash_length
end = start + self.db.hash_length
- return np.frombuffer(self.db.get(self.row_pointers[start:end]),
+ return np.frombuffer(self.db.get(pointers[start:end]),
dtype=np.uint8)
+ def row(self, index):
+ return self.__vector(index, self.row_pointers)
+ def column(self, index):
+ return self.__vector(index, self.column_pointers)