-
Notifications
You must be signed in to change notification settings - Fork 25
Wrapped BTB algorithm for SPRAS integration #204
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
Show all changes
54 commits
Select commit
Hold shift + click to select a range
d731ae2
added placeholder files
ctrlaltaf 99bf632
Draft: btb
ctrlaltaf 725eeb0
goes through snakemake process without any errors
ctrlaltaf 5534087
Added new test files
ctrlaltaf d289f2f
LN testing complete
gabeah 0fe3c2a
dockerfile is made!
gabeah fc3ba80
working on LN implementation
gabeah fe47da5
dealing with some errors
gabeah f887fca
Step 4 completed
gabeah 877707c
stuck on modifying generate inputs and parse outputs
gabeah 8dfa330
finished?
gabeah dbaacf1
finished changes as defined in code review
gabeah 1caca3a
added files for BTB PR
gabeah a59e281
working on btb pr
gabeah 7c46104
continual testing for btb
gabeah e182c89
continual testing for btb
gabeah 12369a4
prepping for PR
gabeah ddde72b
conflicts fixed?
gabeah 64b8783
Merge branch 'ctrlaltaf-btb' into btb
gabeah 01aa15f
passing two tests, need to pass two more
gabeah 740cfb7
losing me mind over pytest :)
gabeah f82b611
three tests passinggit add .
gabeah dbf81a0
continuing finishing test functions for PR
gabeah d0822bb
oops, forgot some extra files
gabeah 7d10dbb
wrapping finished?
gabeah c3310fe
wrapping finished
gabeah f3d4006
updated dockerfile/config to reflect new repo/dockerhub images
gabeah 40ad34f
beginning PR fixes
gabeah 3b9d70e
PR changes finished/comments have been made
gabeah 027ecbd
small fixes, preparing to merge main and resolve conflicts
gabeah e149f0e
Merge branch 'master' into btb
gabeah 6261724
Merge branch 'master' into pr/168
oliverfanderson 6399eb8
Got BTB integrated with SPRAS workflow
oliverfanderson f114b9b
Add further integration and test cases for BTB
oliverfanderson 9050eb6
fix one typo
oliverfanderson 272430b
Update test-spras.yml
oliverfanderson 2816d09
Update README.md
oliverfanderson 980d201
Merge branch 'master' into btb-merge
oliverfanderson b6e833f
Add test cases
oliverfanderson 204ce44
Update test_btb.py
oliverfanderson 156ec9b
Update btb.py
oliverfanderson 6746f03
BTB pytests and snakemake working
oliverfanderson 0b1f26a
Change expected outputs of generate_inputs and parse_outputs
oliverfanderson 8095f34
Update expected output
oliverfanderson c1d1f8e
Update expected outputs of parse_output
oliverfanderson a1882b5
Comment out failing format_error test
oliverfanderson 47840a3
Fix files with outdated cases
oliverfanderson 2468829
Delete test_btb.py
oliverfanderson 0e1eae3
Fix capital T issue
oliverfanderson 11417b3
Restored lost LocalNeighborhood files
oliverfanderson 69cdd38
Merge branch 'master' into btb-merge
oliverfanderson b165dfe
Create bowtiebuilder-raw-pathway.txt
oliverfanderson 4deebb9
Update btb.py
oliverfanderson 2eb8361
Update btb.py
oliverfanderson File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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,5 @@ | ||
| FROM python:3.8-bullseye | ||
|
|
||
| WORKDIR /btb | ||
| RUN wget https://raw.githubusercontent.com/Reed-CompBio/BowTieBuilder-Algorithm/main/btb.py | ||
| RUN pip install networkx==2.8 |
This file contains hidden or 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,15 @@ | ||
| # BowTieBuilder Docker image | ||
|
|
||
| A Docker image for [BowTieBuilder](https://github.com/Reed-CompBio/BowTieBuilder-Algorithm) that is available on [DockerHub](https://hub.docker.com/repository/docker/reedcompbio/bowtiebuilder). | ||
|
|
||
| To create the Docker image run: | ||
| ``` | ||
| docker build -t reedcompbio/bowtiebuilder:v2 -f Dockerfile . | ||
| ``` | ||
| from this directory. | ||
|
|
||
| ## Original Paper | ||
|
|
||
| The original paper for [BowTieBuilder] can be accessed here: | ||
|
|
||
| Supper, J., Spangenberg, L., Planatscher, H. et al. BowTieBuilder: modeling signal transduction pathways. BMC Syst Biol 3, 67 (2009). https://doi.org/10.1186/1752-0509-3-67 |
This file contains hidden or 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,168 @@ | ||
| # need to define a new btb class and contain the following functions | ||
| # - generate_inputs | ||
| # - run | ||
| # - parse_output | ||
|
|
||
| import warnings | ||
| from pathlib import Path | ||
|
|
||
| import pandas as pd | ||
|
|
||
| from spras.containers import prepare_volume, run_container | ||
| from spras.interactome import ( | ||
| reinsert_direction_col_undirected, | ||
| ) | ||
| from spras.prm import PRM | ||
| from spras.util import add_rank_column, duplicate_edges, raw_pathway_df | ||
|
|
||
| __all__ = ['BowTieBuilder'] | ||
|
|
||
| """ | ||
| BTB will construct a BowTie-shaped graph from the provided input file. | ||
| BTB works with directed and undirected graphs. | ||
| It generates a graph connecting multiple source nodes to multiple target nodes with the minimal number of intermediate nodes as possible. | ||
|
|
||
| Expected raw edge file format: | ||
| Interactor1 Interactor2 Weight | ||
| """ | ||
|
|
||
| class BowTieBuilder(PRM): | ||
| required_inputs = ['sources', 'targets', 'edges'] | ||
|
|
||
| #generate input taken from meo.py beacuse they have same input requirements | ||
| @staticmethod | ||
| def generate_inputs(data, filename_map): | ||
| """ | ||
| Access fields from the dataset and write the required input files | ||
| @param data: dataset | ||
| @param filename_map: a dict mapping file types in the required_inputs to the filename for that type | ||
| @return: | ||
| """ | ||
| for input_type in BowTieBuilder.required_inputs: | ||
| if input_type not in filename_map: | ||
| raise ValueError(f"{input_type} filename is missing") | ||
|
|
||
| # Get sources and write to file, repeat for targets | ||
| # Does not check whether a node is a source and a target | ||
| for node_type in ['sources', 'targets']: | ||
| nodes = data.request_node_columns([node_type]) | ||
| if nodes is None: | ||
| raise ValueError(f'No {node_type} found in the node files') | ||
|
|
||
| # TODO test whether this selection is needed, what values could the column contain that we would want to | ||
| # include or exclude? | ||
| nodes = nodes.loc[nodes[node_type]] | ||
| if(node_type == "sources"): | ||
| nodes.to_csv(filename_map["sources"], sep= '\t', index=False, columns=['NODEID'], header=False) | ||
| elif(node_type == "targets"): | ||
| nodes.to_csv(filename_map["targets"], sep= '\t', index=False, columns=['NODEID'], header=False) | ||
|
|
||
|
|
||
| # Create network file | ||
| edges = data.get_interactome() | ||
|
|
||
| # Format into directed graph | ||
| # edges = convert_undirected_to_directed(edges) | ||
|
|
||
| edges.to_csv(filename_map["edges"], sep="\t", index=False, | ||
| columns=["Interactor1", "Interactor2", "Weight"], | ||
| header=False) | ||
|
|
||
|
|
||
|
|
||
| # Skips parameter validation step | ||
| @staticmethod | ||
| def run(sources=None, targets=None, edges=None, output_file=None, container_framework="docker"): | ||
| """ | ||
| Run BTB with Docker | ||
| @param sources: input source file (required) | ||
| @param targets: input target file (required) | ||
| @param edges: input edge file (required) | ||
| @param output_file: path to the output pathway file (required) | ||
| @param container_framework: choose the container runtime framework, currently supports "docker" or "singularity" (optional) | ||
| """ | ||
|
|
||
| # Tests for pytest (docker container also runs this) | ||
| # Testing out here avoids the trouble that container errors provide | ||
|
|
||
| if not sources or not targets or not edges or not output_file: | ||
| raise ValueError('Required BowTieBuilder arguments are missing') | ||
|
|
||
| if not Path(sources).exists() or not Path(targets).exists() or not Path(edges).exists(): | ||
| raise ValueError('Missing input file') | ||
|
|
||
| # Testing for btb index errors | ||
| # It's a bit messy, but it works \_('_')_/ | ||
| with open(edges, 'r') as edge_file: | ||
| try: | ||
| for line in edge_file: | ||
| line = line.strip() | ||
| line = line.split('\t') | ||
| line = line[2] | ||
|
|
||
| except Exception as err: | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. maybe raise an |
||
| raise(err) | ||
|
|
||
| work_dir = '/btb' | ||
|
|
||
| # Each volume is a tuple (src, dest) | ||
| volumes = list() | ||
|
|
||
| bind_path, source_file = prepare_volume(sources, work_dir) | ||
| volumes.append(bind_path) | ||
|
|
||
| bind_path, target_file = prepare_volume(targets, work_dir) | ||
| volumes.append(bind_path) | ||
|
|
||
| bind_path, edges_file = prepare_volume(edges, work_dir) | ||
| volumes.append(bind_path) | ||
|
|
||
| # Use its --output argument to set the output file prefix to specify an absolute path and prefix | ||
| out_dir = Path(output_file).parent | ||
| out_dir.mkdir(parents=True, exist_ok=True) | ||
| bind_path, mapped_out_dir = prepare_volume(str(out_dir), work_dir) | ||
| volumes.append(bind_path) | ||
| mapped_out_prefix = mapped_out_dir + '/raw-pathway.txt' # Use posix path inside the container | ||
|
|
||
| command = ['python', | ||
| 'btb.py', | ||
| '--edges', | ||
| edges_file, | ||
| '--sources', | ||
| source_file, | ||
| '--targets', | ||
| target_file, | ||
| '--output_file', | ||
| mapped_out_prefix] | ||
| # command = ['ls', '-R'] | ||
|
|
||
|
|
||
| print('Running BowTieBuilder with arguments: {}'.format(' '.join(command)), flush=True) | ||
|
|
||
| container_suffix = "bowtiebuilder:v2" | ||
| out = run_container(container_framework, | ||
| container_suffix, | ||
| command, | ||
| volumes, | ||
| work_dir) | ||
| print(out) | ||
| # Output is already written to raw-pathway.txt file | ||
|
|
||
|
|
||
| @staticmethod | ||
| def parse_output(raw_pathway_file, standardized_pathway_file): | ||
| """ | ||
| Convert a predicted pathway into the universal format | ||
| @param raw_pathway_file: pathway file produced by an algorithm's run function | ||
| @param standardized_pathway_file: the same pathway written in the universal format | ||
| """ | ||
| # What about multiple raw_pathway_files | ||
| df = raw_pathway_df(raw_pathway_file, sep='\t', header=0) | ||
| if not df.empty: | ||
| df = add_rank_column(df) | ||
| df = reinsert_direction_col_undirected(df) | ||
| df.columns = ['Node1', 'Node2', 'Rank', 'Direction'] | ||
| df, has_duplicates = duplicate_edges(df) | ||
| if has_duplicates: | ||
| print(f"Duplicate edges were removed from {raw_pathway_file}") | ||
| df.to_csv(standardized_pathway_file, index=False, sep='\t', header=True) | ||
This file contains hidden or 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
Empty file.
This file contains hidden or 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,3 @@ | ||
| Node1 Node2 | ||
| S1 A | ||
| A T1 |
This file contains hidden or 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,5 @@ | ||
| Node1 Node2 | ||
| S1 A | ||
| S2 A | ||
| A T1 | ||
| A T2 |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can be colllapsed into:
_ = line.strip().split('\t')[2]instead of:
line = line.strip() line = line.split('\t') line = line[2]