Skip to content

Commit

Permalink
add analysis.utils.read_popsfile function to load imap from file
Browse files Browse the repository at this point in the history
  • Loading branch information
isaacovercast committed Nov 6, 2024
1 parent 65b5b09 commit c1190f2
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions ipyrad/analysis/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,14 @@

# standard lib
import datetime
import glob
import time
import sys
import os

# third party
import numpy as np
import pandas as pd
from numba import njit, prange


Expand Down Expand Up @@ -209,6 +211,33 @@ def progressbar(finished, total, start, message):
sys.stdout.flush()


def read_popsfile(popfile):
## glob it in case of fuzzy matching
popfile = glob.glob(popfile)[0]
if not os.path.exists(popfile):
raise Exception(
"Population assignment file not found: {}"
.format(self.params.pop_assign_file))

try:
## parse populations file
popdat = pd.read_csv(
popfile, header=None,
sep=r"\s+",
names=["inds", "pops"],
comment="#",
dtype=str)

popdict = {
key: group.inds.values.tolist() for key, group in
popdat.groupby("pops")}

except (ValueError, IOError):
raise Exception(
" Populations file malformed - {}".format(popfile))

return popdict


class Params(object):
"A dict-like object for storing params values with a custom repr"
Expand Down

0 comments on commit c1190f2

Please sign in to comment.