forked from ethanagb/pblibsim
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgenerate_chrdist.py
executable file
·35 lines (31 loc) · 1.2 KB
/
generate_chrdist.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
import numpy as np
with open('namelist','r') as infile:
lines = infile.readlines()
names =[str(e.strip()) for e in lines]
infile.close()
with open('chrdist.td','w+') as outfile2:
for chrom in names:
#Strip header lines from fasta for processing
with open(str(chrom) + '.fa','r') as infile, open(str(chrom) + '.noheader.fa','w+') as outfile:
for i, line in enumerate(infile):
if i >= 0:
if not line.startswith('>'):
outfile.write(line)
infile.close()
outfile.close()
#Remove any newline chars, remove undefined nts, make all nts uppercase for processing.
with open(str(chrom) + '.noheader.fa','r') as infile, \
open(str(chrom) + '.clean.fa','w+') as outfile:
lines = infile.readlines()
x = map(str.strip,lines)
seq = ''
for line in x:
y = str(line)
z = y.upper()
w = z.replace('N','')
seq += w
outfile.write(seq)
outfile2.write(str(chrom) + '\t' + str(len(seq)) + '\n')
infile.close()
outfile.close()
outfile2.close()