Skip to content

Commit

Permalink
v0.20.0
Browse files Browse the repository at this point in the history
  • Loading branch information
fraterenz committed Dec 11, 2023
1 parent ae1bbbe commit 6386dc8
Show file tree
Hide file tree
Showing 7 changed files with 109 additions and 47 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
# Changelog


## 0.20.0
change files and dir names after saving the data.
Now: `{SAMPLE}samples{CELLS}population/{MEASUREMENT}/{B0}b0_{B1}b1_{D0}d0_{D1}d1_0idx.json`.

## 0.19.0
remove bin `abc`.

Expand Down
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "ecdna-evo"
version = "0.19.0"
version = "0.20.0"
edition = "2021"
repository = "https://github.com/fraterenz/ecdna-evo"
description = "Evolutionary models of extra-chromosomal DNA (ecDNA)"
Expand Down
8 changes: 4 additions & 4 deletions src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ impl Dynamics {
P: AdvanceStep<NB_REACTIONS, Reaction = REACTION>
+ Clone
+ Debug
+ ToFile
+ ToFile<NB_REACTIONS>
+ RandomSampling,
REACTION: std::fmt::Debug,
{
Expand Down Expand Up @@ -101,7 +101,7 @@ impl Dynamics {
println!("subsample with {} cells", sampling.0);
}
process
.save(&path2dir.join("before_subsampling"), idx)
.save(&path2dir.join("before_subsampling"), rates, idx)
.with_context(|| {
format!(
"Cannot save run {} before subsampling",
Expand Down Expand Up @@ -139,7 +139,7 @@ impl Dynamics {
initial_state.population.iter().sum::<u64>() == 0u64;
if last_sample || no_individuals_left {
process
.save(&path2dir.join("after_subsampling"), idx)
.save(&path2dir.join("after_subsampling"), rates, idx)
.with_context(|| {
format!(
"Cannot save run {} for timepoint {}",
Expand All @@ -161,7 +161,7 @@ impl Dynamics {
}
run_helper(None, &self.path2dir, initial_state, &mut process);
process
.save(&self.path2dir, idx)
.save(&self.path2dir, rates, idx)
.with_context(|| format!("Cannot save run {}", idx))
.unwrap();
};
Expand Down
18 changes: 4 additions & 14 deletions src/clap_app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -175,24 +175,14 @@ impl Cli {
let samples_str: Vec<String> =
samples.iter().map(|ele| ele.to_string()).collect();
cli.path.join(format!(
"{}samples{}population_{}b0_{}b1_{}d0_{}d1",
"{}samples{}population",
samples_str.join("_"),
cells,
cli.b0.to_string().replace('.', ""),
cli.b1.to_string().replace('.', ""),
d0.to_string().replace('.', ""),
d1.to_string().replace('.', ""),
))
}
None => cli.path.join(format!(
"{}samples{}population_{}b0_{}b1_{}d0_{}d1",
cells,
cells,
cli.b0.to_string().replace('.', ""),
cli.b1.to_string().replace('.', ""),
d0.to_string().replace('.', ""),
d1.to_string().replace('.', ""),
)),
None => {
cli.path.join(format!("{}samples{}population", cells, cells,))
}
};

let process_type = {
Expand Down
11 changes: 8 additions & 3 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,16 @@ use std::path::Path;
use ecdna_lib::distribution::SamplingStrategy;
pub use ecdna_lib::{abc, distribution, DNACopy};
use rand::Rng;
use sosa::NbIndividuals;
use sosa::{NbIndividuals, ReactionRates};

/// Save the results of the simulations.
pub trait ToFile {
fn save(&self, path2dir: &Path, id: usize) -> anyhow::Result<()>;
pub trait ToFile<const NB_REACTIONS: usize> {
fn save(
&self,
path2dir: &Path,
rates: &ReactionRates<NB_REACTIONS>,
id: usize,
) -> anyhow::Result<()>;
}

/// Undersample a process by randomly reducing the number of individuals.
Expand Down
111 changes: 87 additions & 24 deletions src/process.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use ecdna_lib::distribution::SamplingStrategy;
use rand::Rng;
use sosa::{
write2file, AdvanceStep, CurrentState, NbIndividuals, NextReaction,
ReactionRates,
};

use crate::{
Expand All @@ -18,6 +19,26 @@ use super::{
segregation::IsUneven,
};

fn create_filename_birth_death(rates: &[f32; 4], id: usize) -> String {
format!(
"{}b0_{}b1_{}d0_{}d1_{}idx",
rates[0].to_string().replace('.', ""),
rates[1].to_string().replace('.', ""),
rates[2].to_string().replace('.', ""),
rates[3].to_string().replace('.', ""),
id,
)
}

fn create_filename_pure_birth(rates: &[f32; 2], id: usize) -> String {
format!(
"{}b0_{}b1_0d0_0d1_{}idx",
rates[0].to_string().replace('.', "dot"),
rates[1].to_string().replace('.', "dot"),
id,
)
}

#[derive(Debug, Clone, Copy)]
pub enum EcDNAEvent {
ProliferateNPlus,
Expand Down Expand Up @@ -85,16 +106,22 @@ where
}
}

impl<P, S> ToFile for PureBirth<P, S>
impl<P, S> ToFile<2> for PureBirth<P, S>
where
P: EcDNAProliferation,
S: Segregate,
{
fn save(&self, path2dir: &Path, id: usize) -> anyhow::Result<()> {
fn save(
&self,
path2dir: &Path,
rates: &ReactionRates<2>,
id: usize,
) -> anyhow::Result<()> {
//! Save the ecDNA distribution
let path2ecdna = path2dir.join("ecdna");
fs::create_dir_all(&path2ecdna).expect("Cannot create dir");
let path2file = path2ecdna.join(id.to_string()).with_extension("json");
let filename = create_filename_pure_birth(&rates.0, id);
let path2file = path2ecdna.join(filename).with_extension("json");
self.distribution.save(&path2file, self.verbosity)?;
Ok(())
}
Expand Down Expand Up @@ -238,14 +265,19 @@ where
}
}

impl<P, S> ToFile for PureBirthNMinusNPlus<P, S>
impl<P, S> ToFile<2> for PureBirthNMinusNPlus<P, S>
where
P: EcDNAProliferation,
S: Segregate,
{
fn save(&self, path2dir: &Path, id: usize) -> anyhow::Result<()> {
fn save(
&self,
path2dir: &Path,
rates: &ReactionRates<2>,
id: usize,
) -> anyhow::Result<()> {
fs::create_dir_all(path2dir).expect("Cannot create dir");
let filename = id.to_string();
let filename = create_filename_pure_birth(&rates.0, id);
self.data.save(path2dir, &filename, self.verbosity)?;
Ok(())
}
Expand Down Expand Up @@ -386,15 +418,20 @@ where
}
}

impl<P, S> ToFile for PureBirthMean<P, S>
impl<P, S> ToFile<2> for PureBirthMean<P, S>
where
P: EcDNAProliferation,
S: Segregate,
{
fn save(&self, path2dir: &Path, id: usize) -> anyhow::Result<()> {
fn save(
&self,
path2dir: &Path,
rates: &ReactionRates<2>,
id: usize,
) -> anyhow::Result<()> {
fs::create_dir_all(path2dir).expect("Cannot create dir");

let filename = id.to_string();
let filename = create_filename_pure_birth(&rates.0, id);
if self.verbosity > 1 {
println!("Saving data in {:#?}", path2dir)
}
Expand Down Expand Up @@ -597,12 +634,18 @@ impl<P: EcDNAProliferation, S: Segregate> AdvanceStep<4> for BirthDeath<P, S> {
}
}

impl<P: EcDNAProliferation, S: Segregate> ToFile for BirthDeath<P, S> {
fn save(&self, path2dir: &Path, id: usize) -> anyhow::Result<()> {
impl<P: EcDNAProliferation, S: Segregate> ToFile<4> for BirthDeath<P, S> {
fn save(
&self,
path2dir: &Path,
rates: &ReactionRates<4>,
id: usize,
) -> anyhow::Result<()> {
//! Save the ecDNA distribution
let path2ecdna = path2dir.join("ecdna");
let filename = create_filename_birth_death(&rates.0, id);
fs::create_dir_all(&path2ecdna).expect("Cannot create dir");
let path2file = path2ecdna.join(id.to_string()).with_extension("json");
let path2file = path2ecdna.join(filename).with_extension("json");
self.distribution.save(&path2file, self.verbosity)?;
Ok(())
}
Expand Down Expand Up @@ -675,15 +718,20 @@ where
}
}

impl<P, S> ToFile for BirthDeathNMinusNPlus<P, S>
impl<P, S> ToFile<4> for BirthDeathNMinusNPlus<P, S>
where
P: EcDNAProliferation,
S: Segregate,
{
fn save(&self, path2dir: &Path, id: usize) -> anyhow::Result<()> {
fn save(
&self,
path2dir: &Path,
rates: &ReactionRates<4>,
id: usize,
) -> anyhow::Result<()> {
fs::create_dir_all(path2dir).expect("Cannot create dir");

let filename = id.to_string();
let filename = create_filename_birth_death(&rates.0, id);
if self.verbosity > 1 {
println!("Saving data in {:#?}", path2dir)
}
Expand Down Expand Up @@ -842,15 +890,20 @@ where
}
}

impl<P, S> ToFile for BirthDeathMean<P, S>
impl<P, S> ToFile<4> for BirthDeathMean<P, S>
where
P: EcDNAProliferation,
S: Segregate,
{
fn save(&self, path2dir: &Path, id: usize) -> anyhow::Result<()> {
fn save(
&self,
path2dir: &Path,
rates: &ReactionRates<4>,
id: usize,
) -> anyhow::Result<()> {
fs::create_dir_all(path2dir).expect("Cannot create dir");

let filename = id.to_string();
let filename = create_filename_birth_death(&rates.0, id);
if self.verbosity > 1 {
println!("Saving data in {:#?}", path2dir)
}
Expand Down Expand Up @@ -1046,15 +1099,20 @@ where
}
}

impl<P, S> ToFile for BirthDeathMeanVariance<P, S>
impl<P, S> ToFile<4> for BirthDeathMeanVariance<P, S>
where
P: EcDNAProliferation,
S: Segregate,
{
fn save(&self, path2dir: &Path, id: usize) -> anyhow::Result<()> {
fn save(
&self,
path2dir: &Path,
rates: &ReactionRates<4>,
id: usize,
) -> anyhow::Result<()> {
fs::create_dir_all(path2dir).expect("Cannot create dir");

let filename = id.to_string();
let filename = create_filename_birth_death(&rates.0, id);
if self.verbosity > 1 {
println!("Saving data in {:#?}", path2dir)
}
Expand Down Expand Up @@ -1265,15 +1323,20 @@ where
}
}

impl<P, S> ToFile for BirthDeathMeanVarianceEntropy<P, S>
impl<P, S> ToFile<4> for BirthDeathMeanVarianceEntropy<P, S>
where
P: EcDNAProliferation,
S: Segregate,
{
fn save(&self, path2dir: &Path, id: usize) -> anyhow::Result<()> {
fn save(
&self,
path2dir: &Path,
rates: &ReactionRates<4>,
id: usize,
) -> anyhow::Result<()> {
fs::create_dir_all(path2dir).expect("Cannot create dir");

let filename = id.to_string();
let filename = create_filename_birth_death(&rates.0, id);
if self.verbosity > 1 {
println!("Saving data in {:#?}", path2dir)
}
Expand Down

0 comments on commit 6386dc8

Please sign in to comment.