Skip to content

Commit

Permalink
fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
sanjaynagi committed Sep 27, 2024
1 parent 582f221 commit b064e53
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 30 deletions.
30 changes: 28 additions & 2 deletions AnoPrimer/evaluate.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
_plotly_primers,
_retrieve_span,
_return_oligo_list,
add_spans_to_df,
retrieve_data_resource,
round_floats_in_df,
)
Expand Down Expand Up @@ -73,14 +72,16 @@ def __init__(
self.assay_type = assay_type
self.assay_name = assay_name

self.df = round_floats_in_df(add_spans_to_df(primer_df), decimal_places=2)
self.seq_parameters = seq_parameters
self.primer_parameters = primer_parameters

# Extract additional attributes from seq_parameters
self.target_sequence = seq_parameters.get("SEQUENCE_TEMPLATE")
self.gdna_pos = np.array(seq_parameters.get("GENOMIC_DNA_POSITIONS"))

self.df = primer_df
self.df = round_floats_in_df(self.add_spans_to_df(), decimal_places=2)

def evaluate_primers(
self,
sample_sets,
Expand Down Expand Up @@ -122,6 +123,31 @@ def evaluate_primers(
if out_dir is not None and blat_df is not None:
blat_df.to_csv(f"{out_dir}/{self.assay_name}_blat_results.csv")

def add_spans_to_df(self):
df = self.df
oligos, _ = _return_oligo_list(assay_type=self.assay_type)

oligo_spans = {}
for oligo in oligos:
spans = []
for pair in df:
pos = _retrieve_span(
df,
gdna_pos=self.gdna_pos,
oligo=oligo,
assay_type=self.assay_type,
pair=pair,
)
span = f"{self.contig}:{pos.min()}-{pos.max()}"
spans.append(span)

oligo_spans[oligo] = pd.Series(
spans, name=f"primer_{oligo}_span", index=self.df.columns
)
df = pd.concat([df, oligo_spans[oligo].to_frame().T])

return df

def summarise_metadata(self, sample_sets=None, sample_query=None):
"""
Retrieve a summary of metadata for samples in the ag3/af1 resource.
Expand Down
26 changes: 1 addition & 25 deletions AnoPrimer/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,30 +153,6 @@ def _plotly_frequencies(


#### utility functions ####
def add_spans_to_df(primers):
df = primers.df
oligos, _ = _return_oligo_list(assay_type=primers.assay_type)

oligo_spans = {}
for oligo in oligos:
spans = []
for pair in df:
pos = _retrieve_span(
df,
gdna_pos=primers.gdna_pos,
oligo=oligo,
assay_type=primers.assay_type,
pair=pair,
)
span = f"{primers.contig}:{pos.min()}-{pos.max()}"
spans.append(span)

oligo_spans[oligo] = pd.Series(
spans, name=f"primer_{oligo}_span", index=primers.df.columns
)
df = pd.concat([df, oligo_spans[oligo].to_frame().T])

return df


def round_floats_in_df(df, decimal_places=1):
Expand All @@ -193,7 +169,7 @@ def round_if_float(val):
except (ValueError, TypeError):
return val

return df.map(round_if_float)
return df.applymap(round_if_float)


def extract_trailing_digits(string):
Expand Down
6 changes: 3 additions & 3 deletions tests/run_ci_notebooks.sh
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@

papermill notebooks/AnoPrimer-long.ipynb tests/qPCR_run.ipynb -k AnoPrimer -f tests/cDNA_Params_fun.json &&
papermill notebooks/AnoPrimer-long.ipynb tests/qPCR2_run.ipynb -k AnoPrimer -f tests/cDNA_Params_2_fun.json &&
papermill notebooks/AnoPrimer-long.ipynb tests/gDNA_run.ipynb -k AnoPrimer -f tests/gDNA_probe_Params_fun.json &&
papermill notebooks/AnoPrimer-long.ipynb tests/qPCR_run.ipynb -k AnoPrimer -f tests/cDNA_Params.json &&
papermill notebooks/AnoPrimer-long.ipynb tests/qPCR2_run.ipynb -k AnoPrimer -f tests/cDNA_Params_2.json &&
papermill notebooks/AnoPrimer-long.ipynb tests/gDNA_run.ipynb -k AnoPrimer -f tests/gDNA_probe_Params.json &&
papermill notebooks/AnoPrimer-long.ipynb tests/probe_run.ipynb -k AnoPrimer -f tests/probe_Params.json &&
papermill notebooks/AnoPrimer-long.ipynb tests/qPCR_run.ipynb -k AnoPrimer -f tests/cDNA_Params_fun.json &&
papermill notebooks/AnoPrimer-long.ipynb tests/qPCR2_run.ipynb -k AnoPrimer -f tests/cDNA_Params_2_fun.json &&
papermill notebooks/AnoPrimer-long.ipynb tests/gDNA_run.ipynb -k AnoPrimer -f tests/gDNA_probe_Params_fun.json &&
papermill notebooks/AnoPrimer-short.ipynb tests/short_run.ipynb -k AnoPrimer

0 comments on commit b064e53

Please sign in to comment.