Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 6 additions & 8 deletions maxatac/utilities/prediction_tools.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import logging

import numpy as np
import pandas as pd
import pybedtools
Expand Down Expand Up @@ -31,6 +30,7 @@ def write_predictions_to_bigwig(df: pd.DataFrame,
output_filename: str,
chrom_sizes_dictionary: dict,
chromosomes: list,
max_zooms: int,
agg_mean: bool = True
):
"""Write the predictions dataframe into a bigwig file
Expand All @@ -40,10 +40,11 @@ def write_predictions_to_bigwig(df: pd.DataFrame,
output_filename (str): The output bigwig filename
chrom_sizes_dictionary (dict): A dictionary of chromosome sizes used to form the bigwig file
chromosomes (list): A list of chromosomes that you are predicting in
agg_mean (bool, optional): use aggregation method of mean. Defaults to True.
max_zooms (int, optional): The desired number of zoom levels to be retained in the output bigWig file. Defaults to 5.
agg_mean (bool, optional): Use aggregation method of mean. Defaults to True.

Returns:
Writes a bigwig file
Writes a bigWig file

Example:

Expand All @@ -63,7 +64,7 @@ def write_predictions_to_bigwig(df: pd.DataFrame,
header = [(x, chrom_sizes_dictionary[x]) for x in chromosomes]

# Add header to bigwig
data_stream.addHeader(header)
data_stream.addHeader(header, maxZooms = max_zooms)

for chromosome in chromosomes:
# Create a tmp df from the predictions dataframe for each chrom
Expand All @@ -76,10 +77,9 @@ def write_predictions_to_bigwig(df: pd.DataFrame,
data_stream.addEntries(chroms=tmp_chrom_df["chr"].tolist(),
starts=tmp_chrom_df["start"].tolist(),
ends=tmp_chrom_df["stop"].tolist(),
values=tmp_chrom_df["score"].tolist()
values=tmp_chrom_df["score"].astype(np.float16).tolist()
)


def import_prediction_regions(bed_file: str,
chromosomes: list,
chrom_sizes_dictionary: dict,
Expand Down Expand Up @@ -220,7 +220,6 @@ def create_prediction_regions(chromosomes: list,

return df


class PredictionDataGenerator(tf.keras.utils.Sequence):
def __init__(self,
signal,
Expand Down Expand Up @@ -327,7 +326,6 @@ def __get_region_values__(self, roi_pool):

return np.array(inputs_batch)


def make_stranded_predictions(roi_pool: pd.DataFrame,
signal: str,
sequence: str,
Expand Down