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import datasets
|
| 5 |
+
|
| 6 |
+
|
| 7 |
+
logger = datasets.logging.get_logger(__name__)
|
| 8 |
+
|
| 9 |
+
|
| 10 |
+
_CITATION = """\
|
| 11 |
+
@article{10.1093/nar/gkaa484,
|
| 12 |
+
author = {Ishida, Ryoga and Adachi, Tatsuo and Yokota, Aya and Yoshihara, Hidehito and Aoki, Kazuteru and Nakamura, \
|
| 13 |
+
Yoshikazu and Hamada, Michiaki},
|
| 14 |
+
title = "{RaptRanker: in silico RNA aptamer selection from HT-SELEX experiment based on local sequence and \
|
| 15 |
+
structure information}",
|
| 16 |
+
journal = {Nucleic Acids Research},
|
| 17 |
+
volume = {48},
|
| 18 |
+
number = {14},
|
| 19 |
+
pages = {e82-e82},
|
| 20 |
+
year = {2020},
|
| 21 |
+
month = {06},
|
| 22 |
+
abstract = "{Aptamers are short single-stranded RNA/DNA molecules that bind to specific target molecules. \
|
| 23 |
+
Aptamers with high binding-affinity and target specificity are identified using an in vitro procedure called \
|
| 24 |
+
high throughput systematic evolution of ligands by exponential enrichment (HT-SELEX). However, the development \
|
| 25 |
+
of aptamer affinity reagents takes a considerable amount of time and is costly because HT-SELEX produces a large \
|
| 26 |
+
dataset of candidate sequences, some of which have insufficient binding-affinity. Here, we present RNA aptamer \
|
| 27 |
+
Ranker (RaptRanker), a novel in silico method for identifying high binding-affinity aptamers from HT-SELEX data by \
|
| 28 |
+
scoring and ranking. RaptRanker analyzes HT-SELEX data by evaluating the nucleotide sequence and secondary \
|
| 29 |
+
structure simultaneously, and by ranking according to scores reflecting local structure and sequence frequencies. \
|
| 30 |
+
To evaluate the performance of RaptRanker, we performed two new HT-SELEX experiments, and evaluated \
|
| 31 |
+
binding affinities of a part of sequences that include aptamers with low binding-affinity. In both datasets, \
|
| 32 |
+
the performance of RaptRanker was superior to Frequency, Enrichment and MPBind. We also confirmed that \
|
| 33 |
+
the consideration of secondary structures is effective in HT-SELEX data analysis, and that RaptRanker \
|
| 34 |
+
successfully predicted the essential subsequence motifs in each identified sequence.}",
|
| 35 |
+
issn = {0305-1048},
|
| 36 |
+
doi = {10.1093/nar/gkaa484},
|
| 37 |
+
url = {https://doi.org/10.1093/nar/gkaa484},
|
| 38 |
+
eprint = {https://academic.oup.com/nar/article-pdf/48/14/e82/34130937/gkaa484.pdf},
|
| 39 |
+
}
|
| 40 |
+
"""
|
| 41 |
+
|
| 42 |
+
_DESCRIPTION = """\
|
| 43 |
+
PRJDB9110
|
| 44 |
+
https://www.ebi.ac.uk/ena/browser/view/PRJDB9110
|
| 45 |
+
To generate RNA aptamers against human transglutaminase 2, we have performed the high-throughput systematic evolution \
|
| 46 |
+
of ligands by exponential enrichment (HT-SELEX). Of the eight performed rounds, the rounds 0 to 8 have been sequenced.
|
| 47 |
+
"""
|
| 48 |
+
|
| 49 |
+
_URL = "ftp://ftp.sra.ebi.ac.uk/vol1/fastq/DRR201"
|
| 50 |
+
|
| 51 |
+
_URLS = {
|
| 52 |
+
"round_0": os.path.join(_URL, "DRR201861/DRR201861.fastq.gz"),
|
| 53 |
+
"round_1": os.path.join(_URL, "DRR201862/DRR201862.fastq.gz"),
|
| 54 |
+
"round_2": os.path.join(_URL, "DRR201863/DRR201863.fastq.gz"),
|
| 55 |
+
"round_3": os.path.join(_URL, "DRR201864/DRR201864.fastq.gz"),
|
| 56 |
+
"round_4": os.path.join(_URL, "DRR201865/DRR201865.fastq.gz"),
|
| 57 |
+
"round_5": os.path.join(_URL, "DRR201866/DRR201866.fastq.gz"),
|
| 58 |
+
"round_6": os.path.join(_URL, "DRR201867/DRR201867.fastq.gz"),
|
| 59 |
+
"round_7": os.path.join(_URL, "DRR201868/DRR201868.fastq.gz"),
|
| 60 |
+
"round_8": os.path.join(_URL, "DRR201869/DRR201869.fastq.gz"),
|
| 61 |
+
}
|
| 62 |
+
|
| 63 |
+
_FORWARD_PRIMER = "TAATACGACTCACTATAGGGAGCAGGAGAGAGGTCAGATG"
|
| 64 |
+
_REVERSE_PRIMER = "CCTATGCGTGCTAGTGTGA"
|
| 65 |
+
_DESIGN_LENGTH = 30
|
| 66 |
+
|
| 67 |
+
|
| 68 |
+
class TG2Config(datasets.BuilderConfig):
|
| 69 |
+
"""BuilderConfig for SQUAD."""
|
| 70 |
+
|
| 71 |
+
def __init__(self, url, adapter_match=True, length_match=True, remove_primer=True, **kwargs):
|
| 72 |
+
"""BuilderConfig for SQUAD.
|
| 73 |
+
Args:
|
| 74 |
+
**kwargs: keyword arguments forwarded to super.
|
| 75 |
+
"""
|
| 76 |
+
super(TG2Config, self).__init__(**kwargs)
|
| 77 |
+
self.url = url
|
| 78 |
+
self.adapter_match = adapter_match
|
| 79 |
+
self.length_match = length_match
|
| 80 |
+
self.remove_primer = remove_primer
|
| 81 |
+
|
| 82 |
+
|
| 83 |
+
class TG2(datasets.GeneratorBasedBuilder):
|
| 84 |
+
"""SQUAD: The Stanford Question Answering Dataset. Version 1.1."""
|
| 85 |
+
|
| 86 |
+
BUILDER_CONFIGS = [
|
| 87 |
+
TG2Config(name=key, url=_URLS[key]) for key in _URLS
|
| 88 |
+
]
|
| 89 |
+
|
| 90 |
+
DEFAULT_CONFIG_NAME = "round_4"
|
| 91 |
+
|
| 92 |
+
def _info(self):
|
| 93 |
+
return datasets.DatasetInfo(
|
| 94 |
+
description=_DESCRIPTION,
|
| 95 |
+
features=datasets.Features(
|
| 96 |
+
{
|
| 97 |
+
"id": datasets.Value("int32"),
|
| 98 |
+
"identifier": datasets.Value("string"),
|
| 99 |
+
"seq": datasets.Value("string"),
|
| 100 |
+
"count": datasets.Value("int32"),
|
| 101 |
+
}
|
| 102 |
+
),
|
| 103 |
+
homepage="https://www.ebi.ac.uk/ena/browser/view/PRJDB9110",
|
| 104 |
+
citation=_CITATION,
|
| 105 |
+
)
|
| 106 |
+
|
| 107 |
+
def _split_generators(self, dl_manager):
|
| 108 |
+
downloaded_files = dl_manager.download_and_extract(self.config.url)
|
| 109 |
+
|
| 110 |
+
return [
|
| 111 |
+
datasets.SplitGenerator(name=datasets.Split.TRAIN, gen_kwargs={"filepath": downloaded_files}),
|
| 112 |
+
]
|
| 113 |
+
|
| 114 |
+
def _generate_examples(self, filepath):
|
| 115 |
+
"""This function returns the examples in the raw (text) form."""
|
| 116 |
+
logger.info("generating examples from = %s", filepath)
|
| 117 |
+
key = 0
|
| 118 |
+
data = OrderedDict()
|
| 119 |
+
with open(filepath, encoding="utf-8") as f:
|
| 120 |
+
ans = {"id": key, "count": 1}
|
| 121 |
+
for i, line in enumerate(f):
|
| 122 |
+
if line.startswith("@") and i%4==0:
|
| 123 |
+
ans["identifier"] = line[1:].split()[0].strip()
|
| 124 |
+
elif i%4==1:
|
| 125 |
+
ans["seq"] = line.strip()
|
| 126 |
+
if self.filter_fn(ans):
|
| 127 |
+
if ans['seq'] in data:
|
| 128 |
+
data[ans['seq']]['count'] += 1
|
| 129 |
+
else:
|
| 130 |
+
data[ans['seq']] = ans
|
| 131 |
+
key += 1
|
| 132 |
+
ans = {"id": key, "count": 1}
|
| 133 |
+
for item in data.values():
|
| 134 |
+
yield item['id'], item
|
| 135 |
+
|
| 136 |
+
def filter_fn(self, example):
|
| 137 |
+
seq = example["seq"]
|
| 138 |
+
if self.config.adapter_match:
|
| 139 |
+
if not seq.startswith(_FORWARD_PRIMER) or not seq.endswith(_REVERSE_PRIMER):
|
| 140 |
+
return False
|
| 141 |
+
if self.config.length_match:
|
| 142 |
+
if len(seq)!=_DESIGN_LENGTH+len(_FORWARD_PRIMER)+len(_REVERSE_PRIMER):
|
| 143 |
+
return False
|
| 144 |
+
if self.config.remove_primer:
|
| 145 |
+
example["seq"] = seq[len(_FORWARD_PRIMER):len(seq)-len(_REVERSE_PRIMER)]
|
| 146 |
+
return True
|
| 147 |
+
|
| 148 |
+
|
| 149 |
+
if __name__=="__main__":
|
| 150 |
+
from datasets import load_dataset
|
| 151 |
+
dataset = load_dataset("tg2.py", split="all")
|
| 152 |
+
from itertools import s
|
| 153 |
+
|