Skip to content

Commit

Permalink
Merge pull request #24 from ENCODE-DCC/dev0.2.2
Browse files Browse the repository at this point in the history
Dev0.2.2
  • Loading branch information
ottojolanki committed Aug 20, 2019
2 parents 0e0a73c + 1d34a53 commit 9fbcf30
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 11 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Changelog
===========

19.08.1 (20.8.2019)
-------------------------
- `QCMetric` can now be created from a dict-like only. The parsing needs to be done separately. This is a breaking change.
- Change versioning into `CalVer <https://calver.org>`_. The format will be YY.MM.minor.
1 change: 1 addition & 0 deletions docs/changelog.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.. include:: ../CHANGELOG.rst
15 changes: 10 additions & 5 deletions docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ Getting Started
Usage
=======

The basic pattern is to create ``QCMetric`` objects, and then add related ones to a ``QCMetricRecord``. ``QCMetric`` objects can be created directly from dicts, or from files. Supported parsers are for now for samtools flagstats and for STAR log. You can also write your own: provide a function that takes a filepath as input and returns a dict.
The basic pattern is to create ``QCMetric`` objects, and then add related ones to a ``QCMetricRecord``. ``QCMetric`` objects can be created from dicts. Supported parsers are for now for samtools flagstats and for STAR log. You can also write your own: provide a function that takes a path to a file as input and returns a dict.

Examples
---------
Expand All @@ -39,8 +39,9 @@ To create from a STAR log file in ``/path/to/star_Log.out``:

from qc_utils import QCMetric, QCMetricRecord
from qc_utils.parsers import parse_starlog
starlog = parse_starlog("/path/to/star_Log.out")
record = QCMetricRecord()
log_qc_obj = QCMetric("starlogQC", "/path/to/star_Log.out", parser=parse_starlog)
log_qc_obj = QCMetric("starlogQC", starlog)
record.add(log_qc_obj)

To create from a samtools flagstats file in ``/path/to/flagstats.txt`` and write into a ``json``-object in ``/path/to/flagstats.json``:
Expand All @@ -49,7 +50,8 @@ To create from a samtools flagstats file in ``/path/to/flagstats.txt`` and write
import json
from qc_utils import QCMetric, QCMetricRecord
from qc_utils.parsers import parse_flagstats
flagstat_qc_obj = QCMetric("flagstat", "/path/to/flagstats.txt", parser=parse_flagstats)
flagstats = parse_flagstats("/path/to/flagstats.txt")
flagstat_qc_obj = QCMetric("flagstat", flagstats)
with open("/path/to/flagstats.json", "w") as fp:
json.dump(flagstat_qc_obj.to_ordered_dict(), fp)

Expand All @@ -59,8 +61,10 @@ QCMetricRecord can also have a name, and can be written into ``json`` as follows
import json
from qc_utils import QCMetric, QCMetricRecord
from qc_utils.parsers import parse_flagstats, parse_starlog
log_qc_obj = QCMetric("starlogQC", "/path/to/star_Log.out", parser=parse_starlog)
flagstat_qc_obj = QCMetric("flagstat", "/path/to/flagstats.txt", parser=parse_flagstats)
starlog = parse_starlog("/path/to/star_Log.out")
flagstats = parse_flagstats("/path/to/flagstats.txt")
log_qc_obj = QCMetric("starlogQC", starlog)
flagstat_qc_obj = QCMetric("flagstat", flagstats)
record = QCMetricRecord([log_qc_obj, flagstat_qc_obj], name="alignment_qc")
with open("/path/to/alignment_qc.json", "w") as fp:
json.dump(record.to_ordered_dict(), fp)
Expand All @@ -86,6 +90,7 @@ Table of Contents
:maxdepth: 2

license
changelog

Indices and tables
==================
Expand Down
2 changes: 1 addition & 1 deletion qc_utils/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from qc_utils.qcmetric import QCMetric, QCMetricRecord

__title__ = "qc-utils"
__version__ = "0.2.1"
__version__ = "19.08.1.dev0"
__description__ = "Tool for representing ENCODE QC metrics"
__url__ = "https://github.com/ENCODE-DCC/qc-utils"
__uri__ = __url__
Expand Down
7 changes: 2 additions & 5 deletions qc_utils/qcmetric.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,8 @@ class QCMetric(object):
instantiated from a regular dict.
"""

def __init__(self, qc_metric_name, qc_metric_content, parser=None):
if parser is not None:
qc_metric_dict = parser(qc_metric_content)
else:
qc_metric_dict = qc_metric_content
def __init__(self, qc_metric_name, qc_metric_content):
qc_metric_dict = qc_metric_content
if not isinstance(qc_metric_dict, dict):
raise TypeError("QCMetric data must be a dict.")
self._name = qc_metric_name
Expand Down

0 comments on commit 9fbcf30

Please sign in to comment.