Skip to content

Instantly share code, notes, and snippets.

View endrebak's full-sized avatar
🧬
Trying to write a genomic library in Rust

endrebak.ada endrebak

🧬
Trying to write a genomic library in Rust
View GitHub Profile
#!/usr/bin/env python2.7
### On SNPsnap
#!/bin/env python
#source /opt/rh/python27/enable
#---> gives Python 2.7.5 (where as Broad Dotkit python is Python 2.7.1)
import os
import sys
import collections
@endrebak
endrebak / nrwas.py
Last active December 11, 2019 12:01
#!/usr/bin/env python
import os
import sys
import pandas as pd
import numpy as np
import pyranges as pr
import argparse
def table(region, gwas_minus_region, total_gwas):
pos_cols = "Chromosome Start End".split()
total_region = len(region.drop_duplicates(pos_cols))
tp = region.groupby("Trait").size()
fp = (tp - total_region).abs()
fn = gwas_minus_region.groupby("Trait").size()
tn = ((fn + tp + fp) - total_gwas).abs()
from scipy.stats import gaussian_kde
import numpy as np
import pandas as pd
df = pd.read_table(f, sep="\t")
values = df.CorrelationSum.sort_values()
gk = gaussian_kde(values)
➜ head ~/Downloads/CEU/CEU-22-final.txt
Position(bp) Rate(cM/Mb) Map(cM) Filtered
16489239 0.0 0.0 1
16494187 0.0 0.0 1
16504399 0.0 0.0 1
16855618 0.0 0.0 1
16869887 0.0 0.0 1
16872459 0.0 0.0 1
16890307 0.0 0.0 1
16923693 0.0 0.0 1
index1 = 0
index2 = 0
while index1 < len(posin):
pos = posin[index1]
rs = rsin[index1]
if pos == mappos[index2]:
#the 1000 Genomes site was genotyped as part of the map
results.append((rs, pos, mapgpos[index2]))
index1 = index1 + 1
#!/usr/bin/env python3
import sys, os, gzip, math
import numpy as np
# calculate Wen/Stephens shrinkage LD estimate
gmapfile = gzip.open(sys.argv[1]) # genetic map
indfile = open(sys.argv[2]) #list of individuals
# NE = 11418.0
NE = float(sys.argv[3])
def calc_diag_lean(self, out_fname, out_delim, dynamic_delete=True):
if dynamic_delete == False:
raise Exception('Error: Conversion has been run in lean mode, but with dynamically=False.')
self.dynamic_delete = dynamic_delete
flat.print_log_msg('Start')
#!/usr/bin/env python3
import ldetect.baselib.flat_file_consts as cnst
import ldetect.baselib.flat_file as flat
import ldetect.baselib.binary_search as binsrch
import sys
import os.path
import math
import bisect
# from . import flat_file_consts as cnst
import sys
import csv
import gzip
import time
import math
import bisect
def get_final_partitions(input_config, name, snp_first, snp_last):