Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
73 commits
Select commit Hold shift + click to select a range
d731ae2
added placeholder files
ctrlaltaf Feb 20, 2024
99bf632
Draft: btb
ctrlaltaf Feb 29, 2024
725eeb0
goes through snakemake process without any errors
ctrlaltaf Mar 8, 2024
5534087
Added new test files
ctrlaltaf Apr 3, 2024
d289f2f
LN testing complete
gabeah Jun 5, 2024
0fe3c2a
dockerfile is made!
gabeah Jun 5, 2024
fc3ba80
working on LN implementation
gabeah Jun 6, 2024
fe47da5
dealing with some errors
gabeah Jun 7, 2024
f887fca
Step 4 completed
gabeah Jun 7, 2024
877707c
stuck on modifying generate inputs and parse outputs
gabeah Jun 7, 2024
8dfa330
finished?
gabeah Jun 10, 2024
dbaacf1
finished changes as defined in code review
gabeah Jun 11, 2024
1caca3a
added files for BTB PR
gabeah Jun 21, 2024
a59e281
working on btb pr
gabeah Jun 21, 2024
7c46104
continual testing for btb
gabeah Jun 24, 2024
e182c89
continual testing for btb
gabeah Jun 24, 2024
12369a4
prepping for PR
gabeah Jun 24, 2024
ddde72b
conflicts fixed?
gabeah Jun 24, 2024
64b8783
Merge branch 'ctrlaltaf-btb' into btb
gabeah Jun 24, 2024
01aa15f
passing two tests, need to pass two more
gabeah Jun 25, 2024
740cfb7
losing me mind over pytest :)
gabeah Jun 26, 2024
f82b611
three tests passinggit add .
gabeah Jun 28, 2024
dbf81a0
continuing finishing test functions for PR
gabeah Jul 1, 2024
d0822bb
oops, forgot some extra files
gabeah Jul 1, 2024
7d10dbb
wrapping finished?
gabeah Jul 3, 2024
c3310fe
wrapping finished
gabeah Jul 3, 2024
f3d4006
updated dockerfile/config to reflect new repo/dockerhub images
gabeah Jul 8, 2024
40ad34f
beginning PR fixes
gabeah Jul 9, 2024
3b9d70e
PR changes finished/comments have been made
gabeah Jul 9, 2024
027ecbd
small fixes, preparing to merge main and resolve conflicts
gabeah Jul 11, 2024
e149f0e
Merge branch 'master' into btb
gabeah Jul 11, 2024
6261724
Merge branch 'master' into pr/168
oliverfanderson Nov 18, 2024
6399eb8
Got BTB integrated with SPRAS workflow
oliverfanderson Nov 19, 2024
f114b9b
Add further integration and test cases for BTB
oliverfanderson Nov 20, 2024
9050eb6
fix one typo
oliverfanderson Nov 20, 2024
272430b
Update test-spras.yml
oliverfanderson Dec 4, 2024
2816d09
Update README.md
oliverfanderson Feb 5, 2025
980d201
Merge branch 'master' into btb-merge
oliverfanderson Feb 6, 2025
b6e833f
Add test cases
oliverfanderson Feb 6, 2025
204ce44
Update test_btb.py
oliverfanderson Feb 6, 2025
156ec9b
Update btb.py
oliverfanderson Feb 6, 2025
6746f03
BTB pytests and snakemake working
oliverfanderson Feb 7, 2025
0b1f26a
Change expected outputs of generate_inputs and parse_outputs
oliverfanderson Feb 7, 2025
8095f34
Update expected output
oliverfanderson Feb 7, 2025
c1d1f8e
Update expected outputs of parse_output
oliverfanderson Feb 7, 2025
a1882b5
Comment out failing format_error test
oliverfanderson Feb 7, 2025
47840a3
Fix files with outdated cases
oliverfanderson Feb 13, 2025
2468829
Delete test_btb.py
oliverfanderson Feb 13, 2025
0e1eae3
Fix capital T issue
oliverfanderson Feb 13, 2025
11417b3
Restored lost LocalNeighborhood files
oliverfanderson Mar 18, 2025
69cdd38
Merge branch 'master' into btb-merge
oliverfanderson Mar 18, 2025
b165dfe
Create bowtiebuilder-raw-pathway.txt
oliverfanderson Mar 18, 2025
4deebb9
Update btb.py
oliverfanderson Mar 18, 2025
2eb8361
Update btb.py
oliverfanderson Mar 18, 2025
a42c793
fix: re-add ln, fix ci, style
tristan-f-r Jun 3, 2025
2534838
fix: raise correct error
tristan-f-r Jun 3, 2025
3433bc9
fix: convert undirected to directed graph
tristan-f-r Jun 3, 2025
2a197e6
style: fmt
tristan-f-r Jun 3, 2025
22fee13
fix: correct interactome import
tristan-f-r Jun 4, 2025
ad93d63
style: fmt
tristan-f-r Jun 4, 2025
e117a93
test(btb): re-add directed graph to btb
tristan-f-r Jun 4, 2025
ef19cc9
ci: drop odd ci hack
tristan-f-r Jun 4, 2025
7bae862
Merge branch 'Reed-CompBio:master' into tr-btb
tristan-f-r Jun 4, 2025
2e29202
fix: use directed instead of undirected
tristan-f-r Jun 4, 2025
15361bb
Merge branch 'tr-btb' of https://github.com/tristan-f-r/spras into tr…
tristan-f-r Jun 4, 2025
0799bcd
test(btb): direct expecfed
tristan-f-r Jun 5, 2025
a0a446c
Merge remote-tracking branch 'upstream/main' into tr-btb
tristan-f-r Jun 13, 2025
3820968
fix: use run_container_and_log
tristan-f-r Jun 13, 2025
6f6fa1b
Merge branch 'umain' into tr-btb
tristan-f-r Jul 1, 2025
5d8ae5b
docs: on btb err
tristan-f-r Jul 1, 2025
e82d14f
fix: config
tristan-f-r Jul 1, 2025
34ca1f2
docs: mention open btb issue
tristan-f-r Jul 1, 2025
f0038d2
fix(btb): add params to parse_output
tristan-f-r Jul 1, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .github/workflows/build-containers.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,11 @@ jobs:
with:
path: docker-wrappers/DOMINO
container: reedcompbio/domino
build-and-remove-btb:
uses: "./.github/workflows/build-and-remove-template.yml"
with:
path: docker-wrappers/BowTieBuilder
container: reedcompbio/bowtiebuilder
build-and-remove-cytoscape:
uses: "./.github/workflows/build-and-remove-template.yml"
with:
Expand Down
4 changes: 4 additions & 0 deletions config/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,10 @@ algorithms:
alpha: [0.85]
threshold: [100, 200]

- name: "bowtiebuilder"
params:
include: true

# Here we specify which pathways to run and other file location information.
# DataLoader.py can currently only load a single dataset
# Assume that if a dataset label does not change, the lists of associated input files do not change
Expand Down
5 changes: 5 additions & 0 deletions docker-wrappers/BowTieBuilder/Dockerfile
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/dd8519cd8a8397c0e0724106f498b6002d3f7be2/btb.py
RUN pip install networkx==2.8
15 changes: 15 additions & 0 deletions docker-wrappers/BowTieBuilder/README.md
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
162 changes: 162 additions & 0 deletions spras/btb.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,162 @@
from pathlib import Path

from spras.containers import prepare_volume, run_container_and_log
from spras.interactome import (
convert_undirected_to_directed,
reinsert_direction_col_directed,
)
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 (BTB uses the nx.DiGraph constructor internally)
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
# TODO: This error will never actually occur if the inputs are passed through
# `generate_inputs`. See the discussion about removing this or making this a habit at
# https://github.com/Reed-CompBio/spras/issues/306.
with open(edges, 'r') as edge_file:
try:
for line in edge_file:
line = line.strip().split('\t')[2]

except Exception as err:
# catches a much harder to debug error in BTB.
raise IndexError("BTB edges are not formatted correctly") from 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]

container_suffix = "bowtiebuilder:v2"
run_container_and_log('BowTieBuilder',
container_framework,
container_suffix,
command,
volumes,
work_dir)
# Output is already written to raw-pathway.txt file


@staticmethod
def parse_output(raw_pathway_file, standardized_pathway_file, params):
"""
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
"""
# TODO: consider using 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_directed(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)
1 change: 1 addition & 0 deletions spras/runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

# supported algorithm imports
from spras.allpairs import AllPairs as allpairs
from spras.btb import BowTieBuilder as bowtiebuilder
from spras.dataset import Dataset
from spras.domino import DOMINO as domino
from spras.meo import MEO as meo
Expand Down
Empty file added test/BowTieBuilder/__init__.py
Empty file.
3 changes: 3 additions & 0 deletions test/BowTieBuilder/expected/bidirectional-output.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Node1 Node2
S1 A
A T1
5 changes: 5 additions & 0 deletions test/BowTieBuilder/expected/btb-output.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Node1 Node2
S1 A
S2 A
A T1
A T2
6 changes: 6 additions & 0 deletions test/BowTieBuilder/expected/disjoint-output.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Node1 Node2
S1 A
S2 C
C T2
A B
B T1
1 change: 1 addition & 0 deletions test/BowTieBuilder/expected/empty-output.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Node1 Node2
6 changes: 6 additions & 0 deletions test/BowTieBuilder/expected/loop-output.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Node1 Node2
S1 A
A B
B T1
T1 C
C T2
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Node1 Node2
S1 A
S1 S2
S2 B
A T1
B T2
4 changes: 4 additions & 0 deletions test/BowTieBuilder/expected/source-to-source-output.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Node1 Node2
S1 A
A T1
A T2
5 changes: 5 additions & 0 deletions test/BowTieBuilder/expected/source-to-source2-output.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Node1 Node2
S1 A
S2 S1
A T1
A T2
3 changes: 3 additions & 0 deletions test/BowTieBuilder/expected/weighted-output.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Node1 Node2
S1 A
A T1
6 changes: 6 additions & 0 deletions test/BowTieBuilder/input/bad-edges.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
A D 5
B D 1.3
C 0.4
D E 4.5
D F 2
D G 3.2
4 changes: 4 additions & 0 deletions test/BowTieBuilder/input/bidirectional-edges.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
S1 A 1
A T1 1
A S1 1
T1 A 1
Empty file.
5 changes: 5 additions & 0 deletions test/BowTieBuilder/input/btb-edges.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
S1 A 1
S1 S2 1
S2 A 1
A T1 1
A T2 1
2 changes: 2 additions & 0 deletions test/BowTieBuilder/input/btb-sources.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
S1
S2
2 changes: 2 additions & 0 deletions test/BowTieBuilder/input/btb-targets.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
T1
T2
5 changes: 5 additions & 0 deletions test/BowTieBuilder/input/disjoint-edges.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
S1 A 1
A B 1
B T1 1
S2 C 1
C T2 1
3 changes: 3 additions & 0 deletions test/BowTieBuilder/input/disjoint-sources.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
S1
S2
S3
3 changes: 3 additions & 0 deletions test/BowTieBuilder/input/disjoint-targets.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
T1
T2
T3
6 changes: 6 additions & 0 deletions test/BowTieBuilder/input/disjoint2-edges.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
S1 A 1
A B 1
B T1 1
S2 C 1
C T2 1
S3 D 1
6 changes: 6 additions & 0 deletions test/BowTieBuilder/input/edges1.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
A D 5
B D 1.3
C D 0.4
D E 4.5
D F 2
D G 3.2
6 changes: 6 additions & 0 deletions test/BowTieBuilder/input/loop-edges.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
S1 A 1
A B 1
B T1 1
T1 C 1
C T2 1
T2 S1 1
5 changes: 5 additions & 0 deletions test/BowTieBuilder/input/source-to-source-disjoint-edges.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
S1 S2 1
S1 A 1
A T1 1
S2 B 1
B T2 1
4 changes: 4 additions & 0 deletions test/BowTieBuilder/input/source-to-source-edges.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
S1 A 1
S1 S2 1
A T1 1
A T2 1
4 changes: 4 additions & 0 deletions test/BowTieBuilder/input/source-to-source2-edges.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
S1 A 1
S2 S1 1
A T1 1
A T2 1
3 changes: 3 additions & 0 deletions test/BowTieBuilder/input/source1.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
A
B
C
2 changes: 2 additions & 0 deletions test/BowTieBuilder/input/target-to-source-edges.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
A S1 1
T1 A 1
3 changes: 3 additions & 0 deletions test/BowTieBuilder/input/target1.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
E
F
G
4 changes: 4 additions & 0 deletions test/BowTieBuilder/input/weight-one-edges.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
S1 A 1
A T1 1
S1 B 0.5
B T1 0.5
4 changes: 4 additions & 0 deletions test/BowTieBuilder/input/weighted-edges.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
S1 A 0.9
A T1 0.9
S1 B 0.5
B T1 0.5
Loading
Loading