-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathsplit_egi.py
47 lines (38 loc) · 1.31 KB
/
split_egi.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# -*- coding: utf-8 -*-
"""
Created on Mon Nov 19 11:41:41 2018
@author: YudongCai
@Email: [email protected]
"""
import click
@click.command()
@click.option('--inprefix')
@click.option('--outprefix')
@click.option('--winsize', type=int)
def main(inprefix, outprefix, winsize):
with open(f'{inprefix}.snp') as f1, \
open(f'{inprefix}.geno') as f2, \
open(f'{outprefix}.regionidx', 'w') as f_region:
idx = -1
f3 = open(f'{outprefix}.{idx}.snp', 'w')
f4 = open(f'{outprefix}.{idx}.geno', 'w')
for line1 in f1:
tline = line1.strip().split()
chrom = tline[1]
pos = int(tline[3])
nbin = pos // winsize
if nbin != idx:
print(f'{chrom}\t{idx * (winsize)+1}\t{(idx+1) * winsize}\t{idx}\n')
f_region.write(f'{chrom}\t{idx * (winsize)+1}\t{(idx+1) * winsize}\t{idx}\n')
f3.close()
f4.close()
idx = nbin
f3 = open(f'{outprefix}.{chrom}.{idx}.snp', 'w')
f4 = open(f'{outprefix}.{chrom}.{idx}.geno', 'w')
f3.write(line1)
line2 = f2.readline()
f4.write(line2)
f3.close()
f4.close()
if __name__ == '__main__':
main()