Skip to content

Commit

Permalink
testing tweaks and format
Browse files Browse the repository at this point in the history
  • Loading branch information
willdumm committed Apr 5, 2024
1 parent 75b8fa7 commit c2d3726
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 26 deletions.
47 changes: 23 additions & 24 deletions gctree/branching_processes.py
Original file line number Diff line number Diff line change
Expand Up @@ -605,7 +605,6 @@ def my_layout(node):
"\n".join(mutations),
fsize=6,
tight_text=False,
ftype="Courier",
)
if start == 0:
T.margin_top = 6
Expand Down Expand Up @@ -1193,6 +1192,10 @@ def filter_trees( # noqa: C901
"If ranking_coeffs are provided to `filter_trees` method, a list of three values is expected."
)
coeffs = [branching_process_ranking_coeff] + list(ranking_coeffs)
if sum(abs(c) for c in coeffs) == 0:
raise ValueError(
"At least one value provided to ranking_coeffs or the value of branching_process_ranking_coeff must be nonzero."
)
else:
coeffs = [1] * 4

Expand Down Expand Up @@ -1353,31 +1356,27 @@ def reformat(field, n=10):
with open(outbase + ".forest_summary.log", "w") as fh:
independent_best = []
for dfilter, _ in dag_filters:
independent_best.append([])
if dfilter.optimal_func == max:
opt_funcs = [max, min]
else:
opt_funcs = [min, max]
for opt in opt_funcs:
tempdag = dag.copy()
opt_weight = tempdag.trim_optimal_weight(**dfilter)
independent_best[-1].append(opt_weight)
fh.write(
f"\nAmong trees with {opt.__name__} {dfilter.weight_funcs.name} of: {opt_weight}\n"
)
for indfilter, _ in dag_filters:
if indfilter.weight_funcs.name != dfilter.weight_funcs.name:
minval, maxval = tempdag.weight_range_annotate(
**indfilter.weight_funcs
)
fh.write(
f"\t{indfilter.weight_funcs.name} range: {minval} to {maxval}\n"
)
tempdag = dag.copy()
min_val, max_val = tempdag.weight_range_annotate(**dfilter)
opt_weight = tempdag.trim_optimal_weight(**dfilter)
independent_best.append(opt_weight)
fh.write(
f"\nOverall {dfilter.weight_funcs.name} range {min_val} to {max_val}."
f"\nAmong trees with {dfilter.optimal_func.__name__} {dfilter.weight_funcs.name} of: {opt_weight}\n"
)
for indfilter, _ in dag_filters:
if indfilter.weight_funcs.name != dfilter.weight_funcs.name:
minval, maxval = tempdag.weight_range_annotate(
**indfilter.weight_funcs
)
fh.write(
f"\t{indfilter.weight_funcs.name} range: {minval} to {maxval}\n"
)
print("\n", file=fh)
print_stats(
[
[
stat - best[0]
stat - best
for stat, best in zip(best_weighttuple, independent_best)
]
],
Expand Down Expand Up @@ -1405,11 +1404,11 @@ def reformat(field, n=10):
bestdf["set"] = ["best_tree"]
toplot_df = pd.concat([df, bestdf], ignore_index=True)
pplot = sns.pairplot(
toplot_df.drop(["Alleles"]),
toplot_df.drop(["Alleles"], errors="ignore"),
hue="set",
diag_kind="hist",
)
pplot.savefig(outbase + ".tree_stats.pairplot.png")
pplot.savefig(outbase + ".tree_stats.pairplot.pdf")

return (self._trimmed_self(trimdag), best_weighttuple)

Expand Down
4 changes: 2 additions & 2 deletions tests/smalltest.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ mkdir -p tests/smalltest_output
wget -O HS5F_Mutability.csv https://bitbucket.org/kleinstein/shazam/raw/ba4b30fc6791e2cfd5712e9024803c53b136e664/data-raw/HS5F_Mutability.csv
wget -O HS5F_Substitution.csv https://bitbucket.org/kleinstein/shazam/raw/ba4b30fc6791e2cfd5712e9024803c53b136e664/data-raw/HS5F_Substitution.csv

gctree infer tests/small_outfile tests/abundances.csv --outbase tests/smalltest_output/gctree.infer --root GL --frame 1 --verbose --idlabel --idmapfile tests/idmap.txt --isotype_mapfile tests/isotypemap.txt --mutability HS5F_Mutability.csv --substitution HS5F_Substitution.csv --ranking_coeffs 1 1 1 --use_old_mut_parsimony --branching_process_ranking_coeff -2
gctree infer tests/small_outfile tests/abundances.csv --outbase tests/smalltest_output/gctree.infer --root GL --frame 1 --verbose --idlabel --idmapfile tests/idmap.txt --isotype_mapfile tests/isotypemap.txt --mutability HS5F_Mutability.csv --substitution HS5F_Substitution.csv --ranking_coeffs 1 1 0 --use_old_mut_parsimony --branching_process_ranking_coeff 0

gctree infer tests/small_outfile tests/abundances.csv --outbase tests/smalltest_output/gctree.infer --root GL --frame 1 --verbose --idlabel --idmapfile tests/idmap.txt --isotype_mapfile tests/isotypemap.txt --mutability HS5F_Mutability.csv --substitution HS5F_Substitution.csv --ranking_coeffs 1 1 0 --use_old_mut_parsimony --branching_process_ranking_coeff 0
gctree infer tests/small_outfile tests/abundances.csv --outbase tests/smalltest_output/gctree.infer --root GL --frame 1 --verbose --idlabel --idmapfile tests/idmap.txt --isotype_mapfile tests/isotypemap.txt --mutability HS5F_Mutability.csv --substitution HS5F_Substitution.csv --ranking_coeffs .01 -1 0 --branching_process_ranking_coeff -1 --summarize_forest --tree_stats

gctree infer tests/small_outfile tests/abundances.csv --outbase tests/smalltest_output/gctree.infer --root GL --frame 1 --verbose --idlabel

Expand Down

0 comments on commit c2d3726

Please sign in to comment.