-
Notifications
You must be signed in to change notification settings - Fork 2
/
create_metadata_rdf.py
185 lines (153 loc) · 7.74 KB
/
create_metadata_rdf.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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
# -*- coding: utf-8 -*-
"""
Created on Tue Mar 21 12:33:50 2023
@author: Lucian
"""
import os
import libsbml
from biosimulators_utils.ref.utils import get_reference
from biosimulators_utils.config import get_config
from biosimulators_utils.ref.utils import get_pubmed_central_open_access_graphics
from biosimulators_utils.omex_meta.io import BiosimulationsOmexMetaWriter
from biosimulators_utils.omex_meta.data_model import OmexMetadataOutputFormat
import Bio.Entrez
Bio.Entrez.email = '[email protected]'
import operator, glob
import requests
import time
class NonStandardRef():
""" Journal article not from pubmed or doi
"""
citation: str = None
uri: str = None
title: str = None
authors: str = None
date: str = None
pubmed_central_id = None
def __init__(self, citation, uri, title):
self.citation = citation
self.uri = uri
self.title = title
def get_citation(self):
return self.citation
def get_uri(self):
return self.uri
no_pubmed_or_doi = {
"BIOMD0000000358" : NonStandardRef('Stortelder, Walter JH, Pieter Wilhelm Hemker, and Hendrik Coenraad Hemker. "Mathematical modelling in blood coagulation: simulation and parameter estimation." Modelling, Analysis and Simulation [MAS] R 9720 (1997).', "http://www.narcis.nl/publication/RecordID/oai:cwi.nl:4725", "Mathematical modelling in blood coagulation : simulation and parameter estimation"),
"BIOMD0000000454" : NonStandardRef('Smallbone, Kieran. "Metabolic Control Analysis: Rereading Reder." arXiv preprint arXiv:1305.6449 (2013).', "http://arxiv.org/pdf/1305.6449v1.pdf", "Metabolic Control Analysis: Rereading Reder."),
"BIOMD0000000455" : NonStandardRef('Smallbone, Kieran. "Metabolic Control Analysis: Rereading Reder." arXiv preprint arXiv:1305.6449 (2013).', "http://arxiv.org/pdf/1305.6449v1.pdf", "Metabolic Control Analysis: Rereading Reder."),
"BIOMD0000000456" : NonStandardRef('Smallbone, Kieran. "Metabolic Control Analysis: Rereading Reder." arXiv preprint arXiv:1305.6449 (2013).', "http://arxiv.org/pdf/1305.6449v1.pdf", "Metabolic Control Analysis: Rereading Reder."),
"BIOMD0000000882" : NonStandardRef('Munz, Philip, et al. "When zombies attack!: mathematical modelling of an outbreak of zombie infection." Infectious disease modelling research progress 4 (2009): 133-150.', "http://identifiers.org/isbn/ISBN:1607413477", "When zombies attack!: Mathematical modelling of an outbreak of zombie infection"),
"BIOMD0000001045" : NonStandardRef('Smith, David, and Lang Moore. "The SIR model for spread of disease-the differential equation model." Convergence (2004).', "https://www.maa.org/press/periodicals/loci/joma/the-sir-model-for-spread-of-disease-the-differential-equation-model", "The SIR Model for Spread of Disease - The Differential Equation Model"),
"BIOMD0000001070" : NonStandardRef('Kong, Xiangzhe, Huang, Wenbing, and Yang Liu. "Conditional Antibody Design as 3D Equivariant Graph Translation.", arXiv preprint arXiv:2208.06073 (2022).', "http://identifiers.org/doi/10.48550/arXiv.2208.06073", "Conditional Antibody Design as 3D Equivariant Graph Translation."),
}
def parseDocAndAddToMetadata(filename, metadata, master, pubmedIDs, doiIDs):
doc = libsbml.readSBMLFromFile(filename)
model = doc.getModel()
if master:
note = None
notes = model.getNotes()
if notes:
note = notes.getChild(0).toXMLString()
metadata['description'] = note
metadata['title'] = model.getName()
annotations = model.getAnnotation()
cvterms = libsbml.CVTermList()
libsbml.RDFAnnotationParser.parseRDFAnnotation(annotations, cvterms)
for cv in range(cvterms.getSize()):
cvterm = cvterms.get(cv)
for r in range(cvterm.getNumResources()):
rURI = cvterm.getResourceURI(r)
if "pubmed/" in rURI:
pmid = rURI.split("/")[-1]
pubmedIDs.add(pmid)
if "identifiers.org/doi/" in rURI:
uripos = rURI.find("org/doi/")
doiIDs.add(rURI[uripos+8:])
def addCitationsToMetadata(pubmedIDs, doiIDs, masterID, metadata, id, temp_entry_dir):
citations = []
mastercitation = None
if "pubmed" in masterID:
mastercitation = get_reference(pubmed_id=masterID.split("/")[-1])
time.sleep(2.0)
elif "doi" in masterID:
doivec = masterID.split("doi/")
mastercitation = get_reference(doi=doivec[-1])
time.sleep(2.0)
else:
mastercitation = no_pubmed_or_doi[id]
if not mastercitation:
mastercitation = no_pubmed_or_doi[id]
for pmid in pubmedIDs:
citation = get_reference(pubmed_id=pmid)
citations.append(citation)
time.sleep(2.0)
for doiID in doiIDs:
citation = get_reference(doi=doiID)
citations.append(citation)
time.sleep(2.0)
if len(citations)==0:
citations.append(mastercitation)
citations = sorted(citations, key=lambda x : x.get_citation())
for citation in citations:
cite = {
"uri": citation.get_uri(),
"label": citation.get_citation(),
}
metadata['citations'].append(cite)
# if citation.pubmed_central_id:
# thumbnails = get_pubmed_central_open_access_graphics(
# citation.pubmed_central_id,
# temp_entry_dir,
# )
# fileList = glob.glob(temp_entry_dir + '/*.tar.gz')
# # Iterate over the list of filepaths & remove each file.
# for filePath in fileList:
# os.remove(filePath)
# metadata['thumbnails'] = [os.path.relpath(thumbnail.filename, temp_entry_dir).replace("\\", "/") for thumbnail in thumbnails]
if mastercitation.title:
metadata['title'] = mastercitation.title
if mastercitation.authors:
metadata['authors'] = mastercitation.authors
if mastercitation.date:
metadata['date'] = mastercitation.date
def addThumbnailToMetadata(metadata, temp_entry_dir):
for root, dirs, files in os.walk(temp_entry_dir):
for file in files:
if file[-4:] == ".png":
if 'thumbnails' not in metadata:
metadata['thumbnails'] = []
metadata['thumbnails'].append(file)
def getMasterRefFromBiomodels(id):
req = requests.post("https://www.ebi.ac.uk/biomodels/" + id + "?format=json")
req.raise_for_status()
res = req.json()
return res["publication"]["link"]
def run(id, sbml_filenames, temp_entry_dir, sbml_master):
metadata = {
"combine_archive_uri": 'http://omex-library.org/' + id + '.omex',
"uri": '.',
'citations': [],
'keywords': [
'Biomodels',
],
# 'contributors': ["The Biomodels Curation Team", "The Center for Reproducible Biomedical Modeling"]
}
pubmedIDs = set()
doiIDs = set()
masterID = getMasterRefFromBiomodels(id)
if "http://identifiers.org/pubmed/24285357" == masterID:
masterID = "http://identifiers.org/pubmed/24757149"
if "http://identifiers.org/pubmed/25771250" == masterID:
masterID = "http://identifiers.org/pubmed/26148348"
for filename in sbml_filenames:
master = False
if sbml_master in filename:
master = True
parseDocAndAddToMetadata(filename, metadata, master, pubmedIDs, doiIDs)
addCitationsToMetadata(pubmedIDs, doiIDs, masterID, metadata, id, temp_entry_dir)
addThumbnailToMetadata(metadata, temp_entry_dir)
metadata_filename = os.path.join(temp_entry_dir, 'metadata.rdf')
config = get_config()
# config.OMEX_METADATA_OUTPUT_FORMAT = OmexMetadataOutputFormat.turtle
BiosimulationsOmexMetaWriter().run([metadata], metadata_filename, config=config)