How to calculate the value of accessibility

We used the following script to calculate the value of accessibility.
First, we find the region coordinates on which we focused using Blat search and then executed the script.

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
48
49
50
# -*- coding: utf-8 -*-

"""
Calculate average of signal whose the region the user focuse on from Bedgraph format.
"""
__version__ = "1.00"
__date__ = "25 Jun 2022"

import sys

def averageBedgraph(filename, chromosome, start, end):
"""
@function averageBedgraph();
Calculate average of signal whose the region the user focuse on from Bedgraph format.
@param {string} filename : Bedgraph file path
@param {string} chromosome : chromosome number which the user focuse
@param {int} start : start point
@param {int} end : end point
"""

total = 0
with open(filename) as lines:
for line in lines:
c, s, e, v = line.split()
if c != chromosome:
continue
s, e, v = int(s), int(e), int(v)
if s <= start and end <= e:
total += (end - start) * v
elif s <= start < e:
total += (e - start) * v
elif start < s and e <= end:
total += (e - s) * v
elif s < end <= e:
total += (end - s) * v
elif end < s:
break
print('average : %s' % (total / (end - start)))
print('done')

if __name__ == '__main__':
argvs = sys.argv
argc = len(argvs)

if (argc != 5): # Checking input
print("USAGE : python3 averageBedgraph.py <INPUT_FILE> <CHROMOSOME> <START> <END>")
quit()

averageBedgraph(str(argvs[1]),str(argvs[2]),int(argvs[3]),int(argvs[4]))
quit()

Example of usage:

1
python3 averageBedgraph.py example.bedgraph chr1 10150 10250

Output of usage:

1
2
average : 12.74
done

Powered by Hexo and Hexo-theme-hiker

Copyright © 2022 - 2022 MaChIAto All Rights Reserved.

UV : | PV :