-
Notifications
You must be signed in to change notification settings - Fork 7
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 #222 from leoisl/fix_188
Uses psutil to measure RAM, add a pipeline to check the truth kmer intersection with a query and other misc changes
- Loading branch information
Showing
13 changed files
with
157 additions
and
17 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
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
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,25 @@ | ||
import time | ||
import sys | ||
from pathlib import Path | ||
|
||
log_file = Path(sys.argv[1]) | ||
log_file.parent.mkdir(parents=True, exist_ok=True) | ||
|
||
initial_RAM = None | ||
max_RAM_usage = 0 | ||
|
||
try: | ||
import psutil | ||
while True: | ||
RAM_usage = psutil.virtual_memory().used | ||
RAM_usage = RAM_usage / 1024 | ||
max_RAM_usage = max(max_RAM_usage, RAM_usage) | ||
if initial_RAM is None: | ||
initial_RAM = RAM_usage | ||
mof_search_RAM_usage = max_RAM_usage - initial_RAM | ||
with open(log_file, "w", buffering=1024) as fout: | ||
fout.write(f"{mof_search_RAM_usage:.2f}") | ||
time.sleep(0.1) | ||
except ImportError: | ||
with open(log_file, "w", buffering=1024) as fout: | ||
fout.write("N/A (psutil not installed)") |
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,10 +1,8 @@ | ||
#! /usr/bin/env python3 | ||
|
||
import argparse | ||
import collections | ||
import lzma | ||
import os | ||
import re | ||
import sys | ||
|
||
|
||
|
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,25 @@ | ||
configfile: "config.yaml" | ||
|
||
from pathlib import Path | ||
|
||
batches = [f"batch_{i:03}" for i in range(662)] | ||
assemblies_dir = Path(config["assemblies_dir"]) | ||
kmer_size = int(config["k"]) | ||
|
||
|
||
rule all: | ||
input: [f"output/{batch}.counts.txt" for batch in batches] | ||
|
||
|
||
rule count_kmers: | ||
input: | ||
assembly_batch=f"{assemblies_dir}/{{batch}}", | ||
reads=config["reads"] | ||
output: | ||
kmer_counts = "output/{batch}.counts.txt" | ||
conda: | ||
"envs/jellyfish.yaml" | ||
shadow: "shallow" | ||
params: | ||
k=kmer_size | ||
script: "scripts/count_kmers.py" |
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 @@ | ||
assemblies_dir: "/hps/nobackup/iqbal/leandro/cobs/compress_all_data/Assemblies" | ||
reads: /hps/nobackup/iqbal/leandro/cobs/mof-search/truth_pipeline/reads.fa | ||
k: 31 |
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,4 @@ | ||
channels: | ||
- bioconda | ||
dependencies: | ||
- jellyfish=2.2.10 |
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,2 @@ | ||
#!/usr/bin/env bash | ||
snakemake -j4 --use-singularity --use-conda -p |
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,33 @@ | ||
from pathlib import Path | ||
import subprocess | ||
|
||
|
||
def count_kmers(batch_dir: Path, reads_file: Path, kmer_size: int, kmer_counts_filename: Path): | ||
with open(kmer_counts_filename, "w") as kmer_counts_fh: | ||
for file in batch_dir.iterdir(): | ||
if file.name.endswith(".fa.gz"): | ||
file = file.resolve() | ||
subprocess.check_call(f"zcat {file} | jellyfish count --canonical -m {kmer_size} -s 100M -t 1 --if {reads_file} /dev/fd/0", shell=True) | ||
kmer_counts = subprocess.check_output(f"jellyfish dump mer_counts.jf", shell=True) | ||
kmer_counts = kmer_counts.decode("utf-8") | ||
kmer_counts = kmer_counts.strip().split("\n") | ||
|
||
kmer_present = 0 | ||
kmer_absent = 0 | ||
for line in kmer_counts: | ||
if line[0] == ">": | ||
line = line.strip() | ||
if line != ">0": | ||
kmer_present += 1 | ||
else: | ||
kmer_absent += 1 | ||
sample = file.name.split(".")[0] | ||
print( | ||
f"{sample} {kmer_present} {kmer_absent} {kmer_present / (kmer_present + kmer_absent)}", | ||
file=kmer_counts_fh) | ||
|
||
|
||
count_kmers(Path(snakemake.input.assembly_batch), | ||
Path(snakemake.input.reads), | ||
int(snakemake.params.k), | ||
Path(snakemake.output.kmer_counts)) |
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,18 @@ | ||
#!/usr/bin/env bash | ||
set -eux | ||
|
||
MEMORY=2000 | ||
PROFILE="lsf" | ||
LOG_DIR=logs/ | ||
JOB_NAME="snakemake_mof_search_truth_pipeline."$(date --iso-8601='minutes') | ||
|
||
mkdir -p $LOG_DIR | ||
|
||
bsub -R "select[mem>$MEMORY] rusage[mem=$MEMORY] span[hosts=1]" \ | ||
-M "$MEMORY" \ | ||
-o "$LOG_DIR"/"$JOB_NAME".o \ | ||
-e "$LOG_DIR"/"$JOB_NAME".e \ | ||
-J "$JOB_NAME" \ | ||
snakemake --profile "$PROFILE" "$@" | ||
|
||
exit 0 |