Skip to content
Snippets Groups Projects
Commit 38df356d authored by Blaise Li's avatar Blaise Li
Browse files

Genome info can be loaded from separate .yaml.

parent 967df628
Branches
No related tags found
No related merge requests found
......@@ -25,6 +25,7 @@ import os
OPJ = os.path.join
from glob import glob
from subprocess import CalledProcessError
from yaml import safe_load as yload
from collections import defaultdict
from itertools import product
......@@ -53,7 +54,16 @@ from smwrappers import wrappers_dir
shell.prefix(SHELL_FUNCTIONS)
aligner = config["aligner"]
genome_dict = config["genome_dict"]
########################
# Genome configuration #
########################
# config["genome_dict"] can be either the path to a genome configuration file
# or a dict
if isinstance(config["genome_dict"], str):
with open(config["genome_dict"]) as fh:
genome_dict = yload(fh)
else:
genome_dict = config["genome_dict"]
genome = genome_dict["name"]
chrom_sizes = get_chrom_sizes(genome_dict["size"])
chrom_sizes.update(valmap(int, genome_dict.get("extra_chromosomes", {})))
......
......@@ -26,6 +26,7 @@ import os
OPJ = os.path.join
from glob import glob
from pickle import load
from yaml import safe_load as yload
import numpy as np
import pandas as pd
......@@ -87,7 +88,13 @@ alignment_settings = {
########################
# Genome configuration #
########################
genome_dict = config["genome_dict"]
# config["genome_dict"] can be either the path to a genome configuration file
# or a dict
if isinstance(config["genome_dict"], str):
with open(config["genome_dict"]) as fh:
genome_dict = yload(fh)
else:
genome_dict = config["genome_dict"]
genome = genome_dict["name"]
chrom_sizes = get_chrom_sizes(genome_dict["size"])
chrom_sizes.update(valmap(int, genome_dict.get("extra_chromosomes", {})))
......
......@@ -32,6 +32,7 @@ import os
OPJ = os.path.join
from glob import glob
from pickle import load
from yaml import safe_load as yload
from fileinput import input as finput
import warnings
......@@ -193,8 +194,16 @@ aligner = config["aligner"]
########################
# Genome configuration #
########################
genome_dict = config.get("genome_dict", None)
if genome_dict is not None:
# config["genome_dict"] can be either the path to a genome configuration file
# or a dict
if isinstance(config["genome_dict"], str):
with open(config["genome_dict"]) as fh:
genome_dict = yload(fh)
else:
genome_dict = config["genome_dict"]
# genome_dict = config.get("genome_dict", None)
# if genome_dict is not None:
if True:
genome = genome_dict["name"]
chrom_sizes = get_chrom_sizes(genome_dict["size"])
chrom_sizes.update(valmap(int, genome_dict.get("extra_chromosomes", {})))
......
......@@ -49,6 +49,7 @@ import os
OPJ = os.path.join
from glob import glob
from pickle import load
from yaml import safe_load as yload
from collections import defaultdict
from itertools import combinations
from functools import partial
......@@ -253,7 +254,13 @@ aligner = config["aligner"]
########################
# Genome configuration #
########################
genome_dict = config["genome_dict"]
# config["genome_dict"] can be either the path to a genome configuration file
# or a dict
if isinstance(config["genome_dict"], str):
with open(config["genome_dict"]) as fh:
genome_dict = yload(fh)
else:
genome_dict = config["genome_dict"]
genome = genome_dict["name"]
chrom_sizes = get_chrom_sizes(genome_dict["size"])
chrom_sizes.update(valmap(int, genome_dict.get("extra_chromosomes", {})))
......
......@@ -75,6 +75,7 @@ from glob import glob
from gzip import open as gzopen
from re import sub
from pickle import load
from yaml import safe_load as yload
from fileinput import input as finput
from shutil import copyfile
from sys import stderr
......@@ -317,7 +318,13 @@ aligner = config["aligner"]
########################
# Genome configuration #
########################
genome_dict = config["genome_dict"]
# config["genome_dict"] can be either the path to a genome configuration file
# or a dict
if isinstance(config["genome_dict"], str):
with open(config["genome_dict"]) as fh:
genome_dict = yload(fh)
else:
genome_dict = config["genome_dict"]
genome = genome_dict["name"]
genome_version = genome_dict.get("version", "WBcel235")
chrom_sizes = get_chrom_sizes(genome_dict["size"])
......@@ -1659,7 +1666,7 @@ bam2bigwig.sh: bedGraphToBigWig failed
(bedtools_v,) = re.match(r"bedtools\s+(.*)", getoutput("bedtools --version")).groups()
(bedops_v,) = re.match(r".*version:\s+(.*)\s+.*", getoutput("bedops --version | grep 'version'")).groups()
(bg2bw_v,) = re.match(r".*version:\s+([^)]+).*", getoutput("bedGraphToBigWig")).groups()
methods.write(f"# {rule}\nThe resulting alignment was used to generate a bigwig file with a custom bash script using bedtools (version {bedtools_v}), bedops (version {bedops_v}) and bedGraphToBigWig (version {bg2bw_v})\n{norm_methods}.\n")
methods.write(f"# {rule}\nThe resulting alignment was used to generate a bigwig file with a custom bash script using bedtools (version {bedtools_v}), bedops (version {bedops_v}) and bedGraphToBigWig (version {bg2bw_v}).\n{norm_methods}\n")
except CalledProcessError as e:
if last_lines(log.err, 2) == no_reads:
warn(f"{output.bigwig_norm} will be empty.\n")
......
......@@ -104,6 +104,7 @@ OPJ = os.path.join
from glob import glob
from re import sub
from pickle import load
from yaml import safe_load as yload
from fileinput import input as finput
from sys import stderr
from subprocess import Popen, PIPE, CalledProcessError
......@@ -409,7 +410,13 @@ aligner = config["aligner"]
########################
# Genome configuration #
########################
genome_dict = config["genome_dict"]
# config["genome_dict"] can be either the path to a genome configuration file
# or a dict
if isinstance(config["genome_dict"], str):
with open(config["genome_dict"]) as fh:
genome_dict = yload(fh)
else:
genome_dict = config["genome_dict"]
genome = genome_dict["name"]
chrom_sizes = get_chrom_sizes(genome_dict["size"])
chrom_sizes.update(valmap(int, genome_dict.get("extra_chromosomes", {})))
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment