Skip to content

Instantly share code, notes, and snippets.

View romunov's full-sized avatar

Roman Luštrik romunov

View GitHub Profile
@romunov
romunov / gist:b8da2cbab959b3690c5e
Created February 8, 2015 10:39
crayfish data analysis using TMB
# this is what i have so far
require(TMB)
rak <- read.table("./data/master_all_r3.txt", dec = ".", header = TRUE, sep = "\t")
# prepare the data
rakdat <- na.omit(rak[, c("vrsta", "tw", "ETS_t_1000")])
xvar <- rakdat[, "tw"]
yvar <- rakdat[, "ETS_t_1000"]
subsetGenData <- function(x) {
mp <- droplevels(other(x)$metadata)
iksips <- other(x)$xy
pet <- df2genind(X = genind2df(x, sep = "/"), sep = "/", ind.names = indNames(x),
loc.names = locNames(x))
pet@other$metadata <- mp
pet@other$xy <- iksips
pet
}
library(dplyr)
my.db <- src_sqlite("my_db.sqlite3", create = TRUE)
# creates an empty file
library(nycflights13)
# link to flights table
flights.db <- copy_to(my.db, flights, temporary = FALSE,
indexes = list(c("year", "month", "day"), "carrier", "tailnum"))
```R
---
title: "Analiza - CRO"
author: "Teo"
date: "Sunday, February 15, 2015"
output: html_document
---
```{r}
library(ggplot2)
@romunov
romunov / gist:9e65d246146095166c57
Last active August 29, 2015 14:15
sample a population based on variable according to a parametric distribution

Imagine having a population where age of individuals is known. I would like to sample from this population individuals by age according to a parametric distribution (e.g. X ~ Poisson(1.82)). In other words, I would like to remove a known number of individuals from each class, where class sizes follows a Poisson distribution.

Is there a more elegant way?

ma <- 10 # max age
ss <- 50 # sample size
l <- 1.82 # lambda in Poisson distribution

set.seed(357)
@romunov
romunov / gist:27b392b2092b989ff036
Last active August 29, 2015 14:15
problem installing adegenet from github through devtools

I'm trying to install adegenet package using install_github(), but I get a few errors. I'm able to install the package if I build and install the package from console. For the latter output see below. I'm using 64-bit Windows 7. I wonder to what can we attribute the discrepancy between these two ways of installing a package?

Installation through devtools (fail)

> install_github("thibautjombart/adegenet/pkg")
Downloading github repo thibautjombart/adegenet@master
Installing adegenet
"C:/PROGRA~1/R/R-31~1.2/bin/x64/R" --vanilla CMD INSTALL  \
  "C:/Users/romunov/AppData/Local/Temp/RtmpSo6w8C/devtools15882f7c4022/thibautjombart-adegenet-8cca9e1/pkg"  \
  --library="C:/Users/romunov/Documents/R/win-library/3.1" --install-tests 
# -*- coding: utf-8 -*-
import simuPOP as sim
import numpy as np
import random
from math import exp
#from scipy.stats import poisson # for poisson pmf
popHR = 2000
popSI = 1000
population_size = popHR + popSI
@romunov
romunov / gist:c8e64d1f38d54dd687f6
Last active August 29, 2015 14:17
migrating individuals from one VSP to a neighboring SP
# this example demostrantes that two individuals are not migrated from VSP [1, 1] to subpopulation 0
import simuPOP as sim
import numpy as np
pop = sim.Population(size = [100, 100], loci = 3, infoFields = ["age", "migrate_to"])
sim.initInfo(pop = pop, values = np.random.negative_binomial(n = 3, p = 0.4, size = 20), infoFields = "age")
sim.initSex(pop, maleProp = 0.5)
pop.setVirtualSplitter(sim.ProductSplitter(splitters = [
sim.SexSplitter(),
@romunov
romunov / gist:02a030498312a7937538
Created April 15, 2015 09:52
writing to a file from a function
# -*- coding: utf-8 -*-
import simuPOP as sim
import numpy as np
from simuPOP.utils import viewVars
pop = sim.Population(size = [550, 400], loci = 10, infoFields = ["age", "migrate_to"], subPopNames = ["croatia", "slovenia"])
sim.initInfo(pop = pop, values = np.random.choice([1, 2, 3, 4, 5], replace = True, size = 200), infoFields = "age")
sim.initGenotype(pop = pop, prop = [0.1]*10)
sim.initSex(pop, maleProp = 0.5)
@romunov
romunov / gist:4bc695e168cc14f3f0b8
Created April 22, 2015 11:03
write Ne_LD_sp results to a file
def splitCalcMerge(pop, param):
# Calculate population sizes to help with splitting (see below).
pop_size_croatia = pop.subPopSize(0)
pop_size_slovenia = pop.subPopSize(1)
pop_sizes = {"1":pop_size_croatia, "3":pop_size_slovenia}
# Split population into two. First subpopulation is the main one minus the
# sample size (ss).
sim.splitSubPops(pop = pop, subPops = 0, sizes = [pop_size_croatia - param["croatia"], param["croatia"]])
sim.splitSubPops(pop = pop, subPops = 2, sizes = [pop_size_slovenia - param["slovenia"], param["slovenia"]])