def loci2bpp(name, locifile, imap, guidetree,<EOL>minmap=None,<EOL>maxloci=None,<EOL>infer_sptree=<NUM_LIT:0>,<EOL>infer_delimit=<NUM_LIT:0>,<EOL>delimit_alg=(<NUM_LIT:0>, <NUM_LIT:5>),<EOL>seed=<NUM_LIT>,<EOL>burnin=<NUM_LIT:1000>,<EOL>nsample=<NUM_LIT>,<EOL>sampfreq=<NUM_LIT:2>,<EOL>thetaprior=(<NUM_LIT:5>, <NUM_LIT:5>),<EOL>tauprior=(<NUM_LIT:4>, <NUM_LIT:2>, <NUM_LIT:1>),<EOL>traits_df=None,<EOL>nu=<NUM_LIT:0>,<EOL>kappa=<NUM_LIT:0>,<EOL>useseqdata=<NUM_LIT:1>,<EOL>usetraitdata=<NUM_LIT:1>,<EOL>cleandata=<NUM_LIT:0>,<EOL>wdir=None,<EOL>finetune=(<NUM_LIT>, <NUM_LIT>, <NUM_LIT>, <NUM_LIT>, <NUM_LIT>, <NUM_LIT>, <NUM_LIT>, <NUM_LIT>),<EOL>verbose=<NUM_LIT:0>):
<EOL>if not imap:<EOL><INDENT>raise IPyradWarningExit(IMAP_REQUIRED)<EOL><DEDENT>if minmap:<EOL><INDENT>if minmap.keys() != imap.keys():<EOL><INDENT>raise IPyradWarningExit(KEYS_DIFFER)<EOL><DEDENT><DEDENT>if wdir:<EOL><INDENT>wdir = os.path.abspath(wdir)<EOL>if not os.path.exists(wdir):<EOL><INDENT>raise IPyradWarningExit("<STR_LIT>")<EOL><DEDENT><DEDENT>else:<EOL><INDENT>wdir = os.path.curdir<EOL><DEDENT>prog = '<STR_LIT>'<EOL>if isinstance(traits_df, pd.DataFrame):<EOL><INDENT>prog = '<STR_LIT>'<EOL><DEDENT>outfile = OPJ(wdir, "<STR_LIT>".format(name, prog))<EOL>mapfile = OPJ(wdir, "<STR_LIT>".format(name, prog))<EOL>fout = open(outfile, '<STR_LIT:w>')<EOL>fmap = open(mapfile, '<STR_LIT:w>')<EOL>with open(locifile, '<STR_LIT:r>') as infile:<EOL><INDENT>loci = infile.read().strip().split("<STR_LIT>")<EOL>nloci = len(loci)<EOL><DEDENT>samples = list(itertools.chain(*imap.values()))<EOL>nkept = <NUM_LIT:0><EOL>for iloc in xrange(nloci):<EOL><INDENT>lines = loci[iloc].split("<STR_LIT>")[<NUM_LIT:0>].split()<EOL>names = lines[::<NUM_LIT:2>]<EOL>names = ["<STR_LIT>"+i for i in names]<EOL>seqs = [list(i) for i in lines[<NUM_LIT:1>::<NUM_LIT:2>]]<EOL>seqlen = len(seqs[<NUM_LIT:0>])<EOL>skip = <NUM_LIT:0><EOL>if minmap:<EOL><INDENT>covd = {}<EOL>for group, vals in imap.items():<EOL><INDENT>covd[group] = sum(["<STR_LIT>"+i in names for i in vals])<EOL><DEDENT>if not all([covd[group] >= minmap[group] for group in minmap]):<EOL><INDENT>skip = <NUM_LIT:1><EOL><DEDENT><DEDENT>if maxloci:<EOL><INDENT>if nkept >= maxloci:<EOL><INDENT>skip = <NUM_LIT:1><EOL><DEDENT><DEDENT>if not skip:<EOL><INDENT>data = ["<STR_LIT>".format(i, "<STR_LIT>".join(k).replace("<STR_LIT:->", "<STR_LIT:N>")) for(i, k) in zip(names, seqs) if i[<NUM_LIT:1>:] in samples]<EOL>if data:<EOL><INDENT>fout.write("<STR_LIT>".format(len(data), seqlen, "<STR_LIT:\n>".join(data)))<EOL>nkept += <NUM_LIT:1><EOL><DEDENT><DEDENT><DEDENT>fout.close()<EOL>data = ["<STR_LIT>".format(val, key) for keyin sorted(imap) for val in imap[key]]<EOL>fmap.write("<STR_LIT:\n>".join(data))<EOL>fmap.close()<EOL>write_ctl(name, imap, guidetree, nkept,<EOL>infer_sptree, infer_delimit, delimit_alg,<EOL>seed, burnin, nsample, sampfreq,<EOL>thetaprior, tauprior, traits_df, nu, kappa,<EOL>cleandata, useseqdata, usetraitdata, wdir,<EOL>finetune, verbose)<EOL>sys.stderr.write("<STR_LIT>".format(nkept, len(imap.keys()),<EOL>sum([len(i) for i in imap.values()])))<EOL>sys.stderr.write("<STR_LIT>".format(name, prog))<EOL>sys.stderr.write("<STR_LIT>".format(name, prog))<EOL>sys.stderr.write("<STR_LIT>".format(name, prog))<EOL>if isinstance(traits_df, pd.DataFrame):<EOL><INDENT>sys.stderr.write("<STR_LIT>".format(name, prog))<EOL><DEDENT>return os.path.abspath(<EOL>"<STR_LIT>".format(OPJ(wdir, name), prog))<EOL>
Converts loci file format to bpp file format, i.e., concatenated phylip-like
format, and produces imap and ctl input files for bpp.

Parameters:
-----------
name:
    A prefix name for output files that will be produced
locifile:
    A .loci file produced by ipyrad.
imap:
    A Python dictionary with 'species' names as keys, and lists of sample
    names for the values. Any sample that is not included in the imap
    dictionary will be filtered out of the data when converting the .loci
    file into the bpp formatted sequence file. Each species in the imap
    dictionary must also be present in the input 'guidetree'.
guidetree:
    A newick string species tree hypothesis [e.g., (((a,b),(c,d)),e);]
    All species in the imap dictionary must also be present in the guidetree

Optional parameters:
--------------------
infer_sptree:
    Default=0, only infer parameters on a fixed species tree. If 1, then the
    input tree is treated as a guidetree and tree search is employed to find
    the best tree. The results will include support values for the inferred
    topology.
infer_delimit:
    Default=0, no delimitation. If 1 then splits in the tree that separate
    'species' will be collapsed to test whether fewer species are a better
    fit to the data than the number in the input guidetree.
delimit_alg:
    Species delimitation algorithm. This is a tuple. The first value
    is the algorithm (0 or 1) and the following values are arguments
    for the given algorithm. See other ctl files for examples of what the
    delimitation line looks like. This is where you can enter the params
    (e.g., alpha, migration) for the two different algorithms.
    For example, the following args would produce the following ctl lines:
       alg=0, epsilon=5
       > delimit_alg = (0, 5)
       speciesdelimitation = 1 0 5

       alg=1, alpha=2, migration=1
       > delimit_alg = (1, 2, 1)
       speciesdelimitation = 1 1 2 1

       alg=1, alpha=2, migration=1, diagnosis=0, ?=1
       > delimit_alg = (1, 2, 1, 0, 1)
       speciesdelimitation = 1 1 2 1 0 1
seed:
    A random number seed at start of analysis.
burnin:
    Number of burnin generations in mcmc
nsample:
    Number of mcmc generations to run.
sampfreq:
    How often to sample from the mcmc chain.
thetaprior:
    Prior on theta (4Neu), gamma distributed. mean = a/b. e.g., (5, 5)
tauprior
    Prior on root tau, gamma distributed mean = a/b. Last number is 
    dirichlet prior for other taus. e.g., (4, 2, 1)
traits_df:
    A pandas DataFrame with trait data properly formatted. This means only
    quantitative traits are included, and missing values are NaN.
    The first column contains sample names, with "Indiv" as the header.
    The following columns have a header row with trait names. This script
    will write a CSV trait file with trait values mean-standardized, with
    NaN replaced by "NA", and with sample not present in IMAP removed.
nu:
    A prior on phenotypic trait variance (0) for iBPP analysis.
kappa:
    A prior on phenotypic trait mean (0) for iBPP analysis.
useseqdata:
    If false inference proceeds without sequence data (can be used to test
    the effect of priors on the tree distributions).
usetraitdata:
    If false inference proceeds without trait data (can be used to test
    the effect of priors on the trait distributions).
cleandata:
    If 1 then sites with missing or hetero characters are removed.
wdir:
    A working directory to write files to.
finetune:
    See bpp documentation.
verbose:
    If verbose=1 the ctl file text will also be written to screen (stderr).