| import os | |
| import json | |
| from collections import OrderedDict | |
| import datasets | |
| logger = datasets.logging.get_logger(__name__) | |
| _CITATION = """\ | |
| @article{10.1093/nar/gkaa484, | |
| author = {Ishida, Ryoga and Adachi, Tatsuo and Yokota, Aya and Yoshihara, Hidehito and Aoki, Kazuteru and Nakamura, \ | |
| Yoshikazu and Hamada, Michiaki}, | |
| title = "{RaptRanker: in silico RNA aptamer selection from HT-SELEX experiment based on local sequence and \ | |
| structure information}", | |
| journal = {Nucleic Acids Research}, | |
| volume = {48}, | |
| number = {14}, | |
| pages = {e82-e82}, | |
| year = {2020}, | |
| month = {06}, | |
| abstract = "{Aptamers are short single-stranded RNA/DNA molecules that bind to specific target molecules. \ | |
| Aptamers with high binding-affinity and target specificity are identified using an in vitro procedure called \ | |
| high throughput systematic evolution of ligands by exponential enrichment (HT-SELEX). However, the development \ | |
| of aptamer affinity reagents takes a considerable amount of time and is costly because HT-SELEX produces a large \ | |
| dataset of candidate sequences, some of which have insufficient binding-affinity. Here, we present RNA aptamer \ | |
| Ranker (RaptRanker), a novel in silico method for identifying high binding-affinity aptamers from HT-SELEX data by \ | |
| scoring and ranking. RaptRanker analyzes HT-SELEX data by evaluating the nucleotide sequence and secondary \ | |
| structure simultaneously, and by ranking according to scores reflecting local structure and sequence frequencies. \ | |
| To evaluate the performance of RaptRanker, we performed two new HT-SELEX experiments, and evaluated \ | |
| binding affinities of a part of sequences that include aptamers with low binding-affinity. In both datasets, \ | |
| the performance of RaptRanker was superior to Frequency, Enrichment and MPBind. We also confirmed that \ | |
| the consideration of secondary structures is effective in HT-SELEX data analysis, and that RaptRanker \ | |
| successfully predicted the essential subsequence motifs in each identified sequence.}", | |
| issn = {0305-1048}, | |
| doi = {10.1093/nar/gkaa484}, | |
| url = {https://doi.org/10.1093/nar/gkaa484}, | |
| eprint = {https://academic.oup.com/nar/article-pdf/48/14/e82/34130937/gkaa484.pdf}, | |
| } | |
| """ | |
| _DESCRIPTION = """\ | |
| PRJDB9110 | |
| https://www.ebi.ac.uk/ena/browser/view/PRJDB9110 | |
| To generate RNA aptamers against human transglutaminase 2, we have performed the high-throughput systematic evolution \ | |
| of ligands by exponential enrichment (HT-SELEX). Of the eight performed rounds, the rounds 0 to 8 have been sequenced. | |
| """ | |
| _URL = "https://ftp.sra.ebi.ac.uk/vol1/fastq/DRR201" | |
| _URLS = { | |
| "round_0": "/".join([_URL, "DRR201861/DRR201861.fastq.gz"]), | |
| "round_1": "/".join([_URL, "DRR201862/DRR201862.fastq.gz"]), | |
| "round_2": "/".join([_URL, "DRR201863/DRR201863.fastq.gz"]), | |
| "round_3": "/".join([_URL, "DRR201864/DRR201864.fastq.gz"]), | |
| "round_4": "/".join([_URL, "DRR201865/DRR201865.fastq.gz"]), | |
| "round_5": "/".join([_URL, "DRR201866/DRR201866.fastq.gz"]), | |
| "round_6": "/".join([_URL, "DRR201867/DRR201867.fastq.gz"]), | |
| "round_7": "/".join([_URL, "DRR201868/DRR201868.fastq.gz"]), | |
| "round_8": "/".join([_URL, "DRR201869/DRR201869.fastq.gz"]), | |
| } | |
| _HUGGINGFACE_URLS = { | |
| "round_0": "https://huggingface.co/datasets/thewall/tg2/resolve/main/data/DRR201861.fastq.gz", | |
| "round_1": "https://huggingface.co/datasets/thewall/tg2/resolve/main/data/DRR201862.fastq.gz", | |
| "round_2": "https://huggingface.co/datasets/thewall/tg2/resolve/main/data/DRR201863.fastq.gz", | |
| "round_3": "https://huggingface.co/datasets/thewall/tg2/resolve/main/data/DRR201864.fastq.gz", | |
| "round_4": "https://huggingface.co/datasets/thewall/tg2/resolve/main/data/DRR201865.fastq.gz", | |
| "round_5": "https://huggingface.co/datasets/thewall/tg2/resolve/main/data/DRR201866.fastq.gz", | |
| "round_6": "https://huggingface.co/datasets/thewall/tg2/resolve/main/data/DRR201867.fastq.gz", | |
| "round_7": "https://huggingface.co/datasets/thewall/tg2/resolve/main/data/DRR201868.fastq.gz", | |
| "round_8": "https://huggingface.co/datasets/thewall/tg2/resolve/main/data/DRR201869.fastq.gz", | |
| } | |
| _FORWARD_PRIMER = "TAATACGACTCACTATAGGGAGCAGGAGAGAGGTCAGATG" | |
| _REVERSE_PRIMER = "CCTATGCGTGCTAGTGTGA" | |
| _DESIGN_LENGTH = 30 | |
| """ | |
| "forward_primer":"TAATACGACTCACTATAGGGAGCAGGAGAGAGGTCAGATG", | |
| "reverse_primer":"CCTATGCGTGCTAGTGTGA", | |
| "add_forward_primer":"GGGAGCAGGAGAGAGGTCAGATG", | |
| "add_reverse_primer":"CCTATGCGTGCTAGTGTGA", | |
| """ | |
| class TG2Config(datasets.BuilderConfig): | |
| """BuilderConfig for SQUAD.""" | |
| def __init__(self, url, adapter_match=True, length_match=True, remove_primer=True, **kwargs): | |
| """BuilderConfig for SQUAD. | |
| Args: | |
| **kwargs: keyword arguments forwarded to super. | |
| """ | |
| super(TG2Config, self).__init__(**kwargs) | |
| self.url = url | |
| self.adapter_match = adapter_match | |
| self.length_match = length_match | |
| self.remove_primer = remove_primer | |
| class TG2(datasets.GeneratorBasedBuilder): | |
| """SQUAD: The Stanford Question Answering Dataset. Version 1.1.""" | |
| BUILDER_CONFIGS = [ | |
| TG2Config(name=key, url=_HUGGINGFACE_URLS[key]) for key in _URLS | |
| ] | |
| DEFAULT_CONFIG_NAME = "round_4" | |
| def _info(self): | |
| return datasets.DatasetInfo( | |
| description=_DESCRIPTION, | |
| features=datasets.Features( | |
| { | |
| "id": datasets.Value("int32"), | |
| "identifier": datasets.Value("string"), | |
| "seq": datasets.Value("string"), | |
| "count": datasets.Value("int32"), | |
| } | |
| ), | |
| homepage="https://www.ebi.ac.uk/ena/browser/view/PRJDB9110", | |
| citation=_CITATION, | |
| ) | |
| def _split_generators(self, dl_manager): | |
| downloaded_files = dl_manager.download_and_extract(self.config.url) | |
| return [ | |
| datasets.SplitGenerator(name=datasets.Split.TRAIN, gen_kwargs={"filepath": downloaded_files}), | |
| ] | |
| def _generate_examples(self, filepath): | |
| """This function returns the examples in the raw (text) form.""" | |
| logger.info("generating examples from = %s", filepath) | |
| key = 0 | |
| data = OrderedDict() | |
| with open(filepath, encoding="utf-8") as f: | |
| ans = {"id": key, "count": 1} | |
| for i, line in enumerate(f): | |
| if line.startswith("@") and i%4==0: | |
| ans["identifier"] = line[1:].split()[0].strip() | |
| elif i%4==1: | |
| ans["seq"] = line.strip() | |
| if self.filter_fn(ans): | |
| if ans['seq'] in data: | |
| data[ans['seq']]['count'] += 1 | |
| else: | |
| data[ans['seq']] = ans | |
| key += 1 | |
| ans = {"id": key, "count": 1} | |
| for item in data.values(): | |
| yield item['id'], item | |
| def filter_fn(self, example): | |
| seq = example["seq"] | |
| if self.config.adapter_match: | |
| if not seq.startswith(_FORWARD_PRIMER) or not seq.endswith(_REVERSE_PRIMER): | |
| return False | |
| if self.config.length_match: | |
| if len(seq)!=_DESIGN_LENGTH+len(_FORWARD_PRIMER)+len(_REVERSE_PRIMER): | |
| return False | |
| if self.config.remove_primer: | |
| example["seq"] = seq[len(_FORWARD_PRIMER):len(seq)-len(_REVERSE_PRIMER)] | |
| return True |