Code Monkey home page Code Monkey logo

ym162 / tumorsim Goto Github PK

View Code? Open in Web Editor NEW
1.0 2.0 1.0 89.47 MB

Simulation of tumoral growth in multiple dimensions with a special focus on fitness landscapes and adaptive therapy. See Fontaneda, D. & Diaz-Uriarte, R. (2023). Adaptive therapy in cancer: the role of restrictions in the accumulation of mutations. BioRxiv, 2023.05.18(541330), doi: https://doi.org/10.1101/2023.05.18.541330

License: GNU General Public License v3.0

Julia 100.00%

tumorsim's Introduction

TumorSim.jl

Build Status codecov

Julia code for the simulation of tumoral growth in multiple dimensions with a special focus on fitness landscapes and adaptive therapy.

This code is used in Fontaneda, D. & Diaz-Uriarte, R. (2023). Adaptive therapy in cancer: the role of restrictions in the accumulation of mutations. BioRxiv, 2023.05.18(541330), doi: https://doi.org/10.1101/2023.05.18.541330

How to install

1.- Clone the git repo.

git clone https://github.com/YM162/TumorSim.git
cd TumorSim

2.- Install all required dependencies. First, you must install Julia: https://julialang.org/downloads/ . Then, install the dependencies:

using DrWatson
@quickactivate "TumorSim"

using Pkg; Pkg.instantiate()

3.- (Optional) Build a sysimage for faster loading times.

julia scripts/build.jl

How to use

1.- (Optional) Launch the sysimage and set the number of cores for paralellization.

julia -q --sysimage build/TumorSim.so -p 4

2.- Import the DrWatson and TumorSim packages.

using DrWatson
@quickactivate "TumorSim"
using TumorSim

3.- Create a scenario defining the starting state of the simulation.

# create_scenario(dims, Initial Cells, cell_positions).
# Cell position can be "center", "random" or an array specifying the exact positions.

scenario_1D = create_scenario((1000000,),10,"center")

scenario_2D = create_scenario((1000,1000),10,"center")

scenario_3D = create_scenario((100,100,100),10,"center")

4.- Create a fitness landscape.

#Must be a dictionary with genotype keys mapping to mitosis probabilities. If a genotype is not in the dictionary, it is asumed to have a mitosis probability of 0.

fitness = Dict([0,0,0]=>0.027,
                [1,0,0]=>0.030,
                [0,1,0]=>0.033,
                [1,1,0]=>0.046,
                [1,1,1]=>0.025)

#We can also use the OncoSimulR rfitness function. 
#See ./scripts/AT_in_cancer_the_role_of_restrictions_2023/Simulate_7Genes_NK_Fitness_1.jl for a working example.

For more information about generating random fitness landscapes take a look at the OncoSimulR documentation.

5.- Create a Treatment.

#Treatment(Detection size, Starting size (% of detection size), Pausing size (% of detection size), Gene of resistance, kill_rate)

adaptive_therapy = create_treatment(10000, 1.0, 0.5, 3, 0.75) 

continuous_therapy = create_treatment(10000, 1.0, 0, 3, 0.75) 

#After the Detection size has been reached, treatment cycles starting and pausing at the specified sizes will begin, killing kill_rate% of the susceptible cells that try to reproduce.

8.- Create a vector of all the scenarios you want to test.

#We need to specify death rate (% of WT mitosis probability), mutation rate, starting scenario, fitness landscape, treatment, migration rate and interaction rule (:contect or :hierarchical_voter)

parameters = Dict(
    "death_rate" => [0,0.3],
    "mutation_rate" => [0.01,0.015,0.02],   
    "scenario" => [scenario_2D,scenario_3D], 
    "fitness" => fitness,
    "treatment" => [adaptive_therapy,continuous_therapy],
    "migration_rate" => [0.1],
    "interaction_rule" => [:contact],
    "seed" => map(abs,rand(Int64,1000))
)

#DrWatson's dict_list allows us to expand the vectors in our original dict to produce a list with all of the possible combinations of parameters.

parameter_combinations = dict_list(parameters)

9a.- Run a single simulation.

#We specify the number of steps each simulation will go through. The simulation will stop early if all cells die or if we reach 1.5 * treatment.detection_size (resistance was aquired).
steps=5000

#Get a dictionary with the results of the simulation.
result = simulate(parameter_combinations[1],steps)

#We save it to disk in the BSON format
using BSON
filepath = datadir("simulations","example_sim.bson")
bson(filepath,Dict("result" => result))

9b.- Run all the simulations at once using parallelization.

using Distributed
using ProgressMeter

#We use progress_pmap from the ProgressMeter package to take advantage of parallelization and perform the simulations.
p = Progress(length(parameter_combinations), 
            barglyphs=BarGlyphs("[=> ]"),output=stdout,barlen=50)

results = progress_pmap(simulate,
                        parameter_combinations,
                        fill(steps,length(parameter_combinations)),progress=p)


#We again save all of the simulations in a dataframe in the BSON format.
using BSON
using DataFrames

df = DataFrame(results)
filepath = datadir("simulations","example_multi_sim.bson")
bson(filepath,Dict("df" => df))

License

All code is distributed under the GNU GPL v. 3.0 license.

Citation

A pre-print of our manuscript using this model can be found in bioRxiv:

  • Fontaneda, D. & Diaz-Uriarte, R. (2023). Adaptive therapy in cancer: the role of restrictions in the accumulation of mutations. BioRxiv, 2023.05.18(541330), doi: https://doi.org/10.1101/2023.05.18.541330

tumorsim's People

Contributors

ym162 avatar rdiaz02 avatar

Stargazers

 avatar

Watchers

 avatar  avatar

Forkers

rdiaz02

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.