File size: 6,481 Bytes
3d38773
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
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 = """\
PRJDB9111
https://www.ebi.ac.uk/ena/browser/view/PRJDB9111
To generate RNA aptamers against human integrin alphaV beta3, we have performed the high-throughput systematic evolution \
of ligands by exponential enrichment (HT-SELEX). Of the six performed rounds, the rounds 3 to 6 have been sequenced.
"""

_URL = "https://ftp.sra.ebi.ac.uk/vol1/fastq/DRR201"
_URLS = {
    "round_3": "/".join([_URL, "DRR201870/DRR201870.fastq.gz"]),
    "round_4": "/".join([_URL, "DRR201871/DRR201871.fastq.gz"]),
    "round_5": "/".join([_URL, "DRR201872/DRR201872.fastq.gz"]),
    "round_6": "/".join([_URL, "DRR201873/DRR201873.fastq.gz"]),
}

_FORWARD_PRIMER = "CGGAATTCTAATACGACTCACTATAGGGAGAACTTCGACCAGAA"
_FORWARD_PRIMER =         "TAATACGACTCACTATAGGGAGAACTTCGACCAGAAG"

_REVERSE_PRIMER = "TATGTGCGCATACATGGATCCTC"
_DESIGN_LENGTH = 40

"""
  "forward_primer":"TAATACGACTCACTATAGGGAGAACTTCGACCAGAAG",
  "reverse_primer":     "TATGTGCGCATACATGGATCCTC",
  "add_forward_primer":             "GGGAGAACTTCGACCAGAAG",
  "add_reverse_primer": "TATGTGCGCATACATGGATCCTC",
"""

class AlphaVBeta3Config(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(AlphaVBeta3Config, self).__init__(**kwargs)
        self.url = url
        self.adapter_match = adapter_match
        self.length_match = length_match
        self.remove_primer = remove_primer


class AlphaVBeta3(datasets.GeneratorBasedBuilder):
    """SQUAD: The Stanford Question Answering Dataset. Version 1.1."""

    BUILDER_CONFIGS = [
        AlphaVBeta3Config(name=key, url=_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/PRJDB9111",
            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


if __name__=="__main__":
    from datasets import load_dataset
    dataset = load_dataset("alphaVbeta3.py", split="all")