def __init__(self, name, data, workdir=None, mapfile=None): self.name = name self.data = os.path.abspath(os.path.expanduser(data)) self.mainparams = _MainParams() self.extraparams = _ExtraParams() self.clumppparams = _ClumppParams() self.asyncs = [] ## check that bpp is installed and in path for binary in ['structure']: if not subprocess.call("type " + binary, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) == 0: raise IPyradWarningExit(MISSING_IMPORTS) ## make workdir if it does not exist if workdir: self.workdir = os.path.abspath(os.path.expanduser(workdir)) else: self.workdir = OPJ(os.path.abspath('.'), "analysis-structure") if not os.path.exists(self.workdir): os.makedirs(self.workdir) ## check that strfile exists, print and parse some info from it with open(data) as ifile: lines = ifile.readlines() self.ntaxa = len(lines) // 2 self.nsites = len(lines[0].strip().split()[1:]) self.labels = [i.split('\t')[0].strip() for i in lines][::2] self.popdata = [i.split('\t')[1] for i in lines][::2] self.popflag = [i.split('\t')[2] for i in lines][::2] self.locdata = [i.split('\t')[3] for i in lines][::2] self.phenotype = [i.split('\t')[4] for i in lines][::2] #self.extra = [i.split('\t')[5] for i in lines][::2] #default extracols=0 del lines ## if mapfile then parse it to an array if mapfile: with open(mapfile) as inmap: maparr = np.genfromtxt(inmap)[:, [0, 3]].astype(np.uint64) spans = np.zeros((maparr[-1, 0], 2), np.uint64) spans = get_spans(maparr, spans) self.maparr = spans self.nsites = spans.shape[0] else: self.maparr = None
def __init__(self, name, strfile, workdir=None, mapfile=None): self.name = name self.strfile = os.path.realpath(strfile) self.mainparams = _MainParams() self.extraparams = _ExtraParams() self.clumppparams = _ClumppParams() self.asyncs = [] ## make workdir if it does not exist if workdir: self.workdir = os.path.realpath(workdir) else: self.workdir = os.path.join(os.path.curdir, "analysis-structure") if not os.path.exists(self.workdir): os.makedirs(self.workdir) ## check that strfile exists, print and parse some info from it with open(strfile) as ifile: lines = ifile.readlines() self.ntaxa = len(lines) // 2 self.nsites = len(lines[0].strip().split()[1:]) self.labels = [i.split('\t')[0].strip() for i in lines][::2] self.popdata = [i.split('\t')[1] for i in lines][::2] self.popflag = [i.split('\t')[2] for i in lines][::2] del lines ## if mapfile then parse it to an array if mapfile: with open(mapfile) as inmap: maparr = np.genfromtxt(inmap)[:, [0, 3]].astype(np.uint64) spans = np.zeros((maparr[-1, 0], 2), np.uint64) spans = get_spans(maparr, spans) self.maparr = spans self.nsites = spans.shape[0] else: self.maparr = None
def __init__(self, data, name="test", workdir="analysis-treemix", imap=None, mapfile=None, minmap=None, *args, **kwargs): ## path attributes self.name = name self.data = data self.mapfile = mapfile ## if not imap then it will be set to 1 if imap: self.imap = imap ## if not minmap then none if minmap: self.minmap = minmap ## params dict self.params = Params() self.params.k = 0 self.params.m = 0 self.params.g = (None, None) self.params.bootstrap = 0 self.params.cormig = 0 self.params.climb = 0 self.params.noss = 0 self.params.seed = np.random.randint(0, int(1e9)) self.params.root = None self.params.se = 0 self.params.global_ = 0 ## if mapfile then parse it to an array if self.mapfile: with open(self.mapfile) as inmap: maparr = np.genfromtxt(inmap)[:, [0, 3]].astype(np.uint64) spans = np.zeros((maparr[-1, 0], 2), np.uint64) spans = get_spans(maparr, spans) self.maparr = spans self.nsites = spans.shape[0] else: self.maparr = None ## make workdir if it does not exist if workdir: self.workdir = os.path.abspath(os.path.expanduser(workdir)) else: self.workdir = OPJ(os.path.curdir, "analysis-structure") if not os.path.exists(self.workdir): os.makedirs(self.workdir) ## set params notparams = set(["workdir", "name", "data", "minmap", "imap"]) for key in set(kwargs.keys()) - notparams: self.params[key] = kwargs[key] ## check binary self._get_binary() ## results files self.files = Params() self.files.cov = OPJ(self.workdir, self.name + ".cov.gz") self.files.covse = OPJ(self.workdir, self.name + ".covse.gz") self.files.edges = OPJ(self.workdir, self.name + ".edges.gz") self.files.llik = OPJ(self.workdir, self.name + ".llik") self.files.modelcov = OPJ(self.workdir, self.name + ".modelcov.gz") self.files.treeout = OPJ(self.workdir, self.name + ".treeout.gz") self.files.vertices = OPJ(self.workdir, self.name + ".vertices.gz") ## results self.results = Params() self.results.tree = "" self.results.admixture = [] self.results.cov = [] self.results.covse = [] self.results.modelcov = []