-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #12 from CCBR/docs-updates
Add module docstrings
- Loading branch information
Showing
20 changed files
with
172 additions
and
69 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
""" | ||
GSEA tools | ||
Modules: | ||
- `ccbr_tools.GSEA.deg2gs` | ||
- `ccbr_tools.GSEA.multitext2excel` | ||
- `ccbr_tools.GSEA.ncbr_huse` | ||
""" |
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 |
---|---|---|
@@ -1,20 +1,18 @@ | ||
#!/usr/bin/env python3 | ||
# -*- coding: utf-8 -*- | ||
""" | ||
multitext2excel.py | ||
Reads a list of files to import as separate tabs in Excel | ||
Created on Mon Aug 6 14:59:13 2018 | ||
Susan Huse | ||
NIAID Center for Biological Research | ||
Frederick National Laboratory for Cancer Research | ||
Leidos Biomedical | ||
multitext2excel.py | ||
Reads a list of files to import as separate tabs in Excel | ||
v 1.0 - initial code version. | ||
v 1.1 - updated to include first splitter [email protected] | ||
""" | ||
|
||
__author__ = "Susan Huse" | ||
__date__ = "August 6, 2018" | ||
__version__ = "1.1" | ||
|
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,5 @@ | ||
""" | ||
ccbr_tools package. | ||
Utilities for CCBR Bioinformatics Software | ||
""" |
Empty file.
Empty file.
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,3 @@ | ||
""" | ||
hf or HomologFinder finds homologs in human and mouse. | ||
""" |
Empty file.
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,9 @@ | ||
""" | ||
Helpers for bioinformatics pipelines | ||
Modules: | ||
- `ccbr_tools.pipeline.cache` | ||
- `ccbr_tools.pipeline.hpc` | ||
- `ccbr_tools.pipeline.nextflow` | ||
- `ccbr_tools.pipeline.util` | ||
""" |
Empty file.
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
Empty file.
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
Empty file.
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,51 @@ | ||
""" | ||
Template files for CCBR Tools. | ||
Templates: | ||
- `ccbr_tools.templates.submit_slurm.sh` | ||
""" | ||
|
||
import importlib.resources | ||
|
||
|
||
def read_template(template_name): | ||
""" | ||
Read a template file | ||
Args: | ||
template_name (str): Name of the template file | ||
Returns: | ||
template (str): Contents of the template file | ||
""" | ||
|
||
template_files = importlib.resources.files(__package__) | ||
template_path = template_files / template_name | ||
with open(template_path, "rt") as template_file: | ||
return template_file.read() | ||
|
||
|
||
def use_template(template_name, output_filepath=None, **kwargs): | ||
""" | ||
Uses a template, formats variables, and writes it to a file. | ||
Args: | ||
template_name (str): The name of the template to use. | ||
output_filepath (str, optional): The filepath to save the output file. If not provided, it will be written to `template_name` in the current working directory. | ||
**kwargs: Keyword arguments to fill in the template variables. | ||
Returns: | ||
None | ||
Raises: | ||
FileNotFoundError: If the template file is not found. | ||
IOError: If there is an error writing the output file. | ||
Examples: | ||
use_template("submit_slurm.sh", output_filepath="./submit_slurm.sh", PIPELINE="CCBR_nxf", MODULES="ccbrpipeliner nextflow", ENV_VARS="", RUN_COMMAND="nextflow run main.nf -stub") | ||
""" | ||
template_str = read_template(template_name) | ||
if not output_filepath: | ||
output_filepath = template_name | ||
with open(output_filepath, "wt") as outfile: | ||
outfile.write(template_str.format(**kwargs)) |
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 |
---|---|---|
@@ -1,11 +1,5 @@ | ||
from ccbr_tools.pkg_util import read_template | ||
from ccbr_tools.pkg_util import repo_base | ||
|
||
|
||
def test_read_template(): | ||
template_str = read_template("submit_slurm.sh") | ||
assert all( | ||
[ | ||
template_str.startswith("#!/usr/bin/env bash"), | ||
template_str.endswith("{RUN_COMMAND}\n"), | ||
] | ||
) | ||
def test_repo_base(): | ||
assert str(repo_base()).endswith("ccbr_tools") |
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,67 @@ | ||
import os | ||
import pathlib | ||
import pytest | ||
import tempfile | ||
|
||
from ccbr_tools.templates import read_template, use_template | ||
|
||
|
||
def test_read_template(): | ||
template_str = read_template("submit_slurm.sh") | ||
assert all( | ||
[ | ||
template_str.startswith("#!/usr/bin/env bash"), | ||
template_str.endswith("{RUN_COMMAND}\n"), | ||
] | ||
) | ||
|
||
|
||
def test_use_template(): | ||
with tempfile.TemporaryDirectory() as tmp_dir: | ||
out_filepath = pathlib.Path(tmp_dir) / "test.sh" | ||
use_template( | ||
"submit_slurm.sh", | ||
output_filepath=out_filepath, | ||
PIPELINE="CCBR_nxf", | ||
MODULES="ccbrpipeliner nextflow", | ||
ENV_VARS="export HELLO=WORLD", | ||
RUN_COMMAND="nextflow run main.nf -stub", | ||
) | ||
with open(out_filepath, "r") as outfile: | ||
template_str = outfile.read() | ||
assertions = [ | ||
'#SBATCH -J "CCBR_nxf"' in template_str, | ||
"module load ccbrpipeliner nextflow" in template_str, | ||
"export HELLO=WORLD" in template_str, | ||
"nextflow run main.nf -stub" in template_str, | ||
] | ||
assert all(assertions) | ||
|
||
|
||
def test_use_template_defaults(): | ||
with tempfile.TemporaryDirectory() as tmp_dir: | ||
current_wd = os.getcwd() | ||
tmp_wd = pathlib.Path(current_wd) / tmp_dir | ||
os.chdir(tmp_wd) | ||
use_template( | ||
"submit_slurm.sh", | ||
PIPELINE="CCBR_nxf", | ||
MODULES="ccbrpipeliner nextflow", | ||
ENV_VARS="export HELLO=WORLD", | ||
RUN_COMMAND="nextflow run main.nf -stub", | ||
) | ||
os.chdir(current_wd) | ||
template_file = pathlib.Path(tmp_wd) / "submit_slurm.sh" | ||
assertions = [template_file.is_file()] | ||
assert all(assertions) | ||
|
||
|
||
def test_use_template_blanks(): | ||
with tempfile.TemporaryDirectory() as tmp_dir: | ||
out_filepath = pathlib.Path(tmp_dir) / "test.sh" | ||
with pytest.raises(KeyError) as exc_info: | ||
use_template( | ||
"submit_slurm.sh", | ||
output_filepath=out_filepath, | ||
) | ||
assert str(exc_info.value) == "KeyError: 'MODULES'" |