Skip to content

Commit

Permalink
resolve nan issue with merge priority
Browse files Browse the repository at this point in the history
  • Loading branch information
jykr committed Oct 3, 2023
1 parent 7446cbe commit bbfc8d2
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 14 deletions.
3 changes: 2 additions & 1 deletion bean/annotate/filter_alleles.py
Original file line number Diff line number Diff line change
Expand Up @@ -491,7 +491,8 @@ def _map_alleles_to_filtered(
# prioritize allele with most mean counts
merge_priority = guide_filtered_allele_counts.mean(
axis=1, numeric_only=True
).values
)
merge_priority = merge_priority.fillna(0)
if is_cn_allele:
guide_raw_counts["allele_mapped"] = guide_raw_counts[allele_col].map(
lambda allele: allele.map_to_closest(
Expand Down
24 changes: 16 additions & 8 deletions bean/annotate/translate_allele.py
Original file line number Diff line number Diff line change
Expand Up @@ -419,7 +419,7 @@ def translate_allele(
)
return get_allele_aa_change_multi_genes(
allele,
gene_names=fasta_file_dict,
gene_names=gene_names,
include_synonymous=include_synonymous,
)
elif fasta_file:
Expand All @@ -432,11 +432,19 @@ def translate_allele(
fasta_file=fasta_file,
include_synonymous=include_synonymous,
)
return get_allele_aa_change_multi_genes(
allele,
fasta_file_dict=fasta_file_dict,
include_synonymous=include_synonymous,
)
elif fasta_file_dict:
return get_allele_aa_change_multi_genes(
allele,
fasta_file_dict=fasta_file_dict,
include_synonymous=include_synonymous,
)
else:
fasta_file_name = os.path.dirname(be.__file__) + "/annotate/ldlr_exons.fa"
return get_allele_aa_change_single_gene(
allele,
fasta_file=fasta_file_name,
include_synonymous=include_synonymous,
)
except RefBaseMismatchException as e:
if not allow_ref_mismatch:
raise e
Expand All @@ -446,7 +454,7 @@ def translate_allele(

def translate_allele_df(
allele_df,
include_synonymouns=True,
include_synonymous=True,
allow_ref_mismatch=True,
fasta_file=None,
fasta_file_dict: Dict[str, str] = None,
Expand All @@ -457,7 +465,7 @@ def translate_allele_df(
translated_alleles = allele_df.allele.map(
lambda a: be.translate_allele(
a,
include_synonymouns=include_synonymouns,
include_synonymous=include_synonymous,
allow_ref_mismatch=allow_ref_mismatch,
fasta_file=fasta_file,
fasta_file_dict=fasta_file_dict,
Expand Down
2 changes: 1 addition & 1 deletion bean/annotate/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ def check_args(args):
+ int(args.translate_fastas_csv is not None)
+ int(args.translate_gene is not None)
+ int(args.translate_genes_list is not None)
!= 1
> 1
):
raise ValueError(
"Invalid arguments: You should specify exactly one of --translate-fasta, --translate-fastas-csv, --translate-gene, translate-genes-list to translate alleles."
Expand Down
4 changes: 1 addition & 3 deletions bean/framework/Edit.py
Original file line number Diff line number Diff line change
Expand Up @@ -235,9 +235,7 @@ def map_to_closest(
raise ValueError(
f"merge_priority length {len(merge_priority)} is not the same as allele_list length {len(allele_list)}"
)
nt_max_idx = nt_max_idx[
np.argmax(merge_priority[nt_max_idx], skipna=True)
]
nt_max_idx = nt_max_idx[np.nanargmax(merge_priority[nt_max_idx])]
else:
nt_max_idx = nt_max_idx[0]
if nt_jaccards[nt_max_idx] > jaccard_threshold:
Expand Down
2 changes: 1 addition & 1 deletion bean/mapping/GuideEditCounter.py
Original file line number Diff line number Diff line change
Expand Up @@ -743,7 +743,7 @@ def _check_names_filter_fastq(self, filter_by_qual=False):
)

R1, R2 = self._get_seq_records()

info("Done loading reads for quality filtering")
_check_readname_match(R1, R2)
if filter_by_qual:
self.n_reads_after_filtering = self._filter_read_quality(R1, R2)
Expand Down

0 comments on commit bbfc8d2

Please sign in to comment.