Upload jolma_unique.py
Browse files- jolma_unique.py +158 -0
jolma_unique.py
ADDED
@@ -0,0 +1,158 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import os
|
2 |
+
import json
|
3 |
+
import re
|
4 |
+
import pandas as pd
|
5 |
+
import datasets
|
6 |
+
|
7 |
+
|
8 |
+
logger = datasets.logging.get_logger(__name__)
|
9 |
+
|
10 |
+
|
11 |
+
_CITATION = """\
|
12 |
+
@article{jolma2010multiplexed,
|
13 |
+
title={Multiplexed massively parallel SELEX for characterization of human transcription factor binding specificities},
|
14 |
+
author={Jolma, Arttu and Kivioja, Teemu and Toivonen, Jarkko and Cheng, Lu and Wei, Gonghong and Enge, Martin and \
|
15 |
+
Taipale, Mikko and Vaquerizas, Juan M and Yan, Jian and Sillanp{\"a}{\"a}, Mikko J and others},
|
16 |
+
journal={Genome research},
|
17 |
+
volume={20},
|
18 |
+
number={6},
|
19 |
+
pages={861--873},
|
20 |
+
year={2010},
|
21 |
+
publisher={Cold Spring Harbor Lab}
|
22 |
+
}
|
23 |
+
"""
|
24 |
+
|
25 |
+
_DESCRIPTION = """\
|
26 |
+
PRJEB3289
|
27 |
+
https://www.ebi.ac.uk/ena/browser/view/PRJEB3289
|
28 |
+
Data that has been generated by HT-SELEX experiments (see Jolma et al. 2010. PMID: 20378718 for description of method) \
|
29 |
+
that has been now used to generate transcription factor binding specificity models for most of the high confidence \
|
30 |
+
human transcription factors. Sequence data is composed of reads generated with Illumina Genome Analyzer IIX and \
|
31 |
+
HiSeq2000 instruments. Samples are composed of single read sequencing of synthetic DNA fragments with a fixed length \
|
32 |
+
randomized region or samples derived from such a initial library by selection with a sequence specific DNA binding \
|
33 |
+
protein. Originally multiple samples with different "barcode" tag sequences were run on the same Illumina sequencing \
|
34 |
+
lane but the released files have been already de-multiplexed, and the constant regions and "barcodes" of each sequence \
|
35 |
+
have been cut out of the sequencing reads to facilitate the use of data. Some of the files are composed of reads from \
|
36 |
+
multiple different sequencing lanes and due to this each of the names of the individual reads have been edited to show \
|
37 |
+
the flowcell and lane that was used to generate it. Barcodes and oligonucleotide designs are indicated in the names of \
|
38 |
+
individual entries. Depending of the selection ligand design, the sequences in each of these fastq-files are either \
|
39 |
+
14, 20, 30 or 40 bases long and had different flanking regions in both sides of the sequence. Each run entry is named \
|
40 |
+
in either of the following ways: Example 1) "BCL6B_DBD_AC_TGCGGG20NGA_1", where name is composed of following fields \
|
41 |
+
ProteinName_CloneType_Batch_BarcodeDesign_SelectionCycle. This experiment used barcode ligand TGCGGG20NGA, where both \
|
42 |
+
of the variable flanking constant regions are indicated as they were on the original sequence-reads. This ligand has \
|
43 |
+
been selected for one round of HT-SELEX using recombinant protein that contained the DNA binding domain of \
|
44 |
+
human transcription factor BCL6B. It also tells that the experiment was performed on batch of experiments named as "AC".\
|
45 |
+
Example 2) 0_TGCGGG20NGA_0 where name is composed of (zero)_BarcodeDesign_(zero) These sequences have been generated \
|
46 |
+
from sequencing of the initial non-selected pool. Same initial pools have been used in multiple experiments that were \
|
47 |
+
on different batches, thus for example this background sequence pool is the shared background for all of the following \
|
48 |
+
samples. BCL6B_DBD_AC_TGCGGG20NGA_1, ZNF784_full_AE_TGCGGG20NGA_3, DLX6_DBD_Y_TGCGGG20NGA_4 and MSX2_DBD_W_TGCGGG20NGA_2
|
49 |
+
"""
|
50 |
+
|
51 |
+
_URL = "ftp://ftp.sra.ebi.ac.uk/vol1/run/"
|
52 |
+
"ftp://ftp.sra.ebi.ac.uk/vol1/run/ERR173/ERR173154/CTCF_full_AJ_TAGCGA20NGCT_1.fastq.gz"
|
53 |
+
# _FORWARD_PRIMER = "TAATACGACTCACTATAGGGAGCAGGAGAGAGGTCAGATG"
|
54 |
+
# _REVERSE_PRIMER = "CCTATGCGTGCTAGTGTGA"
|
55 |
+
# _DESIGN_LENGTH = 30
|
56 |
+
|
57 |
+
|
58 |
+
config = datasets.load_dataset(path="thewall/deepbindweight", split="all")
|
59 |
+
info = pd.read_excel(config['selex'][0], index_col=0)
|
60 |
+
|
61 |
+
_URLS = {}
|
62 |
+
_DESIGN_LENGTH = {}
|
63 |
+
pattern = re.compile("(\d+)")
|
64 |
+
for idx, row in info.iterrows():
|
65 |
+
sra_id = idx
|
66 |
+
file = row["file"]
|
67 |
+
_URLS[sra_id] = "/".join([_URL, sra_id[:6], sra_id, file])
|
68 |
+
_DESIGN_LENGTH[sra_id] = int(pattern.search(row["Ligand"]).group(0))
|
69 |
+
|
70 |
+
|
71 |
+
class JolmaConfig(datasets.BuilderConfig):
|
72 |
+
def __init__(self, url, sra_id="ERR173157", length_match=True, filter_N=True, design_length=None, file=None, **kwargs):
|
73 |
+
super(JolmaConfig, self).__init__(**kwargs)
|
74 |
+
self.url = url
|
75 |
+
self.sra_id = sra_id
|
76 |
+
self.length_match = length_match
|
77 |
+
self.design_length = design_length
|
78 |
+
self.filter_N = filter_N
|
79 |
+
self.file = file
|
80 |
+
|
81 |
+
|
82 |
+
class Jolma(datasets.GeneratorBasedBuilder):
|
83 |
+
BUILDER_CONFIGS = [
|
84 |
+
JolmaConfig(name=key, url=_URLS[key], design_length=_DESIGN_LENGTH[key], file=info.loc[key]['file']) for key in _URLS
|
85 |
+
]
|
86 |
+
|
87 |
+
DEFAULT_CONFIG_NAME = "ERR173157"
|
88 |
+
|
89 |
+
def _info(self):
|
90 |
+
return datasets.DatasetInfo(
|
91 |
+
description=_DESCRIPTION,
|
92 |
+
features=datasets.Features(
|
93 |
+
{
|
94 |
+
"id": datasets.Value("int32"),
|
95 |
+
"identifier": datasets.Value("string"),
|
96 |
+
"seq": datasets.Value("string"),
|
97 |
+
"quality": datasets.Value("string"),
|
98 |
+
"count": datasets.Value("int32"),
|
99 |
+
}
|
100 |
+
),
|
101 |
+
homepage="https://www.ebi.ac.uk/ena/browser/view/PRJEB3289",
|
102 |
+
citation=_CITATION,
|
103 |
+
)
|
104 |
+
|
105 |
+
def _split_generators(self, dl_manager):
|
106 |
+
downloaded_files = None
|
107 |
+
if getattr(self.config, "data_dir") is not None:
|
108 |
+
# downloaded_files = os.path.join(self.config.data_dir, self.config.sra_id, self.config.file)
|
109 |
+
downloaded_files = dl_manager.extract(os.path.join(self.config.data_dir, self.config.sra_id, self.config.file))
|
110 |
+
logger.info(f"Load from {downloaded_files}")
|
111 |
+
if downloaded_files is None or not os.path.exists(downloaded_files):
|
112 |
+
logger.info(f"Download from {self.config.url}")
|
113 |
+
downloaded_files = dl_manager.download_and_extract(self.config.url)
|
114 |
+
return [
|
115 |
+
datasets.SplitGenerator(name=datasets.Split.TRAIN, gen_kwargs={"filepath": downloaded_files}),
|
116 |
+
]
|
117 |
+
|
118 |
+
def filter_fn(self, example):
|
119 |
+
seq = example["seq"]
|
120 |
+
if self.config.length_match and len(seq)!=self.config.design_length:
|
121 |
+
return False
|
122 |
+
if self.config.filter_N and "N" in seq:
|
123 |
+
return False
|
124 |
+
return True
|
125 |
+
|
126 |
+
def _generate_examples(self, filepath):
|
127 |
+
"""This function returns the examples in the raw (text) form."""
|
128 |
+
logger.info("generating examples from = %s", filepath)
|
129 |
+
with open(filepath, encoding="utf-8") as f:
|
130 |
+
data = []
|
131 |
+
ans = {}
|
132 |
+
for i, line in enumerate(f):
|
133 |
+
if line.startswith("@") and i%4==0:
|
134 |
+
ans["identifier"] = line[1:].strip()
|
135 |
+
elif i%4==1:
|
136 |
+
ans["seq"] = line.strip()
|
137 |
+
elif i%4==3:
|
138 |
+
ans["quality"] = line.strip()
|
139 |
+
if self.filter_fn(ans):
|
140 |
+
ans['id'] = len(data)
|
141 |
+
data.append(ans)
|
142 |
+
ans = {}
|
143 |
+
data = pd.DataFrame(data)
|
144 |
+
groups = data.groupby("seq")
|
145 |
+
for idx, (s, group) in enumerate(groups):
|
146 |
+
yield idx, {"id": idx,
|
147 |
+
"identifier": f"{self.config.name}:{group['id'].iloc[0]}",
|
148 |
+
"seq": group.iloc[0]['seq'],
|
149 |
+
"count": len(group),
|
150 |
+
'quality': group.iloc[0]['quality']}
|
151 |
+
|
152 |
+
|
153 |
+
if __name__=="__main__":
|
154 |
+
from datasets import load_dataset
|
155 |
+
dataset = load_dataset("jolma_unique.py", name="ERR173157", split="all")
|
156 |
+
# dataset = load_dataset("jolma.py", name="ERR173157", split="all", data_dir="/root/autodl-fs/ERP001824-461")
|
157 |
+
|
158 |
+
|