| 1 |
""" |
| 2 |
This compares the output of the tabix commandline tool from htslib to |
| 3 |
this version built with the biogo bindings. |
| 4 |
""" |
| 5 |
|
| 6 |
import sys |
| 7 |
import os |
| 8 |
import subprocess |
| 9 |
import gzip |
| 10 |
|
| 11 |
F = sys.argv[1] if len(sys.argv) > 1 else "NA12878.wham.del.vcf.gz" |
| 12 |
|
| 13 |
positions = [] |
| 14 |
for i, x in enumerate(gzip.open(F)): |
| 15 |
if x[0] == "#": continue |
| 16 |
if i > 2000000: break |
| 17 |
positions.append((x.split("\t")[0], int(x.split("\t")[1]))) |
| 18 |
print(positions[:100]) |
| 19 |
print(len(positions)) |
| 20 |
|
| 21 |
p = subprocess.Popen("go build -o main main.go", shell=True) |
| 22 |
p.wait() |
| 23 |
|
| 24 |
def tbxrun(query, chrom, start, end): |
| 25 |
p = subprocess.Popen("tabix %s %s:%d-%d" % (query, chrom, start+1, end), |
| 26 |
shell=True, stdout=subprocess.PIPE) |
| 27 |
return p |
| 28 |
|
| 29 |
|
| 30 |
def btrun(query, chrom, start, end): |
| 31 |
with open("t.bed", "w") as fin: |
| 32 |
fin.write("%s\t%d\t%d" % (chrom, start, end)) |
| 33 |
p = subprocess.Popen("bedtools intersect -b t.bed -a %s" % query, |
| 34 |
shell=True, stdout=subprocess.PIPE) |
| 35 |
try: |
| 36 |
return p.stdout.read().rstrip() |
| 37 |
finally: |
| 38 |
os.unlink("t.bed") |
| 39 |
|
| 40 |
def bxrun(query, chrom, start, end): |
| 41 |
cmd = "./main %s %s %d %d" % (query, chrom, start, end) |
| 42 |
p = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE) |
| 43 |
return p, cmd |
| 44 |
|
| 45 |
for chrom, position in positions: |
| 46 |
print position |
| 47 |
for j in range(position-5, position+5): |
| 48 |
for l in range(1, 3): |
| 49 |
|
| 50 |
|
| 51 |
bxres, cmd = bxrun(F, chrom, j, j + l) |
| 52 |
tbres = tbxrun(F, chrom, j, j + l) |
| 53 |
bxres = bxres.stdout.read().strip() |
| 54 |
tbres = tbres.stdout.read().strip() |
| 55 |
|
| 56 |
|
| 57 |
lbx = len(bxres.split("\n")) if bxres else 0 |
| 58 |
ltb = len(tbres.split("\n")) if tbres else 0 |
| 59 |
|
| 60 |
assert ltb == lbx, (F, chrom, position, j, j + l, ltb, lbx, cmd) |