1
|
from datetime import datetime
|
2
|
|
3
|
rels = dict(issupplementto="IsSupplementTo", issupplementedby="IsSupplementedBy", references="References",
|
4
|
isreferencedby="IsReferencedBy")
|
5
|
|
6
|
pid_resolver = {
|
7
|
"pdb": "http://www.rcsb.org/pdb/explore/explore.do?structureId=%s",
|
8
|
"ncbi-n": "http://www.ncbi.nlm.nih.gov/gquery/?term=%s",
|
9
|
"pmid": "http://www.ncbi.nlm.nih.gov/pubmed/%s",
|
10
|
"pmcid": "http://www.ncbi.nlm.nih.gov/pmc/articles/%s",
|
11
|
"pubmedid": "http://www.ncbi.nlm.nih.gov/pubmed/%s",
|
12
|
"doi": "http://dx.doi.org/%s",
|
13
|
"genbank": "http://www.ncbi.nlm.nih.gov/nucest/%s?report=genbank",
|
14
|
"nuccore": "http://www.ncbi.nlm.nih.gov/nucest/%s?report=genbank",
|
15
|
"swiss-prot": "http://www.ncbi.nlm.nih.gov/nucest/%s?report=genbank",
|
16
|
"arrayexpress": "http://www.ncbi.nlm.nih.gov/nucest/%s?report=genbank",
|
17
|
"biomodels": "http://www.ncbi.nlm.nih.gov/nucest/%s?report=genbank",
|
18
|
"bmrb": "http://www.ncbi.nlm.nih.gov/nucest/%s?report=genbank",
|
19
|
"ena": "http://www.ncbi.nlm.nih.gov/nucest/%s?report=genbank",
|
20
|
"geo": "http://www.ncbi.nlm.nih.gov/nucest/%s?report=genbank",
|
21
|
"ensembl": "http://www.ncbi.nlm.nih.gov/nucest/%s?report=genbank",
|
22
|
"mgi": "http://www.ncbi.nlm.nih.gov/nucest/%s?report=genbank",
|
23
|
"bind": "http://www.ncbi.nlm.nih.gov/nucest/%s?report=genbank",
|
24
|
"pride": "http://www.ncbi.nlm.nih.gov/nucest/%s?report=genbank",
|
25
|
"ddbj": "http://www.ncbi.nlm.nih.gov/nucest/%s?report=genbank",
|
26
|
"bioproject": "http://www.ncbi.nlm.nih.gov/nucest/%s?report=genbank",
|
27
|
"embl": "http://www.ncbi.nlm.nih.gov/nucest/%s?report=genbank",
|
28
|
"sra": "http://www.ncbi.nlm.nih.gov/nucest/%s?report=genbank",
|
29
|
}
|
30
|
|
31
|
|
32
|
def resolveIdentifier(pid, pid_type):
|
33
|
if pid_type != None:
|
34
|
if pid_type.lower() in pid_resolver:
|
35
|
return pid_resolver[pid_type.lower()] % pid
|
36
|
else:
|
37
|
return "http://identifiers.org/%s:%s" % (pid_type, pid)
|
38
|
|
39
|
|
40
|
def get_scholix_resource(item):
|
41
|
title = ''
|
42
|
if 'title' in item:
|
43
|
title = item.title
|
44
|
if len(title):
|
45
|
if title[0] == '"' and title[-1] == '"':
|
46
|
title = title[1:-1]
|
47
|
identifier = [dict(ID=x.identifier, IDScheme=x.schema, IDURL=resolveIdentifier(x.identifier, x.schema)) for x in
|
48
|
item.identifier]
|
49
|
identifier.append(dict(ID=item.dnetIdentifier, IDScheme='D-Net Identifier', IDURL='http://scholexplorer.openaire.eu/index.html#/detail/%s'%item.dnetIdentifier))
|
50
|
creator = []
|
51
|
if 'creator' in item:
|
52
|
creator = [dict(Name=x.name) for x in item.creator]
|
53
|
publicationDate = None
|
54
|
if 'publicationDate' in item:
|
55
|
publicationDate = item.publicationDate
|
56
|
publisher = []
|
57
|
if 'publisher' in item:
|
58
|
publisher = [dict(name= x.name) for x in item.publisher]
|
59
|
c_type = item.objectType
|
60
|
if item.objectType == 'publication':
|
61
|
c_type = 'literature'
|
62
|
|
63
|
resource = dict(Title=title, Identifier=identifier, Creator=creator, PublicationDate= publicationDate, Publisher = publisher, Type= c_type)
|
64
|
|
65
|
return resource
|
66
|
|
67
|
|
68
|
def create_response(response, current_page):
|
69
|
result = {'totalLinks': response.hits.total, 'currentPage': current_page,
|
70
|
'totalPages': 1 + response.hits.total / 100, 'result': []}
|
71
|
now = datetime.now()
|
72
|
for item in response.hits:
|
73
|
current_item = {'LinkPublicationDate': now.strftime("%Y-%m-%d"), 'HarvestedDate': now.strftime("%Y-%m-%d"),
|
74
|
"LinkProvider": []}
|
75
|
for linkProvider in item.linkprovider:
|
76
|
current_item['LinkProvider'].append(dict(name=linkProvider.name,
|
77
|
identifier=[dict(ID=x.identifier, IDScheme=x.schema) for x in
|
78
|
linkProvider.identifiers]))
|
79
|
|
80
|
rel_sub_type = rels.get(item.relationship.name.lower(), "IsRelatedTo")
|
81
|
current_item['RelationshipType'] = dict(Name=item.relationship.name, SubType=rel_sub_type,
|
82
|
SubTypeSchema=item.relationship.schema)
|
83
|
|
84
|
current_item['source'] = get_scholix_resource(item.source)
|
85
|
current_item['target'] = get_scholix_resource(item.target)
|
86
|
|
87
|
result['result'].append(current_item)
|
88
|
|
89
|
return result
|