Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
112 changes: 112 additions & 0 deletions Osteoarthritis.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
## TODO: Scores should be LOD risk ratios I think...
import pathlib
import json
import os
import pandas as pd
class Osteo:

def __init__(self):
pass

def read_json_osteo(self):

# filename = pathlib.Path(path).name
#print(filename)
with open("/Users/tanvisingh/Documents/Geromics/covcheck/tests/data/Osteoarithritis.json") as f:
data = json.load(f)

return data


def read_json_individual(self):

# filename = pathlib.Path(path).name
#print(filename)
with open("/Users/tanvisingh/Documents/Geromics/covcheck/tests/data/dan_osteo.json") as f:
data = json.load(f)

return data

def calculate_score(self,count,OR):
score = float(count*OR)
return score

def display_score(self,snp,ORatio,Effect_Allele,Geneotype,scores):
df = pd.DataFrame()
df['snp']= snp
df['Effect_Allele']=Effect_Allele
df['Geneotype']=Geneotype
df['ORatio']= ORatio
df['scores']= scores
print("Snp details")
print("-----------------------")
print(df)

def score_report(self,snp,scores):
l=len(snp)
result=sum(scores)/l
print()
if result < 1:
print("Your score is ", result)
print("You are at less risk of developing Osteoarthritis")
else:
print("Your score is " , result)
print("You are at high risk of developing Osteoarthritis")




def parse_data_json(self,data,data1):
scores = []
snp = []
ORatio = []
Effect_Allele = []
Geneotype = []
# data = read_json_osteo()
# data1 = read_json_individual()

k = 0
for i in data['groups']:

if i['group_id'] == "44" and data1['age'] == 44:
#print("Hello", list(data1['snps'].keys())[0])
#print("Bye", list(i['snps'].keys())[0])
l=len(list(i['snps'].keys()))
l1=len(list(data1['snps'].keys()))
#print(l1)
for k in range(l):
for m in range(l1):
a = str(list(data1['snps'].keys())[m])
b = str(list(i['snps'].keys())[k])
#print ("a=" +a , "b="+b)
if a in b:
c1 = list(data1['snps'].values())[m]
c2 = list(i['snps'].values())[k]['effect_allele']
#print("match a=" + a, "b=" + b)
#print("----------------------------")
snp.append(a)
Effect_Allele.append(c2)
Geneotype.append(c1)
if c2 in c1:
count=c1.count(c2)
OR=list(i['snps'].values())[k]['OR']
score = float(count * OR)
s = score
# print(s)
ORatio.append(OR)
scores.append(s)
else:
s=0
OR = list(i['snps'].values())[k]['OR']
ORatio.append(OR)
scores.append(s)

return snp,Effect_Allele,Geneotype,ORatio,scores


snp_osteo = Osteo()
data2=snp_osteo.read_json_osteo()
data3=snp_osteo.read_json_individual()
snp,Effect_Allele,Geneotype,ORatio,scores = snp_osteo.parse_data_json(data2,data3)
snp_osteo.display_score(snp,ORatio,Effect_Allele,Geneotype,scores)
snp_osteo.score_report(snp,scores)
24 changes: 24 additions & 0 deletions tests/data/Osteoarithritis.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"trait": "Osteoarthritis",
"groups": [
{
"group_id": "age",
"note": "This is literally the first idea that came to mind..."
},
{
"group_id": "44",
"snps": {
"rs6976":{"effect_allele": "T", "other_allele": "C", "OR": 1.09},
"rs11177": {"effect_allele": "A", "other_allele": "G", "OR": 1.09},
"rs4836732":{"effect_allele": "C", "other_allele": "T", "OR": 1.04},
"rs9350591":{"effect_allele": "T", "other_allele": "C", "OR": 1.09},
"rs10492367":{"effect_allele": "T", "other_allele": "G", "OR": 1.06},
"rs835487":{"effect_allele": "G", "other_allele": "A", "OR": 1.05},
"rs12107036":{"effect_allele": "G", "other_allele": "A", "OR": 1.05},
"rs8044769":{"effect_allele": "C", "other_allele": "T", "OR": 1.07},
"rs10948172":{"effect_allele": "G", "other_allele": "A", "OR": 1.08}
}

}
]
}
19 changes: 19 additions & 0 deletions tests/test_snp.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import sys
import unittest
sys.path.insert(0, '/Users/tanvisingh/Documents/Geromics/covcheck')
from Osteoarthritis import Osteo

class TestSNP_age(unittest.TestCase):
def test_snp(self):
Ot = Osteo()
data = Ot.read_json_individual()
assert data['age'] == 44
assert list(data['snps'].keys())[0]== 'rs6976'
assert list(data['snps'].keys())[0] == 'rs835488'
assert data['id'] =='dan.geromics'
data1= Ot.read_json_osteo()
assert data1['trait']=='Osteoarthritis'
#assert list(data1['groups'])[1]== '44'
if __name__ == '__main__':
unittest.main()
test_snp()