From 1da7d19a63835001226f262adc6dcad6c4a1ae2c Mon Sep 17 00:00:00 2001 From: balajtimate Date: Wed, 2 Oct 2024 15:56:52 +0200 Subject: [PATCH] feat: add read orient single json output --- htsinfer/get_read_orientation.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/htsinfer/get_read_orientation.py b/htsinfer/get_read_orientation.py index 4b36e8b..b6671a5 100644 --- a/htsinfer/get_read_orientation.py +++ b/htsinfer/get_read_orientation.py @@ -6,6 +6,7 @@ from typing import (Any, DefaultDict, Dict, List) import pysam # type: ignore +import pandas as pd # type: ignore from htsinfer.exceptions import ( FileProblem, @@ -58,6 +59,7 @@ def __init__( self.library_source = config.results.library_source self.transcripts_file = config.args.t_file_processed self.tmp_dir = config.args.tmp_dir + self.out_dir = config.args.out_dir self.min_mapped_reads = config.args.read_orientation_min_mapped_reads self.min_fraction = config.args.read_orientation_min_fraction self.mapping = mapping @@ -183,6 +185,24 @@ def process_single( LOGGER.debug(f"Number of reads mapped: {reads}") LOGGER.debug(f"Fraction of states: {fractions_all_states}") LOGGER.debug(f"Orientation: {orientation}") + + # write data frame (in JSON) to file + filename = ( + Path(self.out_dir) / f"read_layout_{sam.name}.json" + ) + LOGGER.debug(f"Writing results to file: {filename}") + orientation_df = pd.DataFrame([{ + 'Number of mapped reads': reads, + 'Fraction of states': fractions_all_states.get(StatesOrientation.stranded_forward, 0), + 'Orientation': orientation + }]) + orientation_df.to_json( + filename, + orient='split', + index=False, + indent=True, + ) + return orientation def process_paired( # pylint: disable=R0912,R0915