forked from ethanagb/SiLiCO
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgetRandomPosition.py
33 lines (29 loc) · 1.11 KB
/
getRandomPosition.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
#################################
######### SiLiCO v. 1.0 #########
### (c)2016 Ethan A. G. Baker ###
##### ethanagbaker@pitt.edu #####
#################################
import numpy as np
def getRandomPosition(buf,genomeLength, thresholdDict,names,lengthDict):
loopController = True
while loopController == True:
y = np.random.randint(buf, genomeLength-buf)
#generate a name variable, check regions until something is satisfied...
for chrom in thresholdDict:
k = 1 #a counter to get the next chromosome threshold.
if chrom == 'chr1':
t=0
r=thresholdDict[chrom]
else:
t=thresholdDict[chrom]-lengthDict[chrom]
r=thresholdDict[chrom]
if t+buf <= y <= r-buf:
loopController = False
break
k += 1
if k==len(names):
loopController = False
break #would be out of bounds, so time to stop this loop.
return y
if __name__ == "__main__":
getRandomPosition(buf,genomeLength, thresholdDict,names)