Skip to content

Instantly share code, notes, and snippets.

View zx8754's full-sized avatar
🤦‍♂️
24/7

Tokhir Dadaev zx8754

🤦‍♂️
24/7
View GitHub Profile
vif_func<-function(in_frame,thresh=10,trace=T,wts=NULL,...){
library(fmsb)
if(any(!'data.frame' %in% class(in_frame))) in_frame<-data.frame(in_frame)
if(is.null(wts))
wts <- rep(1, ncol(in_frame))
if(!is.null(wts))
if(length(wts)!=ncol(in_frame)) stop('length of weights must equal number of variables')
@brentp
brentp / README.md
Last active October 12, 2023 15:21

Linkage Disequilibrium Calculation

This is complete taken from Ryan D on biostar: http://www.biostars.org/p/2909/#16419

It takes a region in a format like "chr2:1234-3456". If an rs number is specified after the region, it will output the R^2 for every SNP in that region with the requested SNP; otherwise, it is all-vs-all.

@mrdwab
mrdwab / stratified.R
Last active April 27, 2024 19:57
Stratified random sampling from a `data.frame` in R
stratified <- function(df, group, size, select = NULL,
replace = FALSE, bothSets = FALSE) {
if (is.null(select)) {
df <- df
} else {
if (is.null(names(select))) stop("'select' must be a named list")
if (!all(names(select) %in% names(df)))
stop("Please verify your 'select' argument")
temp <- sapply(names(select),
function(x) df[[x]] %in% select[[x]])
@dcomtois
dcomtois / r_c.txt
Last active January 10, 2024 19:08
Linking R internal & primitive C functions with appropriate source files. --- printname = R function name ; c.entry = C function ; sourcefile = relevant C source file; line_no: line featuring fn definition (not all checked)
printname c.entry file line_no
- do_arith R-4.0.3\src\main\arithmetic.c 411
! do_logic R-4.0.3\src\main\logic.c 40
!= do_relop R-4.0.3\src\main\relop.c 51
$ do_subset3 R-4.0.3\src\main\subset.c 1206
$<- do_subassign3 R-4.0.3\src\main\subassign.c 2081
%% do_arith R-4.0.3\src\main\arithmetic.c 411
%*% do_matprod R-4.0.3\src\main\array.c 1228
%/% do_arith R-4.0.3\src\main\arithmetic.c 411
& do_logic R-4.0.3\src\main\logic.c 40
library(readxl)
library(janitor)
library(ggraph)
library(igraph)
df <- readxl::read_excel("/eurovision_song_contest_1975_2016.xlsx") %>%
clean_names()
df <- df[, c(5, 6, 1:4, 7)]
@elowy01
elowy01 / BCFtools cheat sheet
Last active June 29, 2024 05:24
BCFtools cheat sheet
*bcftools filter
*Filter variants per region (in this example, print out only variants mapped to chr1 and chr2)
qbcftools filter -r1,2 ALL.chip.omni_broad_sanger_combined.20140818.snps.genotypes.hg38.vcf.gz
*printing out info for only 2 samples:
bcftools view -s NA20818,NA20819 filename.vcf.gz
*printing stats only for variants passing the filter:
bcftools view -f PASS filename.vcf.gz