Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
54 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
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
149 changes: 149 additions & 0 deletions .github/workflows/test-spras.yml
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,155 @@ jobs:
shell: bash --login {0}
run: snakemake --cores 2 --configfile config/config.yaml --show-failed-logs

# Builds the Docker images
docker:
name: Build Docker images
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest]
steps:
- name: Checkout repository
uses: actions/checkout@v2
# Pull from Docker Hub to use the cache
# https://medium.com/mobileforgood/coding-tips-patterns-for-continuous-integration-with-docker-on-travis-ci-9cedb8348a62
# https://github.com/docker/build-push-action/issues/7
- name: Pull Docker images
run: |
docker pull reedcompbio/omics-integrator-1:latest
docker pull reedcompbio/omics-integrator-2:v2
docker pull reedcompbio/pathlinker:v2
docker pull reedcompbio/meo:latest
docker pull reedcompbio/mincostflow:latest
docker pull reedcompbio/allpairs:v2
docker pull reedcompbio/domino:latest
docker pull reedcompbio/py4cytoscape:v3
docker pull reedcompbio/bowtiebuilder:v2
docker pull reedcompbio/spras:v0.1.0

- name: Build Omics Integrator 1 Docker image
uses: docker/build-push-action@v1
with:
path: docker-wrappers/OmicsIntegrator1/.
dockerfile: docker-wrappers/OmicsIntegrator1/Dockerfile
repository: reedcompbio/omics-integrator-1
tags: latest
cache_froms: reedcompbio/omics-integrator-1:latest
push: false
- name: Remove Omics Integrator 1 Docker image
# Remove the image to prevent the cache from being used. Here we use
# `|| true` to prevent the job from failing if the image doesn't exist or
# can't be removed for some reason
run: docker rmi reedcompbio/omics-integrator-1:latest || true

- name: Build Omics Integrator 2 Docker image
uses: docker/build-push-action@v1
with:
path: docker-wrappers/OmicsIntegrator2/.
dockerfile: docker-wrappers/OmicsIntegrator2/Dockerfile
repository: reedcompbio/omics-integrator-2
tags: v2
cache_froms: reedcompbio/omics-integrator-2:latest
push: false
- name: Remove Omics Integrator 2 Docker image
run: docker rmi reedcompbio/omics-integrator-2:latest || true

- name: Build PathLinker Docker image
uses: docker/build-push-action@v1
with:
path: docker-wrappers/PathLinker/.
dockerfile: docker-wrappers/PathLinker/Dockerfile
repository: reedcompbio/pathlinker
tags: v2
cache_froms: reedcompbio/pathlinker:latest
push: false
- name: Remove PathLinker Docker image
run: docker rmi reedcompbio/pathlinker:latest || true

- name: Build Maximum Edge Orientation Docker image
uses: docker/build-push-action@v1
with:
path: docker-wrappers/MEO/.
dockerfile: docker-wrappers/MEO/Dockerfile
repository: reedcompbio/meo
tags: latest
cache_froms: reedcompbio/meo:latest
push: false
- name: Remove MEO Docker image
run: docker rmi reedcompbio/meo:latest || true

- name: Build MinCostFlow Docker image
uses: docker/build-push-action@v1
with:
path: docker-wrappers/MinCostFlow/.
dockerfile: docker-wrappers/MinCostFlow/Dockerfile
repository: reedcompbio/mincostflow
tags: latest
cache_froms: reedcompbio/mincostflow:latest
push: false
- name: Remove MinCostFlow Docker image
run: docker rmi reedcompbio/mincostflow:latest || true

- name: Build All Pairs Shortest Paths Docker image
uses: docker/build-push-action@v1
with:
path: docker-wrappers/AllPairs/.
dockerfile: docker-wrappers/AllPairs/Dockerfile
repository: reedcompbio/allpairs
tags: v2
cache_froms: reedcompbio/allpairs:latest
push: false
- name: Remove All Pairs Shortest Paths Docker image
run: docker rmi reedcompbio/allpairs:latest || true

- name: Build DOMINO Docker image
uses: docker/build-push-action@v1
with:
path: docker-wrappers/DOMINO/.
dockerfile: docker-wrappers/DOMINO/Dockerfile
repository: reedcompbio/domino
tags: latest
cache_froms: reedcompbio/domino:latest
push: false
- name: Remove DOMINO Docker image
run: docker rmi reedcompbio/domino:latest || true

- name: Build Cytoscape Docker image
uses: docker/build-push-action@v1
with:
path: docker-wrappers/Cytoscape/.
dockerfile: docker-wrappers/Cytoscape/Dockerfile
repository: reedcompbio/py4cytoscape
tags: v3
cache_froms: reedcompbio/py4cytoscape:v3
push: false
- name: Remove Cytoscape Docker image
run: docker rmi reedcompbio/py4cytoscape:v3 || true

- name: Build BowTieBuilder Docker Image
uses: docker/build-push-action@v1
with:
path: docker-wrappers/BowTieBuilder/.
dockerfile: docker-wrappers/BowTieBuilder/Dockerfile
repository: reedcompbio/bowtiebuilder
tags: v2
cache_froms: reedcompbio/bowtiebuilder:v2
push: false
- name: Remove BowTieBuilder Docker image
run: docker rmi reedcompbio/bowtiebuilder:v2 || true

- name: Build SPRAS Docker image
uses: docker/build-push-action@v1
with:
path: .
dockerfile: docker-wrappers/SPRAS/Dockerfile
repository: reedcompbio/spras
tags: v0.2.0
cache_froms: reedcompbio/spras:v0.2.0
push: false
- name: Remove SPRAS Docker image
run: docker rmi reedcompbio/spras:v0.2.0 || true

# Run pre-commit checks on source files
pre-commit:
name: Run pre-commit checks
Expand Down
5 changes: 5 additions & 0 deletions config/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ container_registry:
# careful: too many parameters might make your runs take a long time.

algorithms:

- name: "pathlinker"
params:
include: true
Expand Down Expand Up @@ -96,6 +97,10 @@ algorithms:
slice_threshold: [0.3]
module_threshold: [0.05]

- 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
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/main/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
168 changes: 168 additions & 0 deletions spras/btb.py
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]
Copy link
Contributor

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]


except Exception as err:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe raise an IndexError instead? can say that edge file isnt formatted correctly/etc

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)
1 change: 1 addition & 0 deletions spras/runner.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# 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
Loading
Loading