Skip to content

Commit

Permalink
fix replicate assignment
Browse files Browse the repository at this point in the history
  • Loading branch information
jykr committed Apr 2, 2024
1 parent c0fd334 commit 1942074
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 9 deletions.
40 changes: 39 additions & 1 deletion bean/cli/filter.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,5 +194,43 @@ def main(args):
f"Saving plotting result and log at {args.output_prefix}.[filtered_allele_stats.pdf, filter_log.txt]."
)
with open(f"{args.output_prefix}.filter_log.txt", "w") as out_log:
out_log.write(
"filter_step\tn_alleles\tn_var\tn_noncoding_var\tn_coding_var\tn_synonymous_var\n"
)
for key in allele_df_keys:
out_log.write(f"{key}\t{len(bdata.uns[key])}\n")
if "translate" in key:
n_coding_vars = len(
set().union(
*bdata.uns[key]
.aa_allele.map(lambda a: list(a.aa_allele.edits))
.tolist()
)
)
n_syn_vars = len(
set().union(
*bdata.uns[key]
.aa_allele.map(
lambda a: {e for e in a.aa_allele.edits if e.ref == e.alt}
)
.tolist()
)
)
n_noncoding_vars = len(
set().union(
*bdata.uns[key]
.aa_allele.map(lambda a: list(a.nt_allele.edits))
.tolist()
)
)
out_log.write(
f"{key}\t{len(bdata.uns[key])}\t{n_coding_vars + n_noncoding_vars}\t{n_noncoding_vars}\t{n_coding_vars}\t{n_syn_vars}\n"
)
else:
n_noncoding_vars = len(
set().union(
*bdata.uns[key].allele.map(lambda a: list(a.edits)).tolist()
)
)
out_log.write(
f"{key}\t{len(bdata.uns[key])}\t{n_noncoding_vars}\t{n_noncoding_vars}\t{0}\t{0}\n"
)
15 changes: 10 additions & 5 deletions bean/cli/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
warn = logging.warning
debug = logging.debug
info = logging.info

pyro.set_rng_seed(101)

warnings.filterwarnings(
Expand Down Expand Up @@ -72,16 +73,20 @@ def main(args):
print("bean-run: Run model to identify targeted variants and their impact.")
bdata = be.read_h5ad(args.bdata_path)
args, bdata = check_args(args, bdata)
if args.cuda:
os.environ["CUDA_VISIBLE_DEVICES"] = "1"
torch.set_default_tensor_type(torch.cuda.FloatTensor)
else:
torch.set_default_tensor_type(torch.FloatTensor)
prefix = (
args.outdir
+ "/bean_run_result."
+ os.path.basename(args.bdata_path).rsplit(".", 1)[0]
)
file_logger = logging.FileHandler(f"{prefix}.log")
file_logger.setLevel(logging.INFO)
logging.getLogger().addHandler(file_logger)
if args.cuda:
os.environ["CUDA_VISIBLE_DEVICES"] = "1"
torch.set_default_tensor_type(torch.cuda.FloatTensor)
else:
torch.set_default_tensor_type(torch.FloatTensor)

os.makedirs(prefix, exist_ok=True)
model_label, model, guide = identify_model_guide(args)
info("Done loading data. Preprocessing...")
Expand Down
4 changes: 1 addition & 3 deletions bean/preprocessing/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,7 @@ def __set__(self, obj, value):
def prepare_bdata(bdata: be.ReporterScreen, args, warn, prefix: str):
"""Utility function for formatting bdata for bean-run"""
bdata = bdata.copy()
bdata.samples[args.replicate_col] = bdata.samples[args.replicate_col].astype(
"category"
)
bdata.samples["replicate"] = bdata.samples[args.replicate_col].astype("category")
bdata.guides = bdata.guides.loc[:, ~bdata.guides.columns.duplicated()].copy()
if args.library_design == "variant":
if bdata.guides[args.target_col].isnull().any():
Expand Down

0 comments on commit 1942074

Please sign in to comment.