Skip to content

Commit

Permalink
Merge pull request #190 from tleonardi/release_v1.0.4
Browse files Browse the repository at this point in the history
Release v1.0.4
  • Loading branch information
tleonardi authored May 27, 2021
2 parents 62a8bf4 + 05c1b28 commit 20c0b53
Show file tree
Hide file tree
Showing 8 changed files with 72 additions and 38 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
# Changelog


## v1.0.4

### Fixed
- Fixed logging levels and verbosity of log messages

## v1.0.3

### Fixed
Expand Down
5 changes: 5 additions & 0 deletions nanocompore/Eventalign_collapse.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,12 +106,17 @@ def __call__(self):
for tb in iter(error_q.get, None):
logger.trace("Error caught from error_q")
raise NanocomporeError(tb)
logger.debug("Caught poison pill in error queue")

# Soft processes and queues stopping
logger.debug("Joining all processes")
for ps in ps_list:
ps.join()
logger.debug("All processes were joined")
logger.debug("Closing all queues")
for q in (in_q, out_q, error_q):
q.close()
logger.debug("All queues were closed")

# Catch error, kill all processed and reraise error
except Exception as E:
Expand Down
8 changes: 7 additions & 1 deletion nanocompore/SampComp.py
Original file line number Diff line number Diff line change
Expand Up @@ -217,14 +217,20 @@ def __call__(self):

# Monitor error queue
for tb in iter(error_q.get, None):
logger.trace("Error caught from error_q")
logger.debug("Error caught from error_q")
raise NanocomporeError(tb)
logger.debug("Error queue was closed")

# Soft processes and queues stopping
logger.debug("Waiting for all processes to be joined")
for ps in ps_list:
ps.join()
logger.debug("All processes joined successfully")

logger.debug("Closing all queues")
for q in (in_q, out_q, error_q):
q.close()
logger.debug("All queues were closed")

# Return database wrapper object
return SampCompDB(
Expand Down
69 changes: 39 additions & 30 deletions nanocompore/Whitelist.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,33 +173,45 @@ def __read_eventalign_index(self,
col_names = fp.readline().rstrip().split()
c = Counter()
for line in fp:
try:
# Transform line to dict and cast str numbers to actual numbers
read = numeric_cast_dict(keys=col_names, values=line.rstrip().split("\t"))

# Filter out ref_id if a select_ref_id list or exclude_ref_id list was provided
if select_ref_id and not read["ref_id"] in select_ref_id:
raise NanocomporeError("Ref_id not in select list")
elif exclude_ref_id and read["ref_id"] in exclude_ref_id:
raise NanocomporeError("Ref_id in exclude list")

# Filter out reads with high number of invalid kmers if information available
if self.__filter_invalid_kmers:
if max_invalid_kmers_freq:
invalid_kmers_freq = (read["NNNNN_kmers"]+read["mismatch_kmers"]+read["missing_kmers"])/read["kmers"]
if invalid_kmers_freq > max_invalid_kmers_freq:
raise NanocomporeError("High fraction of invalid kmers ({}%) for read {}".format(round(invalid_kmers_freq*100,2), read["read_id"]))
else:
NNNNN_kmers_freq = read["NNNNN_kmers"]/read["kmers"]
max_mismatching_freq = read["mismatch_kmers"]/read["kmers"]
max_missing_freq = read["missing_kmers"]/read["kmers"]
if NNNNN_kmers_freq > max_NNNNN_freq:
raise NanocomporeError("High fraction of NNNNN kmers ({}%) for read {}".format(round(NNNNN_kmers_freq*100,2), read["read_id"]))
elif max_mismatching_freq > max_mismatching_freq:
raise NanocomporeError("High fraction of mismatching kmers ({}%) for read {}".format(round(max_mismatching_freq*100,2), read["read_id"]))
elif max_missing_freq > max_missing_freq:
raise NanocomporeError("High fraction of missing kmers ({}%) for read {}".format(round(max_missing_freq*100,2), read["read_id"]))

# Transform line to dict and cast str numbers to actual numbers
read = numeric_cast_dict(keys=col_names, values=line.rstrip().split("\t"))
read_is_valid = True
# Filter out ref_id if a select_ref_id list or exclude_ref_id list was provided
if select_ref_id and not read["ref_id"] in select_ref_id:
read_is_valid = False
c["Ref_id not in select list"]+=1
logger.trace("Ref_id not in select list")
elif exclude_ref_id and read["ref_id"] in exclude_ref_id:
read_is_valid = False
c["Ref_id in exclude list"]+=1
logger.trace("Ref_id in exclude list")

# Filter out reads with high number of invalid kmers if information available
if self.__filter_invalid_kmers:
if max_invalid_kmers_freq:
invalid_kmers_freq = (read["NNNNN_kmers"]+read["mismatch_kmers"]+read["missing_kmers"])/read["kmers"]
if invalid_kmers_freq > max_invalid_kmers_freq:
read_is_valid = False
c["High fraction of invalid kmers"]+=1
logger.trace("High fraction of invalid kmers ({}%) for read {}".format(round(invalid_kmers_freq*100,2), read["read_id"]))
else:
NNNNN_kmers_freq = read["NNNNN_kmers"]/read["kmers"]
max_mismatching_freq = read["mismatch_kmers"]/read["kmers"]
max_missing_freq = read["missing_kmers"]/read["kmers"]
if NNNNN_kmers_freq > max_NNNNN_freq:
read_is_valid = False
c["High fraction of NNNNN kmers"]+=1
logger.trace("High fraction of NNNNN kmers ({}%) for read {}".format(round(NNNNN_kmers_freq*100,2), read["read_id"]))
elif max_mismatching_freq > max_mismatching_freq:
read_is_valid = False
c["High fraction of mismatching kmers"]
logger.trace("High fraction of mismatching kmers ({}%) for read {}".format(round(max_mismatching_freq*100,2), read["read_id"]))
elif max_missing_freq > max_missing_freq:
read_is_valid = False
c["High fraction of missing kmers"]+=1
logger.trace("High fraction of missing kmers ({}%) for read {}".format(round(max_missing_freq*100,2), read["read_id"]))

if read_is_valid:
# Create dict arborescence and save valid reads
if not read["ref_id"] in ref_reads:
ref_reads[read["ref_id"]] = OrderedDict()
Expand All @@ -212,9 +224,6 @@ def __read_eventalign_index(self,
ref_reads[read["ref_id"]][cond_lab][sample_lab].append(read)
c ["valid reads"] += 1

except NanocomporeError as E:
c [str(E)] += 1

logger.debug("\tCondition:{} Sample:{} {}".format(cond_lab, sample_lab, counter_to_str(c)))
# Fill in missing condition/sample slots in case
# a ref_id is missing from one of the eventalign files
Expand Down
7 changes: 2 additions & 5 deletions nanocompore/__init__.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
# -*- coding: utf-8 -*-
# https://github.com/python-poetry/poetry/pull/2366#issuecomment-652418094
try:
import importlib.metadata as importlib_metadata
except ModuleNotFoundError:
import importlib_metadata
from nanocompore.common import get_version

__version__ = importlib_metadata.version(__name__)
__version__ = get_version()

__description__ = 'Software package that identifies raw signal changes between two conditions from https://github.com/jts/nanopolish resquiggled dRNA-Seq data.'
3 changes: 2 additions & 1 deletion nanocompore/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ def main(args=None):
sp_output.add_argument("--overwrite", "-w", action='store_true', default=False,
help="Use --outpath even if it exists already (default: %(default)s)")
sp_verbosity = sp.add_argument_group("Verbosity options")
sp_verbosity.add_argument("--log_level", type=str, default="info", choices=["warning", "info", "debug"],
sp_verbosity.add_argument("--log_level", type=str, default="info", choices=["warning", "info", "debug", "trace"],
help="Set the log level (default: %(default)s)")
sp_verbosity.add_argument("--progress", default=False, action='store_true',
help="Display a progress bar during execution (default: %(default)s)")
Expand Down Expand Up @@ -213,6 +213,7 @@ def sampcomp_main(args):
db = s()

# Save all reports
logger.info("Saving results")
if(db):
db.save_all(pvalue_thr=args.pvalue_thr)

Expand Down
11 changes: 11 additions & 0 deletions nanocompore/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

#~~~~~~~~~~~~~~IMPORTS~~~~~~~~~~~~~~#
# Standard library imports
import pkg_resources
import sys
import os
from collections import *
Expand Down Expand Up @@ -219,3 +220,13 @@ def jhelp (f:"python function or method"):

# Display in Jupyter
display (Markdown(s))

def get_version():
try:
distribution = pkg_resources.get_distribution("nanocompore")
except pkg_resources.DistributionNotFound:
return "dev" # or "", or None
# or try with importib.metadata
# or try reading pyproject.toml
else:
return distribution.version
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "nanocompore"
version = "1.0.3"
version = "1.0.4"
description = "Software package that identifies raw signal changes between two conditions from https://github.com/jts/nanopolish resquiggled dRNA-Seq data."
authors = ["Tommaso Leonardi <tom@itm6.xyz>", "Adrien Leger <aleg@ebi.ac.uk>"]
license = "GPL-3.0"
Expand Down

0 comments on commit 20c0b53

Please sign in to comment.