Skip to content

Commit

Permalink
Update simualte
Browse files Browse the repository at this point in the history
  • Loading branch information
xin-huang committed Jan 2, 2024
1 parent fec9026 commit 9d35a0e
Showing 1 changed file with 9 additions and 10 deletions.
19 changes: 9 additions & 10 deletions sstar/simulate.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,13 @@ def simulate(demo_model_file, nrep, nref, ntgt, ref_id, tgt_id, src_id, ploidy,
intro_prop=intro_prop, not_intro_prop=not_intro_prop,
output_prefix=output_prefix, output_dir=output_dir, seed=seed)

label_df = pd.DataFrame()
for i in range(nrep):
df = pd.read_csv(f'{output_dir}/{i}/{output_prefix}.{i}.labels', sep="\t")
label_df = pd.concat([label_df, df])
label_df.to_csv(f'{output_dir}/{output_prefix}.all.labels', sep="\t", index=False)

if feature_config is not None:
label_df = pd.DataFrame()
for i in range(nrep):
df = pd.read_csv(f'{output_dir}/{i}/{output_prefix}.{i}.labels', sep="\t")
label_df = pd.concat([label_df, df])
label_df.to_csv(f'{output_dir}/{output_prefix}.all.labels', sep="\t", index=False)

feature_df = pd.DataFrame()
for i in range(nrep):
df = pd.read_csv(f'{output_dir}/{i}/{output_prefix}.{i}.features', sep="\t")
Expand Down Expand Up @@ -107,10 +107,6 @@ def _simulation_worker(in_queue, out_queue, **kwargs):
sample_tracts['sample'] = s
sample_tracts.to_csv(bed_file, sep="\t", mode='a', header=False, index=False)

_label(ind_file=tgt_ind_file, truth_tract_file=bed_file, output=label_file,
is_phased=kwargs["is_phased"], ploidy=kwargs["ploidy"], rep=rep,
seq_len=kwargs["seq_len"], intro_prop=kwargs["intro_prop"], not_intro_prop=kwargs["not_intro_prop"])

if kwargs['feature_config'] is not None:
preprocess(vcf_file=vcf_file, ref_ind_file=ref_ind_file, tgt_ind_file=tgt_ind_file, anc_allele_file=None,
feature_config=kwargs["feature_config"], is_phased=kwargs["is_phased"],
Expand All @@ -121,6 +117,9 @@ def _simulation_worker(in_queue, out_queue, **kwargs):
feature_df = pd.read_csv(feature_file, sep="\t")
feature_df['rep'] = rep
feature_df.to_csv(feature_file, sep="\t", index=False)
_label(ind_file=tgt_ind_file, truth_tract_file=bed_file, output=label_file,
is_phased=kwargs["is_phased"], ploidy=kwargs["ploidy"], rep=rep,
seq_len=kwargs["seq_len"], intro_prop=kwargs["intro_prop"], not_intro_prop=kwargs["not_intro_prop"])

out_queue.put(rep)

Expand Down

0 comments on commit 9d35a0e

Please sign in to comment.