def write_ctl(name, imap, guidetree, nloci,<EOL>infer_sptree, infer_delimit, delimit_alg,<EOL>seed, burnin, nsample, sampfreq,<EOL>thetaprior, tauprior, traits_df, nu0, kappa0,<EOL>cleandata, useseqdata, usetraitdata, wdir,<EOL>finetune, verbose):
<EOL>ctl = []<EOL>if not guidetree.endswith("<STR_LIT:;>"):<EOL><INDENT>guidetree += "<STR_LIT:;>"<EOL><DEDENT>prog = '<STR_LIT>'<EOL>if isinstance(traits_df, pd.DataFrame):<EOL><INDENT>prog = '<STR_LIT>'<EOL><DEDENT>ctl.append("<STR_LIT>".format(seed))<EOL>ctl.append("<STR_LIT>".format(OPJ(wdir, name), prog))<EOL>ctl.append("<STR_LIT>".format(OPJ(wdir, name), prog))<EOL>ctl.append("<STR_LIT>".format(OPJ(wdir, name), prog))<EOL>ctl.append("<STR_LIT>".format(OPJ(wdir, name), prog))<EOL>if isinstance(traits_df, pd.DataFrame):<EOL><INDENT>ctl.append("<STR_LIT>".format(OPJ(wdir, name), prog))<EOL><DEDENT>ctl.append("<STR_LIT>".format(nloci))<EOL>ctl.append("<STR_LIT>".format(useseqdata))<EOL>ctl.append("<STR_LIT>".format(cleandata))<EOL>if infer_sptree:<EOL><INDENT>ctl.append("<STR_LIT>")<EOL><DEDENT>else:<EOL><INDENT>ctl.append("<STR_LIT>")<EOL><DEDENT>ctl.append("<STR_LIT>".format(infer_delimit, delimit_alg[<NUM_LIT:0>],<EOL>"<STR_LIT:U+0020>".join([str(i) for i in delimit_alg[<NUM_LIT:1>:]])))<EOL>if isinstance(traits_df, pd.DataFrame):<EOL><INDENT>try:<EOL><INDENT>traits_df.values.astype(float)<EOL><DEDENT>except Exception:<EOL><INDENT>raise IPyradWarningExit(PDREAD_ERROR)<EOL><DEDENT>samples = sorted(list(itertools.chain(*imap.values())))<EOL>didx = [list(traits_df.index).index(i) for i in traits_df.indexif i not in samples]<EOL>dtraits = traits_df.drop(traits_df.index[didx])<EOL>straits = dtraits.apply(lambda x: (x - x.mean()) / (x.std()))<EOL>ftraits = straits.fillna("<STR_LIT>")<EOL>traitdict = ftraits.T.to_dict("<STR_LIT:list>")<EOL>rev = {val:key for key in sorted(imap) for val in imap[key]}<EOL>traitfile = "<STR_LIT>".format(os.path.join(wdir, name), prog)<EOL>with open(traitfile, '<STR_LIT:w>') as tout:<EOL><INDENT>tout.write("<STR_LIT>")<EOL>tout.write("<STR_LIT:\t>".join(<EOL>['<STR_LIT>'] + list(ftraits.columns))+"<STR_LIT:\n>"<EOL>)<EOL>nindT = <NUM_LIT:0><EOL>for ikey in sorted(imap.keys()):<EOL><INDENT>samps = imap[ikey]<EOL>for samp in sorted(samps):<EOL><INDENT>if samp in traitdict:<EOL><INDENT>tout.write("<STR_LIT:\t>".join([samp, rev[samp]] +[str(i) for i in traitdict[samp]])+"<STR_LIT:\n>"<EOL>)<EOL>nindT += <NUM_LIT:1><EOL><DEDENT><DEDENT><DEDENT><DEDENT>ctl.append("<STR_LIT>".format(traits_df.shape[<NUM_LIT:1>]))<EOL>ctl.append("<STR_LIT>".format(nindT))  <EOL>ctl.append("<STR_LIT>".format(usetraitdata))<EOL>ctl.append("<STR_LIT>".format(useseqdata))<EOL>ctl.append("<STR_LIT>".format(nu0))<EOL>ctl.append("<STR_LIT>".format(kappa0))<EOL>ctl.remove("<STR_LIT>".format(useseqdata))<EOL>ctl.remove("<STR_LIT>".format(infer_sptree))<EOL><DEDENT>nspecies = str(len(imap))<EOL>species = "<STR_LIT:U+0020>".join(sorted(imap))<EOL>ninds = "<STR_LIT:U+0020>".join([str(len(imap[i])) for i in sorted(imap)])<EOL>ctl.append("""<STR_LIT>""".format(nspecies, species, ninds, guidetree))<EOL>ctl.append("<STR_LIT>".format(*thetaprior))<EOL>ctl.append("<STR_LIT>".format(*tauprior))<EOL>ctl.append("<STR_LIT>".format("<STR_LIT:U+0020>".join([str(i) for i in finetune])))<EOL>ctl.append("<STR_LIT>")<EOL>ctl.append("<STR_LIT>".format(burnin))<EOL>ctl.append("<STR_LIT>".format(sampfreq))<EOL>ctl.append("<STR_LIT>".format(nsample))<EOL>with open("<STR_LIT>".format(OPJ(wdir, name), prog), '<STR_LIT:w>') as out:<EOL><INDENT>out.write("<STR_LIT:\n>".join(ctl))<EOL><DEDENT>if verbose:<EOL><INDENT>sys.stderr.write("<STR_LIT>"+"<STR_LIT:\n>".join(ctl)+"<STR_LIT>")<EOL><DEDENT>
write outfile with any args in argdict