Skip to content

Commit

Permalink
feat: add read orient single json output
Browse files Browse the repository at this point in the history
  • Loading branch information
balajtimate committed Oct 2, 2024
1 parent 51957ac commit 1da7d19
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions htsinfer/get_read_orientation.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 1da7d19

Please sign in to comment.