diff --git a/bin/bcr-phylo-run.py b/bin/bcr-phylo-run.py index 5ce474ee9..865757a8e 100755 --- a/bin/bcr-phylo-run.py +++ b/bin/bcr-phylo-run.py @@ -24,7 +24,6 @@ from python.event import RecombinationEvent import python.paircluster as paircluster -ete_path = os.getenv('HOME') + '/anaconda_ete/bin' bcr_phylo_path = os.getenv('PWD') + '/packages/bcr-phylo-benchmark' ig_or_tr = 'ig' @@ -212,9 +211,9 @@ def run_bcr_phylo(naive_seq, outdir, ievent, uid_str_len=None, igcr=None): cfo = None if args.n_procs == 1: - utils.run_ete_script(cmd, ete_path, dryrun=args.dry_run) + utils.run_ete_script(cmd, dryrun=args.dry_run) else: - cmd, _ = utils.run_ete_script(cmd, ete_path, return_for_cmdfos=True, tmpdir=outdir, dryrun=args.dry_run) + cmd = utils.run_ete_script(cmd, return_for_cmdfos=True, dryrun=args.dry_run) cfo = {'cmd_str' : cmd, 'workdir' : outdir, 'outfname' : bcr_phylo_fasta_fname(outdir)} sys.stdout.flush() return cfo @@ -348,7 +347,7 @@ def translate_duplicate_pids(mpair, dup_translations): kdfname, nwkfname = '%s/kd-vals.csv' % outdir, '%s/simu.nwk' % outdir if not utils.output_exists(args, kdfname, outlabel='kd/nwk conversion', offset=4): # eh, don't really need to check for both kd and nwk file, chances of only one being missing are really small, and it'll just crash when it looks for it a couple lines later cmd = './bin/read-bcr-phylo-trees.py --pickle-tree-file %s/%s_lineage_tree.p --kdfile %s --newick-tree-file %s' % (outdir, args.extrastr, kdfname, nwkfname) - utils.run_ete_script(cmd, ete_path, debug=args.n_procs==1) + utils.run_ete_script(cmd, debug=args.n_procs==1) nodefo = read_kdvals(kdfname) dtree = treeutils.get_dendro_tree(treefname=nwkfname) seqfos = utils.read_fastx(bcr_phylo_fasta_fname(outdir)) # output mutated sequences from bcr-phylo diff --git a/bin/gctree-run.py b/bin/gctree-run.py index 0482e8547..82d95cb4a 100755 --- a/bin/gctree-run.py +++ b/bin/gctree-run.py @@ -167,7 +167,8 @@ def parse_output(): def convert_pickle_tree(): assert False # doesn't work yet cmd = '%s/bin/read-bcr-phylo-trees.py --pickle-tree-file %s --newick-tree-file %s/tree.nwk' % (utils.get_partis_dir(), args.infname, args.outdir) - utils.run_ete_script(cmd, None, conda_path=args.condapath, conda_env='ete3', pyversion='3') + # assert False # this also needs updating + # utils.run_ete_script(cmd, None, conda_path=args.condapath, conda_env='ete3', pyversion='3') # ---------------------------------------------------------------------------------------- parser = argparse.ArgumentParser() diff --git a/bin/partis b/bin/partis index 356559f0e..6c428fe58 100755 --- a/bin/partis +++ b/bin/partis @@ -1380,7 +1380,6 @@ parent_args.append({'name' : '--no-partition-plots', 'kwargs' : {'action' : 'sto parent_args.append({'name' : '--only-csv-plots', 'kwargs' : {'action' : 'store_true', 'help' : 'skip writing actual image files, which can quite be slow, and only write the csv/yaml summaries (where implemented)'}}) parent_args.append({'name' : '--make-per-gene-plots', 'kwargs' : {'action' : 'store_true', 'help' : 'in addition to plots aggregating over genes, write plots displaying info for each gene of, e.g., per position shm rate, deletion frequencies'}}) parent_args.append({'name' : '--make-per-gene-per-base-plots', 'kwargs' : {'action' : 'store_true', 'help' : 'in addition to the plots made by --make-per-gene-plots, also make the per-gene, per-base plots (i.e. showing A->T vs A->G (this is quite slow, like a few seconds per gene plot).'}}) -parent_args.append({'name' : '--ete-path', 'kwargs' : {'default' : ('%s/anaconda_ete/bin' % os.getenv('HOME')) if os.getenv('HOME') is not None else None, 'help' : 'Set to the string \'None\' to turn off.'}}) parent_args.append({'name' : '--linearham-dir', 'kwargs' : {'default' : ('%s/work/linearham' % os.getenv('HOME')) if os.getenv('HOME') is not None else None, 'help' : 'path to linearham main dir (necessary if you want to use linearham without docker)'}}) parent_args.append({'name' : '--meta-info-to-emphasize', 'kwargs' : {'help' : 'Input meta info (or regular annotation) key to emphasize (highlight in red) in various plots, similar to --queries-to-include. Specify as comma-separated key-value pair, for instance \'timepoints,+8d\' would highlight all sequences with timepoint \'+8d\'. Can be any annotation key or input meta key. For now only supports one key-val pair, but in future should support colon-separated list.'}}) parent_args.append({'name' : '--meta-info-key-to-color', 'kwargs' : {'help' : 'Like --meta-info-to-emphasize, except for this key we choose a different color for each value (only in the slug/joy plots at the moment).'}}) diff --git a/bin/read-gctree-output.py b/bin/read-gctree-output.py index a99a785fe..9f7d9b1c9 100755 --- a/bin/read-gctree-output.py +++ b/bin/read-gctree-output.py @@ -113,12 +113,13 @@ def run_cmd(action): cmd += ' --min-selection-metric-cluster-size 3 --treefname %s/%s --plotdir %s --selection-metrics-to-calculate lbi:aa-lbi:cons-dist-aa:lbr:aa-lbr:lbf:aa-lbf' % (args.gctreedir, args.tree_basename, 'paired-outdir' if args.paired_loci else '%s/selection-metrics/plots'%args.outdir) cmd += ' --extra-daffy-metrics lbi:aa-lbi' cmd += ' --label-root-node' - cmd += ' --add-selection-metrics-to-outfname --use-droplet-id-for-combo-id --selection-metric-plot-cfg %s' % ':'.join(treeutils.default_plot_cfg + ['distr', 'tree-mut-stats']) + plt_cfg = treeutils.default_plot_cfg + ['distr', 'tree-mut-stats'] + if args.no_tree_plots: + plt_cfg = [t for t in plt_cfg if t != 'tree'] + cmd += ' --add-selection-metrics-to-outfname --use-droplet-id-for-combo-id --selection-metric-plot-cfg %s' % ':'.join(plt_cfg) if args.slice_bin_fname is not None: cmd += ' --slice-bin-fname %s' % args.slice_bin_fname cmd += ' --choose-all-abs --chosen-ab-fname %s/chosen-abs.csv' % args.outdir # --debug 1 - if args.no_tree_plots: - cmd += ' --ete-path None' if args.n_procs is not None: cmd += ' --n-procs %d' % args.n_procs utils.simplerun(cmd, logfname='%s/%s.log'%(args.outdir, action), dryrun=args.dry) diff --git a/bin/smetric-run.py b/bin/smetric-run.py index f5c0c8e6d..ab58f54d1 100755 --- a/bin/smetric-run.py +++ b/bin/smetric-run.py @@ -38,9 +38,8 @@ # NOTE extra required args are set in treeutils plot_tree_metrics() args.cluster_indices = utils.get_arg_list(args.cluster_indices, intify_with_ranges=True) args.selection_metric_plot_cfg = utils.get_arg_list(args.selection_metric_plot_cfg, choices=treeutils.all_plot_cfg) -ete_path, workdir = None, None +workdir = None, None if args.make_tree_plots or 'tree' in args.selection_metric_plot_cfg: - ete_path = '%s/anaconda_ete/bin' % os.getenv('HOME') workdir = utils.choose_random_subdir('/tmp/%s/tree-metrics' % os.getenv('USER')) if args.n_max_queries != -1: @@ -56,8 +55,8 @@ if args.metric_method == 'dtr': raise Exception('I think the [new] first arg here (metrics_to_calc) isn\'t right, but don\'t want to test cause i don\'t care about dtr') treeutils.add_smetrics(args, ['lbi', 'lbr', 'dtr'], None, args.lb_tau, base_plotdir=args.base_plotdir, - train_dtr=args.action=='train', dtr_cfg=args.dtr_cfg, true_lines_to_use=true_lines, ete_path=ete_path, workdir=workdir) # NOTE if you need this in the future you may want to add tree_inference_method 'gctree' and tree_inference_outdir + train_dtr=args.action=='train', dtr_cfg=args.dtr_cfg, true_lines_to_use=true_lines, workdir=workdir) # NOTE if you need this in the future you may want to add tree_inference_method 'gctree' and tree_inference_outdir else: treeutils.calculate_individual_tree_metrics(args.metric_method, true_lines, base_plotdir=args.base_plotdir, lb_tau=args.lb_tau, only_csv=args.only_csv_plots, min_cluster_size=args.min_selection_metric_cluster_size, include_relative_affy_plots=args.include_relative_affy_plots, - dont_normalize_lbi=args.dont_normalize_lbi, ete_path=ete_path, workdir=workdir, cluster_indices=args.cluster_indices, only_look_upwards=args.only_look_upwards, args=args) #, debug=True) + dont_normalize_lbi=args.dont_normalize_lbi, workdir=workdir, cluster_indices=args.cluster_indices, only_look_upwards=args.only_look_upwards, args=args) #, debug=True) diff --git a/python/lbplotting.py b/python/lbplotting.py index 4ae63f833..cd2ceace4 100644 --- a/python/lbplotting.py +++ b/python/lbplotting.py @@ -1544,7 +1544,7 @@ def ctypetitle(ct): add_fn(fnames, fn=fn) # ---------------------------------------------------------------------------------------- -def get_lb_tree_cmd(treestr, outfname, lb_metric, affy_key, ete_path, subworkdir, metafo=None, tree_style=None, queries_to_include=None, label_all_nodes=False, label_leaf_nodes=False, label_root_node=False, seq_len=None, +def get_lb_tree_cmd(treestr, outfname, lb_metric, affy_key, subworkdir, metafo=None, tree_style=None, queries_to_include=None, label_all_nodes=False, label_leaf_nodes=False, label_root_node=False, seq_len=None, meta_info_key_to_color=None, meta_info_to_emphasize=None, node_size_key=None, branch_color_key=None, uid_translations=None, node_label_regex=None): treefname = '%s/tree.nwk' % subworkdir metafname = '%s/meta.yaml' % subworkdir @@ -1586,12 +1586,12 @@ def get_lb_tree_cmd(treestr, outfname, lb_metric, affy_key, ete_path, subworkdir cmdstr += ' --branch-color-key %s' % branch_color_key if node_label_regex is not None: cmdstr += ' --node-label-regex %s' % node_label_regex - cmdstr, _ = utils.run_ete_script(cmdstr, ete_path, return_for_cmdfos=True, tmpdir=subworkdir, extra_str=' ') + cmdstr = utils.run_ete_script(cmdstr, return_for_cmdfos=True, extra_str=' ') return {'cmd_str' : cmdstr, 'workdir' : subworkdir, 'outfname' : outfname, 'workfnames' : [treefname, metafname]} # ---------------------------------------------------------------------------------------- -def plot_lb_trees(args, metric_methods, baseplotdir, lines, ete_path, base_workdir, is_true_line=False, tree_style=None, fnames=None): +def plot_lb_trees(args, metric_methods, baseplotdir, lines, base_workdir, is_true_line=False, tree_style=None, fnames=None): add_fn(fnames, new_row=True) workdir = '%s/ete3-plots' % base_workdir plotdir = baseplotdir + '/trees' @@ -1614,7 +1614,7 @@ def plot_lb_trees(args, metric_methods, baseplotdir, lines, ete_path, base_workd if affy_key in line: # either 'affinities' or 'relative_affinities' metafo[utils.reversed_input_metafile_keys[affy_key]] = {uid : affy for uid, affy in zip(line['unique_ids'], line[affy_key])} outfname = '%s/%s-tree-iclust-%d%s.svg' % (plotdir, lb_metric, iclust, '-relative' if 'relative' in affy_key else '') - cmdfos += [get_lb_tree_cmd(treestr, outfname, lb_metric, affy_key, ete_path, '%s/sub-%d' % (workdir, len(cmdfos)), metafo=metafo, tree_style=tree_style, queries_to_include=qtis, + cmdfos += [get_lb_tree_cmd(treestr, outfname, lb_metric, affy_key, '%s/sub-%d' % (workdir, len(cmdfos)), metafo=metafo, tree_style=tree_style, queries_to_include=qtis, label_all_nodes=args.label_tree_nodes, label_leaf_nodes=args.label_leaf_nodes, label_root_node=args.label_root_node, uid_translations=altids, node_label_regex=args.node_label_regex, seq_len=float(numpy.mean([len(s) for s in line['seqs']])))] add_fn(fnames, fn=outfname, n_per_row=4) diff --git a/python/partitiondriver.py b/python/partitiondriver.py index fc24ba71a..e5da142cb 100644 --- a/python/partitiondriver.py +++ b/python/partitiondriver.py @@ -390,7 +390,7 @@ def calc_tree_metrics(self, annotation_dict, annotation_list=None, cpath=None): print(' --seed-unique-id: restricting selection metric calculation to seed cluster in best partition (mostly to avoid fasttree crash on duplicate uids)') annotation_dict = OrderedDict([(uidstr, line) for uidstr, line in annotation_dict.items() if self.args.seed_unique_id in line['unique_ids'] and line['unique_ids'] in cpath.partitions[cpath.i_best]]) treeutils.add_smetrics(self.args, self.args.selection_metrics_to_calculate, annotation_dict, self.args.lb_tau, reco_info=self.reco_info, # NOTE keys in may be out of sync with 'unique_ids' if we add inferred ancestral seqs here - use_true_clusters=self.reco_info is not None, base_plotdir=self.args.plotdir, ete_path=self.args.ete_path, workdir=self.args.workdir, + use_true_clusters=self.reco_info is not None, base_plotdir=self.args.plotdir, workdir=self.args.workdir, outfname=self.args.selection_metric_fname, glfo=self.glfo, tree_inference_outdir=self.args.tree_inference_outdir, debug=self.args.debug) # ---------------------------------------------------------------------------------------- diff --git a/python/partitionplotter.py b/python/partitionplotter.py index 386ecf53c..059e8e4ef 100644 --- a/python/partitionplotter.py +++ b/python/partitionplotter.py @@ -798,7 +798,7 @@ def vmuts(vclass_muts, mutfo, uid): qtis = None if self.args.queries_to_include is None else [q for q in self.args.queries_to_include if q in annotation['unique_ids']] # NOTE make sure to *not* modify args.queries_to_include altids = [(u, au) for u, au in zip(annotation['unique_ids'], annotation['alternate-uids']) if au is not None] if 'alternate-uids' in annotation else None mfo, cdr3fo = get_metafo(annotation, iclust) - cfo = lbplotting.get_lb_tree_cmd(self.get_treestr(iclust), '%s/%s.svg'%(plotdir, plotname), None, None, self.args.ete_path, '%s/sub-%d'%(workdir, len(cmdfos)), metafo=mfo, + cfo = lbplotting.get_lb_tree_cmd(self.get_treestr(iclust), '%s/%s.svg'%(plotdir, plotname), None, None, '%s/sub-%d'%(workdir, len(cmdfos)), metafo=mfo, queries_to_include=qtis, meta_info_key_to_color=self.args.meta_info_key_to_color, meta_info_to_emphasize=self.args.meta_info_to_emphasize, uid_translations=altids, label_all_nodes=self.args.label_tree_nodes, label_leaf_nodes=self.args.label_leaf_nodes, label_root_node=self.args.label_root_node, node_size_key=self.args.node_size_key, branch_color_key=self.args.branch_color_key, node_label_regex=self.args.node_label_regex) cmdfos.append(cfo) diff --git a/python/processargs.py b/python/processargs.py index 25f5d6a24..f9f26f4ee 100644 --- a/python/processargs.py +++ b/python/processargs.py @@ -583,6 +583,3 @@ def process_corr_values(cvals, estr=''): raise Exception('have to specify --sw-cachefname or --parameter-dir, since we need sw info to calculate linearham inputs') if args.extra_annotation_columns is None or 'linearham-info' not in args.extra_annotation_columns: args.extra_annotation_columns = utils.add_lists(args.extra_annotation_columns, ['linearham-info']) - - if args.ete_path is not None and args.ete_path == 'None': # it's nice to be able to unset this from the command line (so we don't make the slow tree plots) - args.ete_path = None diff --git a/python/treeutils.py b/python/treeutils.py index af72ed2a3..13f9b3755 100644 --- a/python/treeutils.py +++ b/python/treeutils.py @@ -2214,7 +2214,7 @@ def get_tree_metric_lines(annotations, reco_info, use_true_clusters, inf_partiti return inf_lines_to_use, true_lines_to_use # ---------------------------------------------------------------------------------------- -def plot_tree_metrics(args, plotdir, metrics_to_calc, antn_list, is_simu=False, inf_annotations=None, ete_path=None, workdir=None, include_relative_affy_plots=False, queries_to_include=None, +def plot_tree_metrics(args, plotdir, metrics_to_calc, antn_list, is_simu=False, inf_annotations=None, workdir=None, include_relative_affy_plots=False, queries_to_include=None, paired=False, debug=False): reqd_args = [('selection_metric_plot_cfg', None), ('slice_bin_fname', None), ('queries_to_include', None), ('label_tree_nodes', False), ('label_leaf_nodes', False), ('label_root_node', False), ('affinity_key', None), ('sub_plotdir', None), ('tree_inference_method', None), ('node_label_regex', None)] @@ -2291,8 +2291,8 @@ def plot_tree_metrics(args, plotdir, metrics_to_calc, antn_list, is_simu=False, if 'lb-scatter' in plot_cfg: for xv, yv in [(xv, yv) for xv, yv in [('cons-dist-aa', 'aa-lbi'), ('aa-lbi', 'lbi')] if xv in metrics_to_calc and yv in metrics_to_calc]: lbplotting.make_lb_scatter_plots(xv, plotdir, yv, antn_list, fnames=fnames, is_true_line=is_simu, colorvar='affinity' if has_affinities and 'cons-dist' in xv else None, add_jitter='cons-dist' in xv, n_iclust_plot_fnames=None if has_affinities else 8, queries_to_include=args.queries_to_include, meta_info_to_emphasize=args.meta_info_to_emphasize, meta_emph_formats=args.meta_emph_formats) #, add_stats='correlation') - if ete_path is not None and has_trees and 'tree' in plot_cfg: - lbplotting.plot_lb_trees(args, metrics_to_calc, plotdir, antn_list, ete_path, workdir, is_true_line=is_simu, fnames=fnames) + if has_trees and 'tree' in plot_cfg: + lbplotting.plot_lb_trees(args, metrics_to_calc, plotdir, antn_list, workdir, is_true_line=is_simu, fnames=fnames) subdirs = [d for d in os.listdir(plotdir) if os.path.isdir(plotdir + '/' + d)] plotting.make_html(plotdir, fnames=fnames, new_table_each_row=True, htmlfname=plotdir + '/overview.html', extra_links=[(subd, '%s/' % subd) for subd in subdirs], bgcolor='#FFFFFF', title='all plots:') @@ -2492,7 +2492,7 @@ def get_aa_lb_metrics(line, nuc_dtree, lb_tau, dont_normalize_lbi=False, extra_s # by default, gets smetrics for all # if inf_partition is set (and use_true_clusters isn't), we only calculate tree metrics on those clusters def add_smetrics(args, metrics_to_calc, annotations, lb_tau, inf_partition=None, reco_info=None, use_true_clusters=False, base_plotdir=None, - train_dtr=False, dtr_cfg=None, ete_path=None, workdir=None, true_lines_to_use=None, outfname=None, glfo=None, tree_inference_outdir=None, debug=False): + train_dtr=False, dtr_cfg=None, workdir=None, true_lines_to_use=None, outfname=None, glfo=None, tree_inference_outdir=None, debug=False): min_cluster_size = args.min_selection_metric_cluster_size # default_min_selection_metric_cluster_size smdbgstr = ' getting selection metrics (%s)' % ' '.join(metrics_to_calc) if reco_info is not None: @@ -2621,7 +2621,6 @@ def add_smetrics(args, metrics_to_calc, annotations, lb_tau, inf_partition=None, # elif base_plotdir is not None: # assert true_lines_to_use is not None # plstart = time.time() - # assert ete_path is None or workdir is not None # need the workdir to make the ete trees # import plotting # import lbplotting # # if 'affinities' not in annotations[0] or all(affy is None for affy in annotations[0]['affinities']): # if it's bcr-phylo simulation we should have affinities for everybody, otherwise for nobody @@ -2641,8 +2640,7 @@ def add_smetrics(args, metrics_to_calc, annotations, lb_tau, inf_partition=None, # plotting.make_html(true_plotdir, fnames=fnames, extra_links=[(subd, '%s/%s/' % (true_plotdir, subd)) for subd in lbmlist]) # print ' dtr plotting time %.1fs' % (time.time() - plstart) elif base_plotdir is not None: - assert ete_path is None or workdir is not None # need the workdir to make the ete trees - plot_tree_metrics(args, '%s/%s-tree-metrics' % (base_plotdir, plstr), metrics_to_calc, antn_list, is_simu=is_simu, inf_annotations=inf_annotations, ete_path=ete_path, workdir=workdir, debug=debug) + plot_tree_metrics(args, '%s/%s-tree-metrics' % (base_plotdir, plstr), metrics_to_calc, antn_list, is_simu=is_simu, inf_annotations=inf_annotations, workdir=workdir, debug=debug) if outfname is not None: print(' writing selection metrics to %s' % outfname) @@ -2804,7 +2802,7 @@ def get_delta_affinity_vals(): # 3) doesn't plot as many things # 4) only runs on simulation (as opposed to making two sets of things, for simulation and data) # and yes, it would be really *#(!$ing nice to merge them but I haven't had the time yet -def calculate_individual_tree_metrics(metric_method, annotations, base_plotdir=None, ete_path=None, workdir=None, lb_tau=None, only_csv=False, min_cluster_size=None, include_relative_affy_plots=False, +def calculate_individual_tree_metrics(metric_method, annotations, base_plotdir=None, workdir=None, lb_tau=None, only_csv=False, min_cluster_size=None, include_relative_affy_plots=False, dont_normalize_lbi=False, cluster_indices=None, only_look_upwards=False, args=None, debug=False): # ---------------------------------------------------------------------------------------- def get_combo_lbfo(varlist, iclust, line, lb_tau, is_aa_lb=False): #, add_to_line=False): @@ -2902,9 +2900,8 @@ def mcombine(uid): print(' tree quantity calculation/prediction time: %.1fs' % (time.time() - pstart)) if base_plotdir is not None: - assert ete_path is None or workdir is not None # need the workdir to make the ete trees plstr, is_simu, inf_annotations = 'true', True, None - plot_tree_metrics(args, '%s/%s-tree-metrics' % (base_plotdir, plstr), [metric_method], metric_antns, is_simu=is_simu, inf_annotations=inf_annotations, ete_path=ete_path, workdir=workdir, debug=debug) + plot_tree_metrics(args, '%s/%s-tree-metrics' % (base_plotdir, plstr), [metric_method], metric_antns, is_simu=is_simu, inf_annotations=inf_annotations, workdir=workdir, debug=debug) # ---------------------------------------------------------------------------------------- def run_laplacian_spectra(treestr, workdir=None, plotdir=None, plotname=None, title=None, debug=False): @@ -3584,7 +3581,7 @@ def nstr(c, aa=False): icl_mfos = choose_abs(metric_pairs, iclust, mtpys[iclust], tdbg=debug) all_chosen_mfos[iclust] = icl_mfos inf_lines, true_lines = (None, fake_pntns) if not args.is_data else (utils.get_annotation_dict(fake_pntns), None) - add_smetrics(args, args.selection_metrics_to_calculate, inf_lines, args.lb_tau, true_lines_to_use=true_lines, base_plotdir=plotdir, ete_path=args.ete_path, # NOTE keys in may be out of sync with 'unique_ids' if we add inferred ancestral seqs here + add_smetrics(args, args.selection_metrics_to_calculate, inf_lines, args.lb_tau, true_lines_to_use=true_lines, base_plotdir=plotdir, # NOTE keys in may be out of sync with 'unique_ids' if we add inferred ancestral seqs here tree_inference_outdir=tree_inference_outdir, workdir=args.workdir, outfname=args.selection_metric_fname, debug=args.debug or args.debug_paired_clustering) if inf_lines is not None: # re-synchronize keys in the dict with 'unique_ids' in the lines, in case we added inferred ancestral seqs while getting selection metrics) diff --git a/python/utils.py b/python/utils.py index 6e0e0edc1..5a42edaa0 100644 --- a/python/utils.py +++ b/python/utils.py @@ -4879,33 +4879,24 @@ def run_r(cmdlines, workdir, dryrun=False, print_time=None, extra_str='', logfna # ---------------------------------------------------------------------------------------- def mamba_cmds(env, only_prep=False): - cmds = ['eval "$(micromamba shell hook --shell bash)"'] + cmds = ['export PYTHONNOUSERSITE=1'] # make sure it doesn't use packages from local environment + cmds += ['eval "$(micromamba shell hook --shell bash)"'] if only_prep: return cmds cmds += ['micromamba activate %s'%env] return cmds # ---------------------------------------------------------------------------------------- -def run_ete_script(sub_cmd, ete_path, conda_path=None, conda_env=None, pyversion='', return_for_cmdfos=False, tmpdir=None, dryrun=False, extra_str='', debug=True): # ete3 requires its own python version, so we run as a subprocess +def run_ete_script(sub_cmd, return_for_cmdfos=False, dryrun=False, extra_str='', debug=True): prof_cmds = '' #' -m cProfile -s tottime -o prof.out' # xvfb_err_str = '' # '-e %s' % XXX outdir + '/xvfb-err' # tell xvfb-run to write its error to this file (rather than its default of /dev/null). This is only errors actually from xvfb-run, e.g. xauth stuff is broken - if tmpdir is None: - tmpdir = choose_random_subdir('/tmp/xvfb-run', make_dir=True) - cmd = 'export TMPDIR=%s' % tmpdir - if conda_path is None: - cmd += ' && export PATH=%s:$PATH' % ete_path - else: - assert conda_env is not None # specify both conda_path and conda_env - cmd += ' && . %s/etc/profile.d/conda.sh && conda activate %s' % (conda_path, conda_env) - cmd += ' && %s/bin/xvfb-run -a python%s%s %s' % (get_partis_dir(), pyversion, prof_cmds, sub_cmd) + cmd = '%s/bin/xvfb-run -a python3%s %s' % (get_partis_dir(), prof_cmds, sub_cmd) if debug or dryrun: - itmp = cmd.rfind('&&') - print('%s%s %s' % (extra_str, color('red', 'run'), '%s \\\n%s %s' % (cmd[:itmp + 2], extra_str, cmd[itmp + 2:]))) + print('%s%s %s' % (extra_str, color('red', 'run'), cmd)) if return_for_cmdfos: - return cmd, tmpdir + return cmd else: simplerun(cmd, shell=True, dryrun=dryrun, debug=False) - os.rmdir(tmpdir) # ---------------------------------------------------------------------------------------- def simplerun(cmd_str, shell=False, cmdfname=None, dryrun=False, return_out_err=False, print_time=None, extra_str='', logfname=None, debug=True): diff --git a/test/cf-germline-inference.py b/test/cf-germline-inference.py index 9f66db7df..ab0a5da24 100755 --- a/test/cf-germline-inference.py +++ b/test/cf-germline-inference.py @@ -197,7 +197,7 @@ def make_gls_tree_plot(args, region, plotdir, plotname, glsfnames, glslabels, lo cmdstr += ' --use-cache' if args.only_print: cmdstr += ' --only-print' - utils.run_ete_script(cmdstr, args.ete_path, debug=args.dryrun, dryrun=args.dryrun, extra_str=' ') + utils.run_ete_script(cmdstr, debug=args.dryrun, dryrun=args.dryrun, extra_str=' ') # ---------------------------------------------------------------------------------------- def print_gls_gen_summary_table(args, region, baseoutdir): @@ -871,7 +871,6 @@ def run_tests(args, baseoutdir, method): parser.add_argument('--check', action='store_true') parser.add_argument('--dryrun', action='store_true') parser.add_argument('--label', default='xxx') -parser.add_argument('--ete-path', default=os.getenv('HOME') + '/anaconda_ete/bin') args = parser.parse_args() args.methods = sorted(utils.get_arg_list(args.methods)) diff --git a/test/cf-tree-metrics.py b/test/cf-tree-metrics.py index eeb763624..7308fd276 100755 --- a/test/cf-tree-metrics.py +++ b/test/cf-tree-metrics.py @@ -116,7 +116,7 @@ def calc_lb_bounds(args, n_max_gen_to_plot=4, lbt_bounds=(0.001, 0.005), print_r for btype in btypes: if lbvals[metric][btype]['vals'] is None: continue - cmdfos = [lbplotting.get_lb_tree_cmd(lbvals[metric][btype]['vals']['tree'], '%s/%s-%s-tree.svg' % (plotdir, metric, btype), metric, 'affinities', args.ete_path, args.workdir, metafo=lbvals[metric][btype]['vals'], tree_style='circular')] + cmdfos = [lbplotting.get_lb_tree_cmd(lbvals[metric][btype]['vals']['tree'], '%s/%s-%s-tree.svg' % (plotdir, metric, btype), metric, 'affinities', args.workdir, metafo=lbvals[metric][btype]['vals'], tree_style='circular')] utils.run_cmds(cmdfos, clean_on_success=True, shell=True, debug='print') if args.make_plots: @@ -293,6 +293,7 @@ def get_tree_metrics(args): # cmd += ' --seed %s' % args.random_seed # NOTE second/commented version this is actually wrong: vstrs[varnames.index('seed')] # there isn't actually a reason for different seeds here (we want the different seeds when running bcr-phylo), but oh well, maybe it's a little clearer this way # cmd += ' --selection-metrics-to-calculate lbi:lbr' # TODO it would be better to just always use smetric-run.py, which you can do now, but i don't want to break backwards compatibility # if args.no_tree_plots: + # assert False # needs to be updated to modify plot cfg arg # cmd += ' --ete-path None' # # if args.n_sub_procs > 1: # TODO get-tree-metrics doesn't paralellize anything atm # # cmd += ' --n-procs %d' % args.n_sub_procs @@ -390,7 +391,7 @@ def get_tree_metrics(args): parser.add_argument('--extra-plotstr', default='', help='if set, put plots resulting from \'get-tree-metrics\' into a separate subdir using this string, rather than just plots/ (e.g. for plotting with many different dtr versions)') parser.add_argument('--include-relative-affy-plots', action='store_true') parser.add_argument('--only-csv-plots', action='store_true', help='only write csv/yaml versions of plots (for future parsing), and not the actual svg files (which is slow)') -parser.add_argument('--no-tree-plots', action='store_true', help='don\'t make any of the tree plots, which are slow (this just sets --ete-path to None)') +parser.add_argument('--no-tree-plots', action='store_true', help='don\'t make any of the tree plots, which are slow') parser.add_argument('--overwrite', action='store_true') # not really propagated to everything I think parser.add_argument('--debug', action='store_true') parser.add_argument('--dry', action='store_true') @@ -401,7 +402,6 @@ def get_tree_metrics(args): parser.add_argument('--legend-var', help='non-default "component" variable (e.g. obs-frac) to use to label different lines in the legend') parser.add_argument('--x-legend-var', help='derived variable with which to label the x axis (e.g. mfreq [shm percent] when --final-plot-x-var is scratch-mute-freq)') parser.add_argument('--partis-dir', default=os.getcwd(), help='path to main partis install dir') -parser.add_argument('--ete-path', default=('%s/anaconda_ete/bin' % os.getenv('HOME')) if os.getenv('HOME') is not None else None) parser.add_argument('--make-hist-plots', action='store_true') # specific to get-lb-bounds: parser.add_argument('--n-tau-lengths-list', help='set either this or --n-generations-list')