From 0bcc152d9678cf1298b0eace3c83f87b1eb7f0d6 Mon Sep 17 00:00:00 2001 From: balajtimate Date: Thu, 3 Oct 2024 17:04:20 +0200 Subject: [PATCH] feat: add read orient paired json output --- htsinfer/get_read_orientation.py | 58 +++++++++++++++++++++++++++++--- 1 file changed, 53 insertions(+), 5 deletions(-) diff --git a/htsinfer/get_read_orientation.py b/htsinfer/get_read_orientation.py index 01a0c9b..3ad298e 100644 --- a/htsinfer/get_read_orientation.py +++ b/htsinfer/get_read_orientation.py @@ -319,13 +319,61 @@ def process_paired( # pylint: disable=R0912,R0915 orientation.file_1 = StatesOrientation.unstranded orientation.file_2 = StatesOrientation.unstranded - # write log messages and return result + orient_df_1 = pd.DataFrame([{ + 'Number of mapped reads': reads, + 'Fraction ISF': fractions_all_states.get( + StatesOrientationRelationship.inward_stranded_forward + ), + 'Fraction ISR': fractions_all_states.get( + StatesOrientationRelationship.inward_stranded_reverse + ), + 'Orientation': getattr(orientation.file_1, 'value', None), + 'Relationship': getattr(orientation.relationship, 'value', None) + }]) + orient_df_2 = pd.DataFrame([{ + 'Number of mapped reads': reads, + 'Fraction ISF': fractions_all_states.get( + StatesOrientationRelationship.inward_stranded_forward + ), + 'Fraction ISR': fractions_all_states.get( + StatesOrientationRelationship.inward_stranded_reverse + ), + 'Orientation': getattr(orientation.file_2, 'value', None), + 'Relationship': getattr(orientation.relationship, 'value', None) + }]) + LOGGER.debug( + f"Required number of mapped reads: {self.min_mapped_reads}" + ) + LOGGER.debug(f"Number of mapped reads: {orient_df_1.iloc[0, 0]}") + LOGGER.debug(f"Fraction of ISF: {orient_df_1.iloc[0, 1]}") + LOGGER.debug(f"Fraction of ISR: {orient_df_1.iloc[0, 2]}") + LOGGER.debug(f"Orientation file 1: {orient_df_1.iloc[0, 3]}") + LOGGER.debug(f"Orientation file 2: {orient_df_2.iloc[0, 3]}") LOGGER.debug( - f"Required number of mapped read pairs: {self.min_mapped_reads}" + f"Orientation relationship: {orient_df_1.iloc[0, 4]}" ) - LOGGER.debug(f"Number of reads mapped: {reads}") - LOGGER.debug(f"Fraction of states: {fractions_all_states}") - LOGGER.debug(f"Orientation: {orientation}") + filename_1 = ( + Path(self.out_dir) / f"read_orientation_{self.paths[0].name}.json" + ) + LOGGER.debug(f"Writing results to file: {filename_1}") + orient_df_1.to_json( + filename_1, + orient='split', + index=False, + indent=True, + ) + filename_2 = ( + Path(self.out_dir) / f"read_orientation_" + f"{getattr(self.paths[1], 'name')}.json" + ) + LOGGER.debug(f"Writing results to file: {filename_2}") + orient_df_2.to_json( + filename_2, + orient='split', + index=False, + indent=True, + ) + return orientation @staticmethod