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1 |
+
import re
|
| 2 |
+
import pandas as pd
|
| 3 |
+
import datasets
|
| 4 |
+
from functools import cached_property, cache
|
| 5 |
+
|
| 6 |
+
logger = datasets.logging.get_logger(__name__)
|
| 7 |
+
|
| 8 |
+
|
| 9 |
+
_CITATION = """\
|
| 10 |
+
@article{jolma2010multiplexed,
|
| 11 |
+
title={Multiplexed massively parallel SELEX for characterization of human transcription factor binding specificities},
|
| 12 |
+
author={Jolma, Arttu and Kivioja, Teemu and Toivonen, Jarkko and Cheng, Lu and Wei, Gonghong and Enge, Martin and \
|
| 13 |
+
Taipale, Mikko and Vaquerizas, Juan M and Yan, Jian and Sillanp{\"a}{\"a}, Mikko J and others},
|
| 14 |
+
journal={Genome research},
|
| 15 |
+
volume={20},
|
| 16 |
+
number={6},
|
| 17 |
+
pages={861--873},
|
| 18 |
+
year={2010},
|
| 19 |
+
publisher={Cold Spring Harbor Lab}
|
| 20 |
+
}
|
| 21 |
+
"""
|
| 22 |
+
|
| 23 |
+
_DESCRIPTION = """\
|
| 24 |
+
PRJEB3289
|
| 25 |
+
https://www.ebi.ac.uk/ena/browser/view/PRJEB3289
|
| 26 |
+
Data that has been generated by HT-SELEX experiments (see Jolma et al. 2010. PMID: 20378718 for description of method) \
|
| 27 |
+
that has been now used to generate transcription factor binding specificity models for most of the high confidence \
|
| 28 |
+
human transcription factors. Sequence data is composed of reads generated with Illumina Genome Analyzer IIX and \
|
| 29 |
+
HiSeq2000 instruments. Samples are composed of single read sequencing of synthetic DNA fragments with a fixed length \
|
| 30 |
+
randomized region or samples derived from such a initial library by selection with a sequence specific DNA binding \
|
| 31 |
+
protein. Originally multiple samples with different "barcode" tag sequences were run on the same Illumina sequencing \
|
| 32 |
+
lane but the released files have been already de-multiplexed, and the constant regions and "barcodes" of each sequence \
|
| 33 |
+
have been cut out of the sequencing reads to facilitate the use of data. Some of the files are composed of reads from \
|
| 34 |
+
multiple different sequencing lanes and due to this each of the names of the individual reads have been edited to show \
|
| 35 |
+
the flowcell and lane that was used to generate it. Barcodes and oligonucleotide designs are indicated in the names of \
|
| 36 |
+
individual entries. Depending of the selection ligand design, the sequences in each of these fastq-files are either \
|
| 37 |
+
14, 20, 30 or 40 bases long and had different flanking regions in both sides of the sequence. Each run entry is named \
|
| 38 |
+
in either of the following ways: Example 1) "BCL6B_DBD_AC_TGCGGG20NGA_1", where name is composed of following fields \
|
| 39 |
+
ProteinName_CloneType_Batch_BarcodeDesign_SelectionCycle. This experiment used barcode ligand TGCGGG20NGA, where both \
|
| 40 |
+
of the variable flanking constant regions are indicated as they were on the original sequence-reads. This ligand has \
|
| 41 |
+
been selected for one round of HT-SELEX using recombinant protein that contained the DNA binding domain of \
|
| 42 |
+
human transcription factor BCL6B. It also tells that the experiment was performed on batch of experiments named as "AC".\
|
| 43 |
+
Example 2) 0_TGCGGG20NGA_0 where name is composed of (zero)_BarcodeDesign_(zero) These sequences have been generated \
|
| 44 |
+
from sequencing of the initial non-selected pool. Same initial pools have been used in multiple experiments that were \
|
| 45 |
+
on different batches, thus for example this background sequence pool is the shared background for all of the following \
|
| 46 |
+
samples. BCL6B_DBD_AC_TGCGGG20NGA_1, ZNF784_full_AE_TGCGGG20NGA_3, DLX6_DBD_Y_TGCGGG20NGA_4 and MSX2_DBD_W_TGCGGG20NGA_2
|
| 47 |
+
"""
|
| 48 |
+
|
| 49 |
+
_DOWNLODE_MANAGER = datasets.DownloadManager()
|
| 50 |
+
_RESOURCE_URL = "https://huggingface.co/datasets/thewall/DeepBindWeight/resolve/main"
|
| 51 |
+
SELEX_INFO_FILE = _DOWNLODE_MANAGER.download(f"{_RESOURCE_URL}/ERP001824-deepbind.xlsx")
|
| 52 |
+
PROTEIN_INFO_FILE = _DOWNLODE_MANAGER.download(f"{_RESOURCE_URL}/ERP001824-UniprotKB.xlsx")
|
| 53 |
+
pattern = re.compile("(\d+)")
|
| 54 |
+
URL = "https://huggingface.co/datasets/thewall/jolma_split/resolve/main"
|
| 55 |
+
|
| 56 |
+
|
| 57 |
+
class JolmaSplitConfig(datasets.BuilderConfig):
|
| 58 |
+
def __init__(self, protein_prefix="", protein_suffix="", max_length=1000, max_gene_num=1,
|
| 59 |
+
aptamer_prefix="", aptamer_suffix="", **kwargs):
|
| 60 |
+
super(JolmaSplitConfig, self).__init__(**kwargs)
|
| 61 |
+
self.data_dir = kwargs.get("data_dir")
|
| 62 |
+
self.protein_prefix = protein_prefix
|
| 63 |
+
self.protein_suffix = protein_suffix
|
| 64 |
+
self.aptamer_prefix = aptamer_prefix
|
| 65 |
+
self.aptamer_suffix = aptamer_suffix
|
| 66 |
+
self.max_length = max_length
|
| 67 |
+
self.max_gene_num = max_gene_num
|
| 68 |
+
|
| 69 |
+
|
| 70 |
+
class JolmaSubset(datasets.GeneratorBasedBuilder):
|
| 71 |
+
|
| 72 |
+
SELEX_INFO = pd.read_excel(SELEX_INFO_FILE, index_col=0)
|
| 73 |
+
PROTEIN_INFO = pd.read_excel(PROTEIN_INFO_FILE, index_col=0)
|
| 74 |
+
|
| 75 |
+
BUILDER_CONFIGS = [
|
| 76 |
+
JolmaSplitConfig(name=key) for key in ["p70c10s61087t100", "p99c3s325414t1000"]
|
| 77 |
+
]
|
| 78 |
+
|
| 79 |
+
DEFAULT_CONFIG_NAME = "p70c10s61087t100"
|
| 80 |
+
|
| 81 |
+
def _info(self):
|
| 82 |
+
return datasets.DatasetInfo(
|
| 83 |
+
description=_DESCRIPTION,
|
| 84 |
+
features=datasets.Features(
|
| 85 |
+
{
|
| 86 |
+
"id": datasets.Value("int32"),
|
| 87 |
+
"identifier": datasets.Value("string"),
|
| 88 |
+
"seq": datasets.Value("string"),
|
| 89 |
+
"quality": datasets.Value("string"),
|
| 90 |
+
"count": datasets.Value("int32"),
|
| 91 |
+
"protein": datasets.Value("string"),
|
| 92 |
+
"protein_id": datasets.Value("string"),
|
| 93 |
+
}
|
| 94 |
+
),
|
| 95 |
+
homepage="https://www.ebi.ac.uk/ena/browser/view/PRJEB3289",
|
| 96 |
+
citation=_CITATION,
|
| 97 |
+
)
|
| 98 |
+
|
| 99 |
+
@cached_property
|
| 100 |
+
def selex_info(self):
|
| 101 |
+
return self.SELEX_INFO.loc[self.config.name]
|
| 102 |
+
|
| 103 |
+
@cached_property
|
| 104 |
+
def protein_info(self):
|
| 105 |
+
return self.PROTEIN_INFO.loc[self.config.name]
|
| 106 |
+
|
| 107 |
+
def design_length(self):
|
| 108 |
+
return int(pattern.search(self.protein_info["Ligand"]).group(0))
|
| 109 |
+
|
| 110 |
+
def get_selex_info(self, sra_id):
|
| 111 |
+
return self.SELEX_INFO.loc[sra_id]
|
| 112 |
+
|
| 113 |
+
def get_protein_info(self, sra_id):
|
| 114 |
+
return self.PROTEIN_INFO.loc[sra_id]
|
| 115 |
+
|
| 116 |
+
@cache
|
| 117 |
+
def get_design_length(self, sra_id):
|
| 118 |
+
return int(pattern.search(self.get_protein_info(sra_id)["Ligand"]).group(0))
|
| 119 |
+
|
| 120 |
+
def _split_generators(self, dl_manager):
|
| 121 |
+
train_file = dl_manager.download(f"{URL}/{self.config.name}_train.csv.gz")
|
| 122 |
+
test_file = dl_manager.download(f"{URL}/{self.config.name}_test.csv.gz")
|
| 123 |
+
return [
|
| 124 |
+
datasets.SplitGenerator(name=datasets.Split.TRAIN, gen_kwargs={"filepath": train_file},),
|
| 125 |
+
datasets.SplitGenerator(name=datasets.Split.TEST, gen_kwargs={"filepath": test_file}, ),
|
| 126 |
+
]
|
| 127 |
+
|
| 128 |
+
def _generate_examples(self, filepath):
|
| 129 |
+
"""This function returns the examples in the raw (text) form."""
|
| 130 |
+
logger.info("generating examples from = %s", filepath)
|
| 131 |
+
data = pd.read_csv(filepath)
|
| 132 |
+
for key, row in data.iterrows():
|
| 133 |
+
sra_id = row["identifier"].split(":")[0]
|
| 134 |
+
protein_info = self.get_protein_info(sra_id)
|
| 135 |
+
proteins = protein_info["Sequence"]
|
| 136 |
+
gene_num = protein_info["Unique Gene"]
|
| 137 |
+
protein_id = protein_info["Entry"]
|
| 138 |
+
protein_seq = f"{self.config.protein_prefix}{proteins}{self.config.protein_suffix}"
|
| 139 |
+
aptamer_seq = f'{self.config.aptamer_prefix}{row["seq"]}{self.config.aptamer_suffix}'
|
| 140 |
+
if len(protein_seq)>self.config.max_length:
|
| 141 |
+
continue
|
| 142 |
+
if gene_num>self.config.max_gene_num:
|
| 143 |
+
continue
|
| 144 |
+
if str(proteins)=="nan" or len(str(proteins))==0:
|
| 145 |
+
continue
|
| 146 |
+
ans = {"id": key,
|
| 147 |
+
"protein": protein_seq,
|
| 148 |
+
"protein_id": protein_id,
|
| 149 |
+
"seq": aptamer_seq,
|
| 150 |
+
"identifier": row["identifier"],
|
| 151 |
+
"count": int(row["count"]),
|
| 152 |
+
"quality": row['quality']}
|
| 153 |
+
yield key, ans
|
| 154 |
+
|
| 155 |
+
|
| 156 |
+
if __name__=="__main__":
|
| 157 |
+
from datasets import load_dataset
|
| 158 |
+
dataset = load_dataset("jolma_split.py", split="all")
|
| 159 |
+
|