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

Added (un-used) partial string formatter.

parent 4d16fcf4
No related branches found
No related tags found
No related merge requests found
from .libworkflows import ( from .libworkflows import (
SHELL_FUNCTIONS, cleanup_and_backup, column_converter, ensure_relative, SHELL_FUNCTIONS, cleanup_and_backup, column_converter, ensure_relative,
file_len, feature_orientation2stranded, filter_combinator, get_chrom_sizes, file_len, feature_orientation2stranded, filter_combinator, get_chrom_sizes,
last_lines, make_id_list_getter, read_float_from_file, read_int_from_file, last_lines, make_id_list_getter,
partial_format,
read_float_from_file, read_int_from_file,
read_feature_counts, read_htseq_counts, read_intersect_counts, read_feature_counts, read_htseq_counts, read_intersect_counts,
save_plot, strip_split, save_plot, strip_split,
sum_by_family, sum_feature_counts, sum_htseq_counts, sum_intersect_counts, sum_by_family, sum_feature_counts, sum_htseq_counts, sum_intersect_counts,
......
...@@ -110,6 +110,22 @@ def ensure_relative(path, basedir): ...@@ -110,6 +110,22 @@ def ensure_relative(path, basedir):
return path return path
# https://stackoverflow.com/a/15728287/1878788
import string
from _string import formatter_field_name_split
class PartialFormatter(string.Formatter):
def get_field(self, field_name, args, kwargs):
try:
val = super(PartialFormatter, self).get_field(field_name, args, kwargs)
except (IndexError, KeyError, AttributeError):
first, _ = formatter_field_name_split(field_name)
val = '{' + field_name + '}', first
return val
partial_format = PartialFormatter().format
def wc_applied(source_function): def wc_applied(source_function):
""" """
This can be used as a decorator for rule input sourcing functions. This can be used as a decorator for rule input sourcing functions.
...@@ -389,6 +405,11 @@ def save_plot(outfile, ...@@ -389,6 +405,11 @@ def save_plot(outfile,
def make_id_list_getter(gene_lists_dir, avail_id_lists=None): def make_id_list_getter(gene_lists_dir, avail_id_lists=None):
"""
*gene_lists_dir* is the directory in which gene lists are located.
*avail_id_lists* can be used to restrict the set of files to use.
If not set, all files ending in "_ids.txt" will be considered.
"""
if avail_id_lists is None: if avail_id_lists is None:
avail_id_lists = set(glob(OPJ(gene_lists_dir, "*_ids.txt"))) avail_id_lists = set(glob(OPJ(gene_lists_dir, "*_ids.txt")))
str_attr_err = compile("'str' object has no attribute '.*'") str_attr_err = compile("'str' object has no attribute '.*'")
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment