Skip to content
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

Draft: BowtieBuilder status #150

Draft
wants to merge 31 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 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
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
10 changes: 10 additions & 0 deletions .github/workflows/test-spras.yml
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,16 @@ jobs:
docker pull reedcompbio/domino:latest
docker pull reedcompbio/py4cytoscape:v3
docker pull reedcompbio/spras:v0.1.0
docker pull reedcompbio/bowtiebuilder:v1
- name: Build BowtieBuilder Docker Image
uses: docker/build-push-action@v1
with:
path: docker-wrappers/BowTieBuilder
dockerfile: docker-wrappers/BowTieBuilder/Dockerfile
respository: reedcompbio/bowtiebuilder
tags: latest
cache_from: reedcompbio/bowtiebuilder:v1
push: false
- name: Build Omics Integrator 1 Docker image
uses: docker/build-push-action@v1
with:
Expand Down
5 changes: 5 additions & 0 deletions config/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,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 @@ -92,6 +93,9 @@ algorithms:
run1:
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.
Expand All @@ -116,6 +120,7 @@ datasets:
# Relative path from the spras directory
data_dir: "input"


# If we want to reconstruct then we should set run to true.
# TODO: if include is true above but run is false here, algs are not run.
# is this the behavior we want?
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:v1 -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
1 change: 0 additions & 1 deletion docker-wrappers/LocalNeighborhood/Dockerfile

This file was deleted.

44 changes: 0 additions & 44 deletions docker-wrappers/LocalNeighborhood/README.md

This file was deleted.

70 changes: 0 additions & 70 deletions docker-wrappers/LocalNeighborhood/local_neighborhood.py

This file was deleted.

174 changes: 174 additions & 0 deletions spras/btb.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,174 @@
# 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 (
convert_undirected_to_directed,
reinsert_direction_col_directed,
)

from spras.prm import PRM

__all__ = ['BowtieBuilder']

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")
print("FILEMAP NAME: ", filename_map)
print("DATA HEAD: ")
print( data.node_table.head())
print("DATA INTERACTOME: ")
print(data.interactome.head())

# 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)
print("NODES: ")
print(nodes)
elif(node_type == "targets"):
nodes.to_csv(filename_map["targets"], sep= '\t', index=False, columns=['NODEID'], header=False)
print("NODES: ")
print(nodes)


# 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, header=False)



# Skips parameter validation step
@staticmethod
def run(sources=None, targets=None, edges=None, output_file=None, container_framework="docker"):
"""
Run PathLinker 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:
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)

# PathLinker does not provide an argument to set the output directory
# Use its --output argument to set the output file prefix to specify an absolute path and prefix
out_dir = Path(output_file).parent
# PathLinker requires that the output directory exist
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,
'--target',
target_file,
'--output',
mapped_out_prefix]
# command = ['ls', '-R']


print('Running BowtieBuilder with arguments: {}'.format(' '.join(command)), flush=True)

container_suffix = "bowtiebuilder:v1"
out = run_container(container_framework,
container_suffix,
command,
volumes,
work_dir)
print(out)
print("Source file: ", source_file)
print("target file: ", target_file)
print("edges file: ", edges_file)
print("mapped out dir: ", mapped_out_dir)
print("mapped out prefix: ", mapped_out_prefix)


# Output is already written to raw-pathway.txt file
# output_edges = Path(next(out_dir.glob('out*-ranked-edges.txt')))
# output_edges.rename(output_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
print("PARSING OUTPUT BTB")
df = pd.read_csv(raw_pathway_file, sep='\t')
df = reinsert_direction_col_directed(df)
print(df)
df.to_csv(standardized_pathway_file, header=False, index=False, sep='\t')
1 change: 1 addition & 0 deletions spras/runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from spras.omicsintegrator1 import OmicsIntegrator1 as omicsintegrator1
from spras.omicsintegrator2 import OmicsIntegrator2 as omicsintegrator2
from spras.pathlinker import PathLinker as pathlinker
from spras.btb import BowtieBuilder as bowtiebuilder


def run(algorithm, params):
Expand Down
7 changes: 7 additions & 0 deletions test/BowtieBuilder/expected/output1.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Node1 Node2
A D
B D
C D
D F
D G
D E
6 changes: 6 additions & 0 deletions test/BowtieBuilder/input/edges.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/edges_bad.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
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
A
B
C
Loading