-
Notifications
You must be signed in to change notification settings - Fork 6
/
codingRNA.py
55 lines (47 loc) · 2.14 KB
/
codingRNA.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
# Maps genes to ensembl transcripts and to uniprot ids
# Requires:
# ftp://ftp.ensembl.org/pub/grch37/release-98/tsv/homo_sapiens/Homo_sapiens.GRCh37.85.uniprot.tsv.gz
# ensemble gene to hgnc symbol mapping from https://www.genenames.org/download/custom/
import wget
import gzip
import os
import metadata
import pandas as pd
from datetime import date
from atomwrappers import *
source = "ftp://ftp.ensembl.org/pub/grch37/release-98/tsv/homo_sapiens/Homo_sapiens.GRCh37.85.uniprot.tsv.gz"
dataset = "Homo_sapiens.GRCh37.85.uniprot.tsv.gz"
if not dataset in os.listdir("raw_data/"):
wget.download(source, "raw_data")
data = pd.read_csv("raw_data/"+dataset, sep="\t",dtype=str)
mapping_data = pd.read_csv("raw_data/symbol2entrez_mapping.txt", sep="\t")
# Approved symbol Ensembl gene ID
data.rename(columns = {'gene_stable_id':'Ensembl gene ID'}, inplace = True)
col = ["Ensembl gene ID","transcript_stable_id","xref"]
data = data[col]
df = data.join(mapping_data.set_index('Ensembl gene ID'), on='Ensembl gene ID')
df = df.dropna()
print("\nStarted importing\n")
rnas = []
genes = []
proteins = []
with open("dataset/codingRNA_{}.scm".format(str(date.today())), 'w') as f:
for i in range(len(df)):
rna = df.iloc[i]["transcript_stable_id"]
gene = df.iloc[i]['Approved symbol'].strip().upper()
prot = df.iloc[i]["xref"]
rnas.append(rna)
genes.append(gene)
proteins.append(prot)
if gene:
trans = CEvaluationLink(CPredicateNode("transcribed_to"), CListLink(CGeneNode(gene),CRNANode(rna)))
f.write(trans.recursive_print() + "\n")
if rna:
trans = CEvaluationLink(CPredicateNode("translated_to"), CListLink(CRNANode(rna), ProteinNode(prot)))
f.write(trans.recursive_print() + "\n")
expr = CEvaluationLink(CPredicateNode("expresses"), CListLink(CGeneNode(gene), ProteinNode(prot)))
f.write(expr.recursive_print() + "\n")
version = dataset.split(".")[1]
script = "https://github.com/MOZI-AI/knowledge-import/codingRNA.py"
metadata.update_meta("codingRNA:{}".format(version),dataset,script,genes=len(set(genes)),rna=len(set(rnas)))
print("Done")