-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
224 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
# -*- coding: utf-8 -*- | ||
""" | ||
fsnviz.fusioncatcher | ||
~~~~~~~~~~~~~~~~~~~~ | ||
FusionCatcher output plotting. | ||
:copyright: (c) 2016 Wibowo Arindrarto <[email protected]> | ||
:license: BSD | ||
""" | ||
from crimson.fusioncatcher import parse | ||
|
||
from .models import CircosEntry, CircosLabel, CircosLink, FusionToolResults | ||
from .utils import adjust_chrom | ||
|
||
|
||
__all__ = ["FusionCatcherResults"] | ||
|
||
|
||
class FusionCatcherResults(FusionToolResults): | ||
|
||
"""Class representing a FusionCatcher run result.""" | ||
|
||
mito_names = ("chrM", "M", "MT") | ||
|
||
def __init__(self, results_fname, config, tpl_params): | ||
super().__init__(results_fname, config, tpl_params) | ||
self.payload = parse(results_fname) | ||
|
||
def _make_circos_entry(self, raw_entry): | ||
left = raw_entry["5end"] | ||
right = raw_entry["3end"] | ||
if left["chromosome"] in self.mito_names: | ||
return | ||
if right["chromosome"] in self.mito_names: | ||
return | ||
lchrom = adjust_chrom(left["chromosome"]) | ||
rchrom = adjust_chrom(right["chromosome"]) | ||
|
||
link = CircosLink(lchrom, left["position"], left["position"] + 1, | ||
rchrom, right["position"], right["position"] + 1) | ||
|
||
geneA = CircosLabel(lchrom, left["position"], left["position"] + 1, | ||
left["geneSymbol"]) | ||
geneB = CircosLabel(rchrom, right["position"], right["position"] + 1, | ||
right["geneSymbol"]) | ||
|
||
njr = raw_entry["nSpanningUniqueReads"] | ||
nsf = raw_entry["nSpanningPairs"] | ||
|
||
jrA = CircosLabel(lchrom, left["position"], left["position"] + 1, | ||
njr) | ||
jrB = CircosLabel(rchrom, right["position"], right["position"] + 1, | ||
njr) | ||
|
||
sfA = CircosLabel(lchrom, left["position"], left["position"] + 1, | ||
nsf) | ||
sfB = CircosLabel(rchrom, right["position"], right["position"] + 1, | ||
nsf) | ||
|
||
return CircosEntry(link, [geneA, geneB], [jrA, jrB], [sfA, sfB]) | ||
|
||
@property | ||
def circos_entries(self): | ||
if not hasattr(self, "_circos_entries"): | ||
entries = [self._make_circos_entry(x) for x in self.payload] | ||
self._circos_entries = list(filter(None, entries)) | ||
return self._circos_entries |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
# -*- coding: utf-8 -*- | ||
""" | ||
fsnviz.tests.test_fusioncatcher | ||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
FusionCatcher subcommand tests. | ||
:copyright: (c) 2016 Wibowo Arindrarto <[email protected]> | ||
:license: BSD | ||
""" | ||
from os import path | ||
|
||
from click.testing import CliRunner | ||
|
||
from fsnviz.main import cli | ||
from .utils import get_test_path | ||
|
||
|
||
FNAME1 = get_test_path("fusioncatcher_v0995a_01.txt") | ||
|
||
|
||
def test_fusioncatcher_ok(): | ||
runner = CliRunner() | ||
with runner.isolated_filesystem(): | ||
cmd = runner.invoke(cli, ["fusioncatcher", FNAME1]) | ||
assert cmd.exit_code == 0 | ||
assert path.exists("fsnviz.svg") | ||
|
||
|
||
def test_fusioncatcher_circos_exe_fail(): | ||
runner = CliRunner() | ||
with runner.isolated_filesystem(): | ||
params = ["--circos-exe", "/nonexistent/file"] | ||
cmd = runner.invoke(cli, params + ["fusioncatcher", FNAME1]) | ||
assert cmd.exit_code != 0 | ||
assert "Could not find an executable circos at '/nonexistent/file'" \ | ||
in cmd.output | ||
assert not path.exists("fsnviz.svg") | ||
|
||
|
||
def test_fusioncatcher_out_dir_ok(): | ||
runner = CliRunner() | ||
with runner.isolated_filesystem(): | ||
out_dir = "my_dir" | ||
params = ["--out-dir", out_dir] | ||
cmd = runner.invoke(cli, params + ["fusioncatcher", FNAME1]) | ||
assert cmd.exit_code == 0 | ||
assert path.exists(path.join(out_dir, "fsnviz.svg")) | ||
assert not path.exists("fsnviz.svg") | ||
|
||
|
||
def test_fusioncatcher_base_name_ok(): | ||
runner = CliRunner() | ||
with runner.isolated_filesystem(): | ||
base_name = "my_stuff" | ||
params = ["--base-name", base_name] | ||
cmd = runner.invoke(cli, params + ["fusioncatcher", FNAME1]) | ||
assert cmd.exit_code == 0 | ||
assert path.exists("{0}.svg".format(base_name)) | ||
assert not path.exists("fsnviz.svg") | ||
|
||
|
||
def test_fusioncatcher_karyotype_ok(): | ||
runner = CliRunner() | ||
with runner.isolated_filesystem(): | ||
params = ["--karyotype", "human.hg19"] | ||
cmd = runner.invoke(cli, params + ["fusioncatcher", FNAME1]) | ||
assert cmd.exit_code == 0 | ||
assert path.exists("fsnviz.svg") | ||
|
||
|
||
def test_fusioncatcher_karyotype_png_ok(): | ||
runner = CliRunner() | ||
with runner.isolated_filesystem(): | ||
params = ["--png"] | ||
cmd = runner.invoke(cli, params + ["fusioncatcher", FNAME1]) | ||
assert cmd.exit_code == 0 | ||
assert path.exists("fsnviz.svg") | ||
assert path.exists("fsnviz.png") |