File size: 13,785 Bytes
90d8750 |
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 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 |
# coding=utf-8
# Copyright 2022 The HuggingFace Datasets Authors and the current dataset script contributor.
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import xml.etree.ElementTree as ET
from typing import Dict, Iterator, List, Tuple
import datasets
from .bigbiohub import kb_features
from .bigbiohub import BigBioConfig
from .bigbiohub import Tasks
_LANGUAGES = ['English']
_PUBMED = True
_LOCAL = False
_CITATION = """\
@Article{Bagewadi2014,
author={Bagewadi, Shweta
and Bobi{\'{c}}, Tamara
and Hofmann-Apitius, Martin
and Fluck, Juliane
and Klinger, Roman},
title={Detecting miRNA Mentions and Relations in Biomedical Literature},
journal={F1000Research},
year={2014},
month={Aug},
day={28},
publisher={F1000Research},
volume={3},
pages={205-205},
keywords={MicroRNAs; corpus; prediction algorithms},
abstract={
INTRODUCTION: MicroRNAs (miRNAs) have demonstrated their potential as post-transcriptional
gene expression regulators, participating in a wide spectrum of regulatory events such as
apoptosis, differentiation, and stress response. Apart from the role of miRNAs in normal
physiology, their dysregulation is implicated in a vast array of diseases. Dissection of
miRNA-related associations are valuable for contemplating their mechanism in diseases,
leading to the discovery of novel miRNAs for disease prognosis, diagnosis, and therapy.
MOTIVATION: Apart from databases and prediction tools, miRNA-related information is largely
available as unstructured text. Manual retrieval of these associations can be labor-intensive
due to steadily growing number of publications. Additionally, most of the published miRNA
entity recognition methods are keyword based, further subjected to manual inspection for
retrieval of relations. Despite the fact that several databases host miRNA-associations
derived from text, lower sensitivity and lack of published details for miRNA entity
recognition and associated relations identification has motivated the need for developing
comprehensive methods that are freely available for the scientific community. Additionally,
the lack of a standard corpus for miRNA-relations has caused difficulty in evaluating the
available systems. We propose methods to automatically extract mentions of miRNAs, species,
genes/proteins, disease, and relations from scientific literature. Our generated corpora,
along with dictionaries, and miRNA regular expression are freely available for academic
purposes. To our knowledge, these resources are the most comprehensive developed so far.
RESULTS: The identification of specific miRNA mentions reaches a recall of 0.94 and
precision of 0.93. Extraction of miRNA-disease and miRNA-gene relations lead to an
F1 score of up to 0.76. A comparison of the information extracted by our approach to
the databases miR2Disease and miRSel for the extraction of Alzheimer's disease
related relations shows the capability of our proposed methods in identifying correct
relations with improved sensitivity. The published resources and described methods can
help the researchers for maximal retrieval of miRNA-relations and generation of
miRNA-regulatory networks. AVAILABILITY: The training and test corpora, annotation
guidelines, developed dictionaries, and supplementary files are available at
http://www.scai.fraunhofer.de/mirna-corpora.html.
},
note={26535109[pmid]},
note={PMC4602280[pmcid]},
issn={2046-1402},
url={https://pubmed.ncbi.nlm.nih.gov/26535109},
language={eng}
}
"""
_DATASETNAME = "mirna"
_DISPLAYNAME = "miRNA"
_DESCRIPTION = """\
The corpus consists of 301 Medline citations. The documents were screened for
mentions of miRNA in the abstract text. Gene, disease and miRNA entities were manually
annotated. The corpus comprises of two separate files, a train and a test set, coming
from 201 and 100 documents respectively.
"""
_HOMEPAGE = "https://www.scai.fraunhofer.de/en/business-research-areas/bioinformatics/downloads/download-mirna-test-corpus.html"
_LICENSE = 'Creative Commons Attribution Non Commercial 3.0 Unported'
_BASE = "https://www.scai.fraunhofer.de/content/dam/scai/de/downloads/bioinformatik/miRNA/miRNA-"
_URLs = {
"source": {
"train": _BASE + "Train-Corpus.xml",
"test": _BASE + "Test-Corpus.xml",
},
"bigbio_kb": {
"train": _BASE + "Train-Corpus.xml",
"test": _BASE + "Test-Corpus.xml",
},
}
_SUPPORTED_TASKS = [Tasks.NAMED_ENTITY_RECOGNITION, Tasks.NAMED_ENTITY_DISAMBIGUATION]
_SOURCE_VERSION = "1.0.0"
_BIGBIO_VERSION = "1.0.0"
class miRNADataset(datasets.GeneratorBasedBuilder):
"""mirna"""
SOURCE_VERSION = datasets.Version(_SOURCE_VERSION)
BIGBIO_VERSION = datasets.Version(_BIGBIO_VERSION)
BUILDER_CONFIGS = [
BigBioConfig(
name="mirna_source",
version=SOURCE_VERSION,
description="mirna source schema",
schema="source",
subset_id="mirna",
),
BigBioConfig(
name="mirna_bigbio_kb",
version=BIGBIO_VERSION,
description="mirna BigBio schema",
schema="bigbio_kb",
subset_id="mirna",
),
]
DEFAULT_CONFIG_NAME = "mirna_source"
def _info(self):
if self.config.schema == "source":
features = datasets.Features(
{
"passages": [
{
"document_id": datasets.Value("string"),
"type": datasets.Value("string"),
"text": datasets.Value("string"),
"offset": datasets.Value("int32"),
"entities": [
{
"id": datasets.Value("string"),
"offsets": [[datasets.Value("int32")]],
"text": [datasets.Value("string")],
"type": datasets.Value("string"),
"normalized": [
{
"db_name": datasets.Value("string"),
"db_id": datasets.Value("string"),
}
],
}
],
}
]
}
)
elif self.config.schema == "bigbio_kb":
features = kb_features
return datasets.DatasetInfo(
description=_DESCRIPTION,
features=features,
supervised_keys=None,
homepage=_HOMEPAGE,
license=str(_LICENSE),
citation=_CITATION,
)
def _split_generators(self, dl_manager):
"""Returns SplitGenerators."""
my_urls = _URLs[self.config.schema]
path_xml_train = dl_manager.download(my_urls["train"])
path_xml_test = dl_manager.download(my_urls["test"])
return [
datasets.SplitGenerator(
name=datasets.Split.TRAIN,
# These kwargs will be passed to _generate_examples
gen_kwargs={
"filepath": path_xml_train,
"split": "train",
},
),
datasets.SplitGenerator(
name=datasets.Split.TEST,
# These kwargs will be passed to _generate_examples
gen_kwargs={
"filepath": path_xml_test,
"split": "test",
},
),
]
def _get_passages_and_entities(self, d) -> Tuple[List[Dict], List[List[Dict]]]:
sentences: List[Dict] = []
entities: List[List[Dict]] = []
relations: List[List[Dict]] = []
text_total_length = 0
po_start = 0
# Get sentences of the document
for _, s in enumerate(d):
# annotation used only for document indexing
if s.attrib["text"] is None or len(s.attrib["text"]) <= 0:
continue
# annotation used only for document indexing
if len(s) <= 0:
continue
text_total_length += len(s.attrib["text"]) + 1
po_end = po_start + len(s.attrib["text"])
start = po_start
dp = {
"text": s.attrib["text"],
"type": "title" if ".s0" in s.attrib["id"] else "abstract",
"offsets": [(po_start, po_end)],
"offset": 0, # original offset
}
po_start = po_end + 1
sentences.append(dp)
pe = [] # entities
re = [] # relations
# For each entity
for a in s:
# If correspond to a entity
if a.tag == "entity":
length = len(a.attrib["text"])
if a.attrib["text"] is None or length <= 0:
continue
# no in-text annotation: only for document indexing
if a.attrib["type"] in ["MeSH_Indexing_Chemical", "OTHER"]:
continue
startOffset, endOffset = a.attrib["charOffset"].split("-")
startOffset, endOffset = int(startOffset), int(endOffset)
pe.append(
{
"id": a.attrib["id"],
"type": a.attrib["type"],
"text": (a.attrib["text"],),
"offsets": [(start + startOffset, start + endOffset + 1)],
"normalized": [
{"db_name": "miRNA-corpus", "db_id": a.attrib["id"]}
],
}
)
# If correspond to relation pair
elif a.tag == "pair":
re.append(
{
"id": a.attrib["id"],
"type": a.attrib["type"],
"arg1_id": a.attrib["e1"],
"arg2_id": a.attrib["e2"],
"normalized": [],
}
)
entities.append(pe)
relations.append(re)
return sentences, entities, relations
def _generate_examples(
self,
filepath: str,
split: str,
) -> Iterator[Tuple[int, Dict]]:
"""Yields examples as (key, example) tuples."""
reader = ET.fromstring(open(str(filepath), "r").read())
if self.config.schema == "source":
for uid, doc in enumerate(reader):
(
sentences,
sentences_entities,
relations,
) = self._get_passages_and_entities(doc)
if (
len(sentences) < 1
or len(sentences_entities) < 1
or len(sentences_entities) != len(sentences)
):
continue
for p, pe, re in zip(sentences, sentences_entities, relations):
p.pop("offsets") # BioC has only start for passages offsets
p["document_id"] = doc.attrib["id"]
p["entities"] = pe # BioC has per passage entities
yield uid, {"passages": sentences}
elif self.config.schema == "bigbio_kb":
uid = 0
for idx, doc in enumerate(reader):
(
sentences,
sentences_entities,
relations,
) = self._get_passages_and_entities(doc)
if (
len(sentences) < 1
or len(sentences_entities) < 1
or len(sentences_entities) != len(sentences)
):
continue
# global id
uid += 1
# unpack per-sentence entities
entities = [e for pe in sentences_entities for e in pe]
for p in sentences:
p.pop("offset") # drop original offset
p["text"] = (p["text"],) # text in sentence is Sequence
p["id"] = uid
uid += 1
for e in entities:
e["id"] = uid
uid += 1
# unpack per-sentence relations
relations = [r for re in relations for r in re]
for r in relations:
r["id"] = uid
uid += 1
yield idx, {
"id": uid,
"document_id": doc.attrib["id"],
"passages": sentences,
"entities": entities,
"events": [],
"coreferences": [],
"relations": relations,
}
|