Skip to content

Commit

Permalink
Merge pull request #81 from faridrashidi/develop
Browse files Browse the repository at this point in the history
release v0.0.19
  • Loading branch information
faridrashidi authored Oct 18, 2021
2 parents 99535af + e9afde6 commit 6f69784
Show file tree
Hide file tree
Showing 44 changed files with 611 additions and 504 deletions.
2 changes: 1 addition & 1 deletion .bumpversion.cfg
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[bumpversion]
current_version = 0.0.18
current_version = 0.0.19
commit = True
message = [skip ci] {current_version} → {new_version}
tag = False
Expand Down
1 change: 1 addition & 0 deletions .github/ISSUE_TEMPLATE/bug_report.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ assignees: ''
```python
...
```

### Traceback
<!-- If applicable, replace `...` with an error traceback below -->
<details>
Expand Down
9 changes: 9 additions & 0 deletions docs/source/references.bib
Original file line number Diff line number Diff line change
Expand Up @@ -474,3 +474,12 @@ @article{Bourque
title = {{The Bourque distances for mutation trees of cancers}},
journal = {Algorithms for Molecular Biology}
}
@article{GRMT,
doi = {10.3389/fgene.2021.692964},
year = 2021,
month = jun,
publisher = {Frontiers Media {SA}},
volume = {12},
author = {Zhenhua Yu and Huidong Liu and Fang Du and Xiaofen Tang},
title = {{{GRMT}: Generative Reconstruction of Mutation Tree From Scratch Using Single-Cell Sequencing Data}}
}
10 changes: 10 additions & 0 deletions docs/source/release_notes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,16 @@ Release Notes
=============


Version 0.0.19 :small:`October 18, 2021`
----------------------------------------

This version includes:

- Add GRMT and SPhyR as new solvers.
- Update the consensus to new algorithm.
- Fix some bugs.


Version 0.0.18 :small:`October 13, 2021`
----------------------------------------

Expand Down
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,5 @@ pyyaml
scikit_learn
scipy
seaborn
termcolor
tqdm
20 changes: 20 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,23 @@ ignore =
C400, # C400 Unnecessary generator - rewrite as a list comprehension
[tool:pytest]
filterwarnings = ignore::DeprecationWarning
[coverage:run]
omit =
./trisicell/external/*
# unfinished
./trisicell/tl/solver/_cardelino.py
./trisicell/tl/solver/_cellphy.py
./trisicell/tl/solver/_dendro.py
./trisicell/tl/solver/_gpps.py
./trisicell/tl/solver/_grmt.py
./trisicell/tl/solver/_sasc.py
./trisicell/tl/solver/_sbm.py
./trisicell/tl/solver/_scelestial.py
./trisicell/tl/solver/_siclonefit.py
./trisicell/tl/solver/_sphyr.py
./trisicell/commands/_grmt.py
./trisicell/commands/_sphyr.py
# gurobi
./trisicell/pp/_bifiltering.py
# r
./trisicell/tl/cna/_cna.py
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
__author__ = ", ".join(["Farid Rashidi"])
__maintainer__ = ", ".join(["Farid Rashidi"])
__email__ = ", ".join(["[email protected]"])
__version__ = "0.0.18"
__version__ = "0.0.19"

if platform == "linux" or platform == "linux2":
os.environ["CC"] = "g++"
Expand Down
3 changes: 1 addition & 2 deletions tests/test_datasets.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ def test_simulate_2(self):
assert not tsc.ul.is_conflict_free_gusfield(df_noisy)

def test_load_datasets(self):
# TODO: complete
adata = tsc.datasets.example()
assert adata.shape == (83, 452)
adata = tsc.datasets.test()
Expand All @@ -47,7 +46,7 @@ def test_load_datasets(self):
adata = tsc.datasets.erbc()
assert adata.shape == (47, 40)
adata = tsc.datasets.high_grade_serous_ovarian_cancer_3celllines()
assert adata.shape == (891, 13666)
assert adata.shape == (891, 14068)
adata = tsc.datasets.melanoma20()
assert adata.shape == (20, 2367)
adata = tsc.datasets.muscle_invasive_bladder()
Expand Down
11 changes: 11 additions & 0 deletions tests/test_io.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import trisicell as tsc


class TestIO:
def test_read_newick(self):
f1 = tsc.ul.get_file("trisicell.datasets/test/T00.nwk")
f2 = tsc.ul.get_file("trisicell.datasets/test/T06.nwk")
df1 = tsc.io.read(f1)
df2 = tsc.io.read(f2)
assert df1.shape == (185, 368)
assert df2.shape == (185, 368)
File renamed without changes.
4 changes: 4 additions & 0 deletions tests/test_preprocessing.py → tests/test_pp.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,7 @@ def test_readcount(self):
tsc.pp.filter_mut_mutant_must_present_in_at_least(adata, min_cells=2)
tsc.pp.statistics(adata)
assert adata.shape == (83, 267)
tsc.pp.group_obs_apply_func(adata, group_key="group")
tsc.pp.remove_cell_by_list(adata, ["C15_1"])
tsc.pp.keep_cell_by_list(adata, ["C15_2", "C15_3"])
assert adata.shape == (2, 267)
12 changes: 4 additions & 8 deletions tests/test_consensus.py → tests/test_tl_consensus.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def test_consensus_1(self):
sc1 = tsc.io.read(f1)
sc2 = tsc.io.read(f2)
final_tree = tsc.tl.consensus(sc1, sc2)
assert len(final_tree.nodes) == 18
assert len(final_tree.nodes) == 19

def test_consensus_2(self):
# result in recomb.fig1c
Expand All @@ -31,7 +31,7 @@ def test_consensus_3(self):
sc1 = tsc.io.read(f1)
sc2 = tsc.io.read(f2)
final_tree = tsc.tl.consensus(sc1, sc2)
assert len(final_tree.nodes) == 33
assert len(final_tree.nodes) == 34

def test_consensus_4(self):
# result in biorxiv.fig3f
Expand All @@ -54,9 +54,7 @@ def test_consensus_day_1(self):
sc2 = tsc.io.read(f2)
tris_tree = tsc.tl.consensus(sc1, sc2)
day_tree = tsc.tl.consensus_day(sc1, sc2)
assert not nx.is_isomorphic(
tris_tree, day_tree
) # because of nonoverlapping mutations
assert nx.is_isomorphic(tris_tree, day_tree)

def test_consensus_day_2(self):
# result in recomb.fig1c
Expand All @@ -76,9 +74,7 @@ def test_consensus_day_3(self):
sc2 = tsc.io.read(f2)
tris_tree = tsc.tl.consensus(sc1, sc2)
day_tree = tsc.tl.consensus_day(sc1, sc2)
assert not nx.is_isomorphic(
tris_tree, day_tree
) # because of nonoverlapping mutations in private of C21
assert nx.is_isomorphic(tris_tree, day_tree)

def test_consensus_day_4(self):
# result in biorxiv.fig3f
Expand Down
File renamed without changes.
File renamed without changes.
10 changes: 5 additions & 5 deletions tests/test_solvers.py → tests/test_tl_solvers.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,6 @@ def test_phiscsb(self):
df_out = tsc.tl.phiscsb(self.df_in, alpha=0.0000001, beta=0.1)
assert tsc.ul.is_conflict_free_gusfield(df_out)

@skip_gurobi
def test_phiscsi(self):
df_out = tsc.tl.phiscsi(self.df_in, alpha=0.0000001, beta=0.1)
assert tsc.ul.is_conflict_free_gusfield(df_out)

def test_huntress_both(self):
df_out = tsc.tl.huntress(self.df_in, alpha=0.0000001, beta=0.1, kind="both")
assert tsc.ul.is_conflict_free_gusfield(df_out)
Expand All @@ -51,6 +46,11 @@ def test_onconem(self):
is_cf = tsc.ul.is_conflict_free_gusfield(df_out)
assert is_cf

@skip_gurobi
def test_phiscsi(self):
df_out = tsc.tl.phiscsi(self.df_in, alpha=0.0000001, beta=0.1)
assert tsc.ul.is_conflict_free_gusfield(df_out)

@skip_gurobi
def test_phiscsi_bulk_1(self):
adata = tsc.datasets.acute_lymphocytic_leukemia2()
Expand Down
13 changes: 6 additions & 7 deletions tests/test_solvers_tmp.py → tests/test_tl_solvers_tmp.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@ def test_titch_algorithm(self):
tsc.tl.fitch(tree)
assert True

def test_rscistree(self):
adata = tsc.datasets.colorectal2(readcount=True)
df_out = tsc.tl.rscistree(adata, mode="haploid")
is_cf = tsc.ul.is_conflict_free_gusfield(df_out)
assert is_cf

def test_iscistree(self):
df_in = tsc.datasets.test()
df_out = tsc.tl.iscistree(df_in, alpha=0.0000001, beta=0.1)
Expand Down Expand Up @@ -59,10 +65,3 @@ def test_cardelino(self):
adata = tsc.datasets.example()
tsc.tl.cardelino(adata, mode="free", n_clones=11)
assert True

@pytest.mark.skip(reason="Cause make: *** Error!")
def test_rscistree(self):
adata = tsc.datasets.colorectal2(readcount=True)
df_out = tsc.tl.rscistree(adata, mode="haploid")
is_cf = tsc.ul.is_conflict_free_gusfield(df_out)
assert is_cf
18 changes: 18 additions & 0 deletions tests/test_utils.py → tests/test_ul.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,3 +81,21 @@ def test_cells_muts_rooted_at(self):

res = tsc.ul.muts_rooted_at(tree, "[8]")
assert res.shape[0] == 51

def test_general(self):
# tsc.ul.executable("kDPFC", "SPhyR")
file = tsc.ul.get_file("trisicell.datasets/test/fp_0-fn_0-na_0.ground.CFMatrix")
tsc.ul.dir_base(file)
tsc.ul.dirbase(file)
tsc.ul.get_param(
"simNo_2-s_7-m_20-h_1-minVAF_0.1-ISAV_0-n_10-fp_0-fn_0.1-na_0-d_0-l_1000000"
".SC"
)

@tsc.ul.timeit
def _test():
return None

_test()

assert True
2 changes: 1 addition & 1 deletion trisicell/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@
__author__ = ", ".join(["Farid Rashidi"])
__maintainer__ = ", ".join(["Farid Rashidi"])
__email__ = ", ".join(["[email protected]"])
__version__ = "0.0.18"
__version__ = "0.0.19"
__all__ = (datasets, io, logg, pl, pp, settings, tl, ul)
52 changes: 52 additions & 0 deletions trisicell/commands/_grmt.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import os

import click

import trisicell as tsc


@click.command(short_help="Run GRMT.")
@click.argument(
"genotype_file",
required=True,
type=click.Path(
exists=True, file_okay=True, dir_okay=False, readable=True, resolve_path=True
),
)
@click.argument(
"alpha",
required=True,
type=float,
)
@click.argument(
"beta",
required=True,
type=float,
)
@click.option(
"--n_threads",
"-p",
default=1,
type=int,
show_default=True,
help="Number of threads.",
)
def grmt(genotype_file, alpha, beta, n_threads):
"""GRMT.
Generative Reconstruction of Mutation Tree From Scratch Using Single-Cell
Sequencing Data :cite:`GRMT`.
trisicell grmt input.SC 0.0001 0.1
"""

outfile = os.path.splitext(genotype_file)[0]

tsc.settings.verbosity = "info"
tsc.settings.logfile = f"{outfile}.grmt.log"

df_in = tsc.io.read(genotype_file)
df_out = tsc.tl.grmt(df_in, alpha=alpha, beta=beta, n_threads=n_threads)
tsc.io.write(df_out, f"{outfile}.grmt.CFMatrix")

return None
2 changes: 1 addition & 1 deletion trisicell/commands/_phiscs.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ def phiscsb(genotype_file, alpha, beta):
default=86400,
type=int,
show_default=True,
help="Timelimit of the program (in second).",
help="Time limit of the program (in second).",
)
@click.option(
"--n_threads",
Expand Down
11 changes: 9 additions & 2 deletions trisicell/commands/_score.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,14 @@ def score(ground_file, inferred_file):
dl = tsc.tl.dl(df_g, df_s)
mltd = tsc.tl.mltd(df_g, df_s)["normalized_similarity"]
tpted = tsc.tl.tpted(df_g, df_s)

tsc.logg.info(f"AD={ad:0.4f}\nDL={dl:0.4f}\nMLTSM={mltd:0.4f}\nTPTED={tpted:0.4f}")
caset = tsc.tl.caset(df_g, df_s)
disc = tsc.tl.disc(df_g, df_s)
mp3 = tsc.tl.mp3(df_g, df_s)
rf = tsc.tl.rf(df_g, df_s)

tsc.logg.info(
f"AD={ad:0.4f}\nDL={dl:0.4f}\nMLTSM={mltd:0.4f}\nTPTED={tpted:0.4f}\n"
f"CASet={caset:0.4f}\nDISC={disc:0.4f}\nMP3={mp3:0.4f}\nRF={rf:0.4f}"
)

return None
62 changes: 62 additions & 0 deletions trisicell/commands/_sphyr.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
import os

import click

import trisicell as tsc


@click.command(short_help="Run SPhyR.")
@click.argument(
"genotype_file",
required=True,
type=click.Path(
exists=True, file_okay=True, dir_okay=False, readable=True, resolve_path=True
),
)
@click.argument(
"alpha",
required=True,
type=float,
)
@click.argument(
"beta",
required=True,
type=float,
)
@click.option(
"--n_restarts",
"-r",
default=10,
type=int,
show_default=True,
help="Number of restarts.",
)
@click.option(
"--n_threads",
"-p",
default=1,
type=int,
show_default=True,
help="Number of threads.",
)
def sphyr(genotype_file, alpha, beta, n_restarts, n_threads):
"""SPhyR.
Tumor phylogeny estimation from single-cell sequencing data under loss and error
:cite:`SPhyR`.
trisicell sphyr input.SC 0.0001 0.1
"""

outfile = os.path.splitext(genotype_file)[0]

tsc.settings.verbosity = "info"
tsc.settings.logfile = f"{outfile}.sphyr.log"

df_in = tsc.io.read(genotype_file)
df_out = tsc.tl.sphyr(
df_in, alpha=alpha, beta=beta, n_restarts=n_restarts, n_threads=n_threads
)
tsc.io.write(df_out, f"{outfile}.sphyr.CFMatrix")

return None
Loading

0 comments on commit 6f69784

Please sign in to comment.