Skip to content

Commit 387dd79

Browse files
committed
Corrects a bug when parsing MavericK Qmatrix files that did not have a population identifier field
1 parent 213f7cc commit 387dd79

File tree

1 file changed

+12
-9
lines changed

1 file changed

+12
-9
lines changed

structure_threader/plotter/structplot.py

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -283,15 +283,18 @@ def _parse_maverick(self):
283283
"""
284284

285285
# Explanation of data import:
286-
# 1. Import data using genfromtxt numpy method, specifiying the
287-
# delimiter and skiping the first header line
288-
# 2. Remove the first three columns from the array with .T[3:].
289-
# However, this messes the shape of the structure array, so....
290-
# 3. We transpose the array so that each row is a taxon and
291-
# the columns represent the assignment probabilities for each K
292-
mavarray = np.genfromtxt(self.file_path, delimiter=",",
293-
skip_header=1)
294-
self.qvals = mavarray.T[3:].T
286+
# 1. Figure out which columns we need to parse by reading the file
287+
# header
288+
# 2. Import data using genfromtxt numpy method, specifiying the
289+
# delimiter, skiping the header line and using only the "demes"
290+
# columns
291+
mavfile = open(self.file_path, "r")
292+
header = mavfile.readline().rstrip()
293+
mavfile.close()
294+
demes = [i for i, j in enumerate(header.split(",")) if "deme" in j]
295+
296+
self.qvals = np.genfromtxt(self.file_path, delimiter=",",
297+
skip_header=1, usecols=demes)
295298

296299
if self.get_indv:
297300
self.indv = list(np.genfromtxt(self.file_path, delimiter=",",

0 commit comments

Comments
 (0)