Skip to content

Instantly share code, notes, and snippets.

@abikoushi
Created July 12, 2024 07:59
Show Gist options
  • Select an option

  • Save abikoushi/993a7c789f6ee699e3defbef5a0fe99c to your computer and use it in GitHub Desktop.

Select an option

Save abikoushi/993a7c789f6ee699e3defbef5a0fe99c to your computer and use it in GitHub Desktop.
RNA kinetics
library(deSolve)
library(ggplot2)
RNAvelo <- function(Time, State, Pars, input) {
with(as.list(c(State, Pars)), {
import <- input(Time)
du <- import - beta * U
ds <- beta * U - gamma * S
return(list(c(du, ds)))
})
}
parms <- c(beta = 0.1, gamma = 0.05)
times <- seq(0, 100, length = 101)
signal <- data.frame(times = times,
import = rep(0, length(times)))
signal$import[signal$times <= 11] <- 0.1
sigimp <- approxfun(signal$times, signal$import, rule = 2)
curve(sigimp(x), 0, 100)
xstart <- c(U=0, S = 0)
out <- ode(y = xstart, times = times,
func = RNAvelo, parms = parms, input = sigimp)
dfout <- as.data.frame(out)
ggplot(dfout, aes(x=time))+
geom_line(aes(y=U, colour="U"))+
geom_line(aes(y=S, colour="S"))+
labs(colour="")+
geom_vline(xintercept = 11, linetype=2)+
theme_bw(15)
ggsave("time_SU.png")
ggplot(dfout, aes(x=S,y=U))+
geom_path()+
geom_point(aes(colour=time))+
theme_bw(15)
ggsave("SvsU.png")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment