-
Notifications
You must be signed in to change notification settings - Fork 2
/
helpers.py
67 lines (54 loc) · 2.15 KB
/
helpers.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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# Ways to import the below functions
# from my_tool.helpers import read_gtf, get_exon_boundaries, is_exon, get_gene_name
# from my_tool.splice_graph import SpliceGraph, read_sqtl_junctions, check_snp_in_junctions
# from my_tool.gwas_sno import GWASSNO, read_gwas_snps
def read_gwas_snp_file(file_path):
"""
Reads a GWAS SNP file and returns a list of dictionaries with the data.
Args:
file_path (str): Path to the GWAS SNP file.
Returns:
A list of dictionaries with the data from the file.
"""
with open(file_path, 'r') as f:
header = f.readline().strip().split('\t') # Read and parse the header line
rows = [] # Initialize an empty list to store the data
for line in f:
values = line.strip().split('\t')
row_dict = {header[i]: values[i] for i in range(len(header))}
rows.append(row_dict)
return rows
def read_leafcutter_sQTL_file(file_path):
"""
Reads a LeafCutter sQTL file and returns a list of dictionaries with the data.
Args:
file_path (str): Path to the LeafCutter sQTL file.
Returns:
A list of dictionaries with the data from the file.
"""
with open(file_path, 'r') as f:
header = f.readline().strip().split('\t') # Read and parse the header line
sqtls = [] # Initialize an empty list to store the data
for line in f:
values = line.strip().split('\t')
row_dict = {header[i]: values[i] for i in range(len(header))}
sqtls.append(row_dict)
return sqtls
def read_moloc_sqtl_file(file_path):
"""
Reads a MOLoc sQTL file and returns a list of dictionaries with the data.
Args:
file_path (str): Path to the MOLoc sQTL file.
Returns:
A list of dictionaries with the data from the file.
"""
sqtl_list = []
with open(file_path, 'r') as f:
header = f.readline().strip().split('\t')
for line in f:
data = line.strip().split('\t')
sqtl_dict = {}
for i, value in enumerate(data):
sqtl_dict[header[i]] = value
sqtl_list.append(sqtl_dict)
return sqtl_list