Skip to content

Instantly share code, notes, and snippets.

View tomatoiscoding's full-sized avatar
🎯
Focusing

Beilei Bian tomatoiscoding

🎯
Focusing
View GitHub Profile
cut -d ',' -f1 FDADOS_CENSO2014.csv|tail-n +2|sort|uniq -c|sort -nr
@tomatoiscoding
tomatoiscoding / re.py
Created October 14, 2016 03:21
some tricks for regular expression with python
# this a list in python,\n represents newline
a = ['1', '2', '3', '4', '\n']
# convert list to string
a = ''.join(a)
# delete '\n'
a = a.rstrip('\n')
# convert string to integer
a = map(int, a)
# splitline
a = ['1', '2', '3', '4', '\n', '5', '6', '7', '8']
@tomatoiscoding
tomatoiscoding / index.r
Created October 13, 2016 14:52
vector intersect and return index
a <- c(1:10)
b <- c(1,3,5,11,12,13,14)
c <- intersect(a, b)
index.a <- match(c, a) # [1] 1 3 5
index.b <- match(c, b) # [1] 1 2 3
@tomatoiscoding
tomatoiscoding / convert.r
Last active October 14, 2016 08:36
some tricks for regular expression in R
# convert charactor vector to a matrix
a <- rep(NA, 2) # generate a vector
a[1] <- '1, 2, 3, 4'
a[2] <- '5, 6, 7, 8'
a <- gsub('\\s', '', a)
b <- matrix(NA, length(a), 4)
for(i in 1:length(a)) {
b[i, ] <- as.numeric(as.matrix(strsplit(a[i], ',')[[1]]))
}
@tomatoiscoding
tomatoiscoding / replace.py
Last active October 20, 2016 04:04
replace string with python
ped = open('/data/bbl/bbl/bbl/ped/nnped.txt')
try:
peds = ped.readlines()
finally:
ped.close()
outfile = open('/data/bbl/bbl/bbl/ped/pedxin.txt', 'w')
for ped in peds:
for i in range(0, 605997):
this_snp = ped[i*4] + ped[i*4 + 1] + ped[i*4 + 2]
outfile.write(this_snp + '\t')