-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathidMapping.py
35 lines (23 loc) · 990 Bytes
/
idMapping.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
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Fri Jun 16 14:00:20 2023
@author: Ozan Ozisik
Converts IDs of genes
"""
import pandas as pd
def getIDMappingDict(mappingFilePath, convertFrom, convertTo):
df=pd.read_csv(mappingFilePath, sep="\t")
df=df[[convertFrom, convertTo]]
df=df.dropna(axis=0)
if('NCBI Gene ID(supplied by NCBI)' in df.columns):
df['NCBI Gene ID(supplied by NCBI)']= df['NCBI Gene ID(supplied by NCBI)'].astype(int)
df['NCBI Gene ID(supplied by NCBI)']= df['NCBI Gene ID(supplied by NCBI)'].astype(str)
df=df.set_index(convertFrom)
idMappingDict=df.to_dict()[convertTo]
return idMappingDict
def mapIDsInGeneGroupsDict(geneGroupsDict, idMappingDict):
idMappedGeneGroupsDict=dict()
for group, genesList in geneGroupsDict.items():
idMappedGeneGroupsDict[group]=[ idMappingDict[g] for g in genesList if g in idMappingDict.keys()]
return idMappedGeneGroupsDict