RILseq-analysis 1.0.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- rilseq_analysis-1.0.0/PKG-INFO +10 -0
- rilseq_analysis-1.0.0/README.md +405 -0
- rilseq_analysis-1.0.0/RILseq_analysis.egg-info/PKG-INFO +10 -0
- rilseq_analysis-1.0.0/RILseq_analysis.egg-info/SOURCES.txt +20 -0
- rilseq_analysis-1.0.0/RILseq_analysis.egg-info/dependency_links.txt +1 -0
- rilseq_analysis-1.0.0/RILseq_analysis.egg-info/entry_points.txt +8 -0
- rilseq_analysis-1.0.0/RILseq_analysis.egg-info/requires.txt +7 -0
- rilseq_analysis-1.0.0/RILseq_analysis.egg-info/top_level.txt +1 -0
- rilseq_analysis-1.0.0/RILseq_analysis_package/__init__.py +0 -0
- rilseq_analysis-1.0.0/RILseq_analysis_package/annotations_graphs.py +185 -0
- rilseq_analysis-1.0.0/RILseq_analysis_package/chimeras_venn_diagram.py +81 -0
- rilseq_analysis-1.0.0/RILseq_analysis_package/circos_plot.py +164 -0
- rilseq_analysis-1.0.0/RILseq_analysis_package/cli/__init__.py +0 -0
- rilseq_analysis-1.0.0/RILseq_analysis_package/cli/add_number_of_libraries_cli.py +15 -0
- rilseq_analysis-1.0.0/RILseq_analysis_package/cli/circos_plot_cli.py +48 -0
- rilseq_analysis-1.0.0/RILseq_analysis_package/cli/merge_results_cli.py +20 -0
- rilseq_analysis-1.0.0/RILseq_analysis_package/extract_genes_by_chr.py +32 -0
- rilseq_analysis-1.0.0/RILseq_analysis_package/generate_and_edit_RILseq_xslx.py +118 -0
- rilseq_analysis-1.0.0/RILseq_analysis_package/sRNAs_percent.py +144 -0
- rilseq_analysis-1.0.0/RILseq_analysis_package/utils.py +84 -0
- rilseq_analysis-1.0.0/pyproject.toml +24 -0
- rilseq_analysis-1.0.0/setup.cfg +4 -0
|
@@ -0,0 +1,405 @@
|
|
|
1
|
+
# RILseq-analysis
|
|
2
|
+
|
|
3
|
+
Python package for downstream analysis of **RILseq** datasets.
|
|
4
|
+
|
|
5
|
+
The package provides tools for merging RIL-seq results from multiple libraries and performing comparative and visualization analyses of RNA-RNA interactions. It is designed to facilitate the analysis of significant chimeric interactions generated by the RILseq pipeline.
|
|
6
|
+
|
|
7
|
+
## Features
|
|
8
|
+
|
|
9
|
+
RILseq-analysis provides command-line tools for:
|
|
10
|
+
|
|
11
|
+
* Merging significant interactions from multiple RILseq libraries into a unified Excel workbook.
|
|
12
|
+
* Comparing RNA-RNA interactions between experimental conditions using Venn diagrams.
|
|
13
|
+
* Generating Circos plots for visualization of RNA-RNA interaction networks.
|
|
14
|
+
* Generating bar plots showing RNA annotation percentages.
|
|
15
|
+
* Generating heatmaps showing the RNA annotations of the two components of the chimeras.
|
|
16
|
+
* Quantifying and visualizing sRNA representation among S-chimeras and RILseq and RNAseq read counts.
|
|
17
|
+
* Counting the number of libraries in which each RNA-RNA interaction is detected and enaming columns in the resulting S-chimeras workbook.
|
|
18
|
+
|
|
19
|
+
---
|
|
20
|
+
|
|
21
|
+
## Installation
|
|
22
|
+
|
|
23
|
+
The package can be installed directly from GitHub:
|
|
24
|
+
|
|
25
|
+
```bash
|
|
26
|
+
pip install git+https://github.com/Reut-Wasserman/RILseq-analysis.git
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
### Requirements
|
|
31
|
+
|
|
32
|
+
The package is written in Python and uses packages including:
|
|
33
|
+
|
|
34
|
+
* pandas
|
|
35
|
+
* numpy
|
|
36
|
+
* matplotlib
|
|
37
|
+
* seaborn
|
|
38
|
+
* matplotlib-venn
|
|
39
|
+
* openpyxl
|
|
40
|
+
* PyYAML
|
|
41
|
+
|
|
42
|
+
Some analyses also require **R** and the **RCircos** R package.
|
|
43
|
+
|
|
44
|
+
---
|
|
45
|
+
|
|
46
|
+
# Configuration
|
|
47
|
+
|
|
48
|
+
Most commands require a YAML configuration file.
|
|
49
|
+
|
|
50
|
+
The configuration file should contain the following keys:
|
|
51
|
+
|
|
52
|
+
```yaml
|
|
53
|
+
base_path: "base_path"
|
|
54
|
+
|
|
55
|
+
annotation_path: "annotation_path"
|
|
56
|
+
|
|
57
|
+
rna_types_excel: "rna_types_excel"
|
|
58
|
+
|
|
59
|
+
experiments:
|
|
60
|
+
- "experiment1"
|
|
61
|
+
- "experiment2"
|
|
62
|
+
|
|
63
|
+
replicates:
|
|
64
|
+
- "_I"
|
|
65
|
+
- "_II"
|
|
66
|
+
|
|
67
|
+
chr_dic:
|
|
68
|
+
"chrI": "organism1 name"
|
|
69
|
+
"chrII": "organism2 name"
|
|
70
|
+
|
|
71
|
+
chr_len:
|
|
72
|
+
"chrI": chromosome1_length
|
|
73
|
+
"chrII": chromosome2_length
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
### Configuration fields
|
|
77
|
+
|
|
78
|
+
| Key | Description |
|
|
79
|
+
| ----------------- | ----------------------------------------------------------------------------------------- |
|
|
80
|
+
| `base_path` | Directory containing the `sig_interactions.txt` and `all_counts_table.txt` files. |
|
|
81
|
+
| `annotation_path` | Path to the GFF annotation file used in the RILseq pipeline. |
|
|
82
|
+
| `rna_types_excel` | Path to an Excel file containing RNA annotations. |
|
|
83
|
+
| `experiments` | List of experiment names. |
|
|
84
|
+
| `replicates` | List of replicate suffixes/names. |
|
|
85
|
+
| `chr_dic` | Dictionary mapping chromosome names in the annotation file to names displayed in figures. |
|
|
86
|
+
| `chr_len` | Dictionary containing chromosome lengths in base pairs. |
|
|
87
|
+
|
|
88
|
+
### RNA annotation Excel file
|
|
89
|
+
|
|
90
|
+
The Excel file specified by `rna_types_excel` should contain the following sheets:
|
|
91
|
+
|
|
92
|
+
* `sRNA`
|
|
93
|
+
* `oRNA`
|
|
94
|
+
* `rRNA`
|
|
95
|
+
* `tRNA`
|
|
96
|
+
|
|
97
|
+
Each sheet should contain a `Name` column listing the corresponding RNA names.
|
|
98
|
+
|
|
99
|
+
---
|
|
100
|
+
|
|
101
|
+
# Workflow
|
|
102
|
+
|
|
103
|
+
A typical downstream analysis consists of the following steps:
|
|
104
|
+
|
|
105
|
+
1. Create a configuration file.
|
|
106
|
+
2. Merge results from multiple RIL-seq libraries.
|
|
107
|
+
3. Compare conditions using Venn diagrams.
|
|
108
|
+
4. Generate Circos input files and plots.
|
|
109
|
+
5. Generate annotation bar plots and heatmaps.
|
|
110
|
+
6. Generate sRNA percentage plots.
|
|
111
|
+
7. Count the number of libraries supporting each interaction.
|
|
112
|
+
|
|
113
|
+
The commands can also be run independently when only a subset of the analyses is required.
|
|
114
|
+
|
|
115
|
+
---
|
|
116
|
+
|
|
117
|
+
# Commands
|
|
118
|
+
|
|
119
|
+
## 1. Merge RIL-seq results
|
|
120
|
+
|
|
121
|
+
Merge significant interactions from multiple libraries into a unified Excel workbook.
|
|
122
|
+
|
|
123
|
+
```bash
|
|
124
|
+
merge-results config_path file_names
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
### Arguments
|
|
128
|
+
|
|
129
|
+
* `config_path` — path to the YAML configuration file.
|
|
130
|
+
* `file_names` — path to a tab-separated file containing two columns:
|
|
131
|
+
|
|
132
|
+
1. significant-interactions file name
|
|
133
|
+
2. corresponding experiment name as defined in the YAML configuration.
|
|
134
|
+
|
|
135
|
+
For example:
|
|
136
|
+
|
|
137
|
+
```text
|
|
138
|
+
unified_Hfq_lambda_60_example_sig_interactions.txt Hfq_lambda_60
|
|
139
|
+
unified_Hfq_lambda_30_example_sig_interactions.txt Hfq_lambda_30
|
|
140
|
+
Hfq_lambda_30_I_example_sig_interactions.txt Hfq_lambda_30_I
|
|
141
|
+
Hfq_lambda_30_II_example_sig_interactions.txt Hfq_lambda_30_II
|
|
142
|
+
Hfq_lambda_60_I_example_sig_interactions.txt Hfq_lambda_60_I
|
|
143
|
+
Hfq_lambda_60_II_example_sig_interactions.txt Hfq_lambda_60_II
|
|
144
|
+
```
|
|
145
|
+
|
|
146
|
+
By default, annotation information is included in the output.
|
|
147
|
+
|
|
148
|
+
To exclude the annotations column:
|
|
149
|
+
|
|
150
|
+
```bash
|
|
151
|
+
merge-results config_path file_names --no-annotations
|
|
152
|
+
```
|
|
153
|
+
|
|
154
|
+
### Output
|
|
155
|
+
|
|
156
|
+
The command produces a unified Excel workbook containing the interactions from the specified libraries.
|
|
157
|
+
|
|
158
|
+
---
|
|
159
|
+
|
|
160
|
+
## 2. Compare conditions using Venn diagrams
|
|
161
|
+
|
|
162
|
+
Generate Venn diagrams comparing chimeric interactions between pairs of conditions. RNA1/RNA2 orientation is ignored when determining whether two chimeras represent the same interaction.
|
|
163
|
+
|
|
164
|
+
```bash
|
|
165
|
+
chimeras-venn config_path conditions_pairs
|
|
166
|
+
```
|
|
167
|
+
|
|
168
|
+
`conditions_pairs` is a comma-separated list of condition pairs. Conditions within each pair are separated by `-`.
|
|
169
|
+
|
|
170
|
+
For example:
|
|
171
|
+
|
|
172
|
+
```bash
|
|
173
|
+
chimeras-venn config_path "Hfq_30-Hfq_lambda_30,Hfq_60-Hfq_lambda_60"
|
|
174
|
+
```
|
|
175
|
+
|
|
176
|
+
A separate Venn diagram is generated for each pair.
|
|
177
|
+
|
|
178
|
+
By default, all S-chimeras are included. To restrict the analysis to specific chromosomes, use --chr to provide list of chromosomes separated by a comma.
|
|
179
|
+
|
|
180
|
+
```bash
|
|
181
|
+
chimeras-venn config_path "Hfq_30-Hfq_lambda_30" --chr chrI,chrII
|
|
182
|
+
```
|
|
183
|
+
|
|
184
|
+
---
|
|
185
|
+
|
|
186
|
+
## 3. Generate Circos plots
|
|
187
|
+
|
|
188
|
+
The `circos-plot` command generates the input files required for visualization of RNA-RNA interactions using circos_plot.R script.
|
|
189
|
+
|
|
190
|
+
```bash
|
|
191
|
+
circos-plot plot_type config_path
|
|
192
|
+
```
|
|
193
|
+
|
|
194
|
+
Two plot types are available:
|
|
195
|
+
|
|
196
|
+
### `two_genomes_half_circle`
|
|
197
|
+
|
|
198
|
+
Generates a plot in which each genome occupies half of the circle.
|
|
199
|
+
|
|
200
|
+
### `two_genomes_real_proportions`
|
|
201
|
+
|
|
202
|
+
Generates a plot in which each genome is represented proportionally to its actual length.
|
|
203
|
+
|
|
204
|
+
### Optional parameters
|
|
205
|
+
|
|
206
|
+
#### `--mark_step1`
|
|
207
|
+
|
|
208
|
+
Interval between scale marks on the first chromosome.
|
|
209
|
+
|
|
210
|
+
Default:
|
|
211
|
+
|
|
212
|
+
```text
|
|
213
|
+
200000
|
|
214
|
+
```
|
|
215
|
+
|
|
216
|
+
Used only with `two_genomes_real_proportions`.
|
|
217
|
+
|
|
218
|
+
#### `--mark_step2`
|
|
219
|
+
|
|
220
|
+
Interval between scale marks on the second chromosome.
|
|
221
|
+
|
|
222
|
+
Default:
|
|
223
|
+
|
|
224
|
+
```text
|
|
225
|
+
48500
|
|
226
|
+
```
|
|
227
|
+
|
|
228
|
+
Used only with `two_genomes_real_proportions`.
|
|
229
|
+
|
|
230
|
+
#### `--genes`
|
|
231
|
+
|
|
232
|
+
Restrict the plot to chimeras involving specific genes.
|
|
233
|
+
|
|
234
|
+
Genes should be provided as a string separated by underscores.
|
|
235
|
+
|
|
236
|
+
For example:
|
|
237
|
+
|
|
238
|
+
```bash
|
|
239
|
+
--genes "geneA_geneB_geneC"
|
|
240
|
+
```
|
|
241
|
+
|
|
242
|
+
#### `--present_chr`
|
|
243
|
+
|
|
244
|
+
Present the chimeras of the given chromosome only.
|
|
245
|
+
|
|
246
|
+
For example:
|
|
247
|
+
|
|
248
|
+
```bash
|
|
249
|
+
--present_chr chrII
|
|
250
|
+
```
|
|
251
|
+
|
|
252
|
+
If this option is not provided, interactions involving both chromosomes are included.
|
|
253
|
+
|
|
254
|
+
### Generating the Circos figures
|
|
255
|
+
|
|
256
|
+
The `circos-plot` command generates the input CSV files. The final Circos plots are generated using the circos_plot.R script in the `R/` directory. Users can open the script, modify the parameters according to their dataset, and run it directly using R or RStudio.
|
|
257
|
+
|
|
258
|
+
---
|
|
259
|
+
|
|
260
|
+
## 4. Generate annotation plots
|
|
261
|
+
|
|
262
|
+
Generate annotation percentage bar plots and RNA1/RNA2 annotation heatmaps.
|
|
263
|
+
|
|
264
|
+
```bash
|
|
265
|
+
annotations-graphs config_path
|
|
266
|
+
```
|
|
267
|
+
|
|
268
|
+
The command uses the RNA annotation information specified by `rna_types_excel` and the merged RIL-seq results.
|
|
269
|
+
|
|
270
|
+
The generated figures summarize the annotation composition of the RNA-RNA interactions.
|
|
271
|
+
|
|
272
|
+
---
|
|
273
|
+
|
|
274
|
+
## 5. Generate sRNA percentage plots
|
|
275
|
+
|
|
276
|
+
Generate bar plots showing the representation of sRNAs among S-chimeras and RILseq and RNAseq read counts.
|
|
277
|
+
|
|
278
|
+
```bash
|
|
279
|
+
sRNAs-percent config_path sRNAs_number
|
|
280
|
+
```
|
|
281
|
+
|
|
282
|
+
### Arguments
|
|
283
|
+
|
|
284
|
+
* `config_path` — path to the YAML configuration file.
|
|
285
|
+
* `sRNAs_number` — number of sRNAs to display in the bar plots.
|
|
286
|
+
|
|
287
|
+
For example:
|
|
288
|
+
|
|
289
|
+
```bash
|
|
290
|
+
sRNAs-percent config_path 15
|
|
291
|
+
```
|
|
292
|
+
|
|
293
|
+
### RNA-seq normalization
|
|
294
|
+
|
|
295
|
+
Optionally, RNAseq counts can be provided:
|
|
296
|
+
|
|
297
|
+
```bash
|
|
298
|
+
sRNAs-percent config_path 15 --RNAseq_counts RNAseq_counts.txt
|
|
299
|
+
```
|
|
300
|
+
|
|
301
|
+
When RNA-seq counts are provided, an additional graph is generated showing the percentage of sRNAs according to their RNAseq representation.
|
|
302
|
+
|
|
303
|
+
---
|
|
304
|
+
|
|
305
|
+
## 6. Count supporting libraries
|
|
306
|
+
|
|
307
|
+
Calculate the number of libraries in which each RNA-RNA interaction is detected.
|
|
308
|
+
|
|
309
|
+
```bash
|
|
310
|
+
libraries-num config_path
|
|
311
|
+
```
|
|
312
|
+
|
|
313
|
+
The command also renames columns in the S-chimeras workbook.
|
|
314
|
+
|
|
315
|
+
**Warning:** Renaming the columns may break compatibility with other analysis scripts. Run this command only when the resulting workbook will not be used as input for scripts that depend on the original column names.
|
|
316
|
+
|
|
317
|
+
---
|
|
318
|
+
|
|
319
|
+
# Example Dataset
|
|
320
|
+
|
|
321
|
+
Example files are provided to facilitate validation of the workflow.
|
|
322
|
+
|
|
323
|
+
The example dataset contains a small subset of a complete RILseq dataset and can be used to verify that the analysis commands produce the expected output.
|
|
324
|
+
|
|
325
|
+
The example files correspond to the output generated during the downstream RILseq analysis workflow and can be used to reproduce the example figures.
|
|
326
|
+
|
|
327
|
+
A typical validation workflow is:
|
|
328
|
+
|
|
329
|
+
```bash
|
|
330
|
+
merge-results config.yaml file_names.txt
|
|
331
|
+
|
|
332
|
+
chimeras-venn config.yaml "Hfq_lambda_30-Hfq_lambda_60"
|
|
333
|
+
|
|
334
|
+
circos-plot two_genomes_half_circle config.yaml
|
|
335
|
+
|
|
336
|
+
annotations-graphs config.yaml
|
|
337
|
+
|
|
338
|
+
sRNAs-percent config.yaml 5
|
|
339
|
+
|
|
340
|
+
libraries-num config.yaml
|
|
341
|
+
```
|
|
342
|
+
|
|
343
|
+
---
|
|
344
|
+
|
|
345
|
+
# Input Files
|
|
346
|
+
|
|
347
|
+
Depending on the analysis, the package uses the following input files:
|
|
348
|
+
|
|
349
|
+
### `sig_interactions.txt`
|
|
350
|
+
|
|
351
|
+
Significant RNA-RNA interactions generated by the RILseq analysis pipeline for each library.
|
|
352
|
+
|
|
353
|
+
### `all_counts_table.txt`
|
|
354
|
+
|
|
355
|
+
Counts table (reads per gene for all libraries) generated by the RILseq analysis pipeline.
|
|
356
|
+
|
|
357
|
+
### GFF annotation file
|
|
358
|
+
|
|
359
|
+
The annotation file used by the RILseq pipeline.
|
|
360
|
+
|
|
361
|
+
### RNA annotation Excel file
|
|
362
|
+
|
|
363
|
+
An Excel file containing RNA names grouped into:
|
|
364
|
+
|
|
365
|
+
```text
|
|
366
|
+
sRNA
|
|
367
|
+
oRNA
|
|
368
|
+
rRNA
|
|
369
|
+
tRNA
|
|
370
|
+
```
|
|
371
|
+
|
|
372
|
+
### RNA-seq counts
|
|
373
|
+
|
|
374
|
+
Optional RNAseq counts used by `sRNAs-percent` to compare sRNA representation with RNA abundance.
|
|
375
|
+
|
|
376
|
+
---
|
|
377
|
+
|
|
378
|
+
# Output
|
|
379
|
+
|
|
380
|
+
Depending on the command, the package generates:
|
|
381
|
+
|
|
382
|
+
* Unified Excel workbooks containing results from multiple libraries.
|
|
383
|
+
* Venn diagrams comparing experimental conditions.
|
|
384
|
+
* Circos plots and Intermediate files.
|
|
385
|
+
* Annotation percentage bar plots.
|
|
386
|
+
* RNA1/RNA2 annotation heatmaps.
|
|
387
|
+
* sRNA percentage bar plots.
|
|
388
|
+
* Tables containing the number of supporting libraries for each interaction.
|
|
389
|
+
|
|
390
|
+
|
|
391
|
+
# RILseq
|
|
392
|
+
|
|
393
|
+
This package is intended for **downstream analysis** of RILseq results and does not perform the upstream processing of raw sequencing data.
|
|
394
|
+
|
|
395
|
+
For upstream RIL-seq processing, see the original RIL-seq computational pipeline:
|
|
396
|
+
|
|
397
|
+
https://github.com/asafpr/RILseq
|
|
398
|
+
|
|
399
|
+
---
|
|
400
|
+
|
|
401
|
+
# Citation
|
|
402
|
+
|
|
403
|
+
If you use `RILseq-analysis` in your work, please cite the corresponding RILseq study and the original RILseq methodology.
|
|
404
|
+
|
|
405
|
+
---
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
README.md
|
|
2
|
+
pyproject.toml
|
|
3
|
+
RILseq_analysis.egg-info/PKG-INFO
|
|
4
|
+
RILseq_analysis.egg-info/SOURCES.txt
|
|
5
|
+
RILseq_analysis.egg-info/dependency_links.txt
|
|
6
|
+
RILseq_analysis.egg-info/entry_points.txt
|
|
7
|
+
RILseq_analysis.egg-info/requires.txt
|
|
8
|
+
RILseq_analysis.egg-info/top_level.txt
|
|
9
|
+
RILseq_analysis_package/__init__.py
|
|
10
|
+
RILseq_analysis_package/annotations_graphs.py
|
|
11
|
+
RILseq_analysis_package/chimeras_venn_diagram.py
|
|
12
|
+
RILseq_analysis_package/circos_plot.py
|
|
13
|
+
RILseq_analysis_package/extract_genes_by_chr.py
|
|
14
|
+
RILseq_analysis_package/generate_and_edit_RILseq_xslx.py
|
|
15
|
+
RILseq_analysis_package/sRNAs_percent.py
|
|
16
|
+
RILseq_analysis_package/utils.py
|
|
17
|
+
RILseq_analysis_package/cli/__init__.py
|
|
18
|
+
RILseq_analysis_package/cli/add_number_of_libraries_cli.py
|
|
19
|
+
RILseq_analysis_package/cli/circos_plot_cli.py
|
|
20
|
+
RILseq_analysis_package/cli/merge_results_cli.py
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
[console_scripts]
|
|
2
|
+
annotations-graphs = RILseq_analysis_package.annotations_graphs:main
|
|
3
|
+
chimeras-venn = RILseq_analysis_package.chimeras_venn_diagram:main
|
|
4
|
+
circos-plot = RILseq_analysis_package.cli.circos_plot_cli:main
|
|
5
|
+
filter-genes = RILseq_analysis_package.extract_genes_by_chr:main
|
|
6
|
+
libraries-num = RILseq_analysis_package.cli.add_number_of_libraries_cli:main
|
|
7
|
+
merge-results = RILseq_analysis_package.cli.merge_results_cli:main
|
|
8
|
+
sRNAs-percent = RILseq_analysis_package.sRNAs_percent:main
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
RILseq_analysis_package
|
|
File without changes
|
|
@@ -0,0 +1,185 @@
|
|
|
1
|
+
import pandas as pd
|
|
2
|
+
import os
|
|
3
|
+
import seaborn as sns
|
|
4
|
+
import matplotlib.pyplot as plt
|
|
5
|
+
from RILseq_analysis_package.utils import get_annotation, get_RNA_types, load_config
|
|
6
|
+
import argparse
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
def get_gene_annotation(gene, genes, tRNAs, sRNAs, oRNAs):
|
|
11
|
+
if gene in tRNAs:
|
|
12
|
+
return "tRNA"
|
|
13
|
+
if gene in sRNAs:
|
|
14
|
+
return "sRNA"
|
|
15
|
+
if gene in oRNAs:
|
|
16
|
+
return "oRNA"
|
|
17
|
+
if "3UTR" in gene:
|
|
18
|
+
return "3UTR"
|
|
19
|
+
if "5UTR" in gene:
|
|
20
|
+
return "5UTR"
|
|
21
|
+
if "AS" in gene:
|
|
22
|
+
return "AS"
|
|
23
|
+
if "IGR" in gene:
|
|
24
|
+
return "IGR"
|
|
25
|
+
if "IGT" in gene:
|
|
26
|
+
return "IGT"
|
|
27
|
+
if gene in genes:
|
|
28
|
+
return "CDS"
|
|
29
|
+
return "unknown"
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
def get_RNAs_types(rna_types_excel):
|
|
33
|
+
sRNAs = set(get_RNA_types("sRNA", rna_types_excel))
|
|
34
|
+
tRNAs = set(get_RNA_types("tRNA", rna_types_excel))
|
|
35
|
+
oRNAs = set(get_RNA_types("oRNA", rna_types_excel))
|
|
36
|
+
return sRNAs, tRNAs, oRNAs
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
def RNA1_RNA2_annotations(chr_dic, base_path, experiments, rna_types_excel, annotation_path, chimeras_or_fragments, chrom=None):
|
|
40
|
+
"""
|
|
41
|
+
Creates heatmaps of the chimeras annotations, with and without the annotations numbers.
|
|
42
|
+
:param chimeras_or_fragments: if "chimeras" create the heatmaps according to the amount of chimeras. Else, according
|
|
43
|
+
to the amount of fragments.
|
|
44
|
+
:param chrom: if None, create the heatmaps base on the chimeras between the two chromosomes. Else, create the heatmaps
|
|
45
|
+
base on the chimeras of the given chromosome.
|
|
46
|
+
"""
|
|
47
|
+
genes = get_annotation(annotation_path, chromosome=chrom, separate_id_name=True)["name"].values.tolist()
|
|
48
|
+
sRNAs, tRNAs, oRNAs = get_RNAs_types(rna_types_excel)
|
|
49
|
+
if chrom:
|
|
50
|
+
dir_ = chr_dic[chrom] + "_annotation"
|
|
51
|
+
else:
|
|
52
|
+
dir_ = "_".join(chr_dic.values()) + "_annotation"
|
|
53
|
+
output_path = os.path.join(base_path, dir_)
|
|
54
|
+
if not os.path.exists(output_path):
|
|
55
|
+
os.makedirs(output_path)
|
|
56
|
+
for experiment in experiments:
|
|
57
|
+
df = pd.read_excel(os.path.join(base_path, "RILseq_unified_results.xlsx"), sheet_name=experiment)
|
|
58
|
+
if chrom is not None:
|
|
59
|
+
df = df[(df["RNA1 chromosome"] == chrom) & (df["RNA2 chromosome"] == chrom)]
|
|
60
|
+
else:
|
|
61
|
+
chr1, chr2 = chr_dic.keys()
|
|
62
|
+
df = df[((df["RNA1 chromosome"] == chr1) & (df["RNA2 chromosome"] == chr2)) |
|
|
63
|
+
((df["RNA1 chromosome"] == chr2) & (df["RNA2 chromosome"] == chr1))]
|
|
64
|
+
df["RNA1_annotation"] = df["RNA1 name"].apply(get_gene_annotation, genes=genes, tRNAs=tRNAs, sRNAs=sRNAs, oRNAs=oRNAs)
|
|
65
|
+
df["RNA2_annotation"] = df["RNA2 name"].apply(get_gene_annotation, genes=genes, tRNAs=tRNAs, sRNAs=sRNAs, oRNAs=oRNAs)
|
|
66
|
+
options = ["3UTR", "5UTR", "CDS", "AS", "IGR", "sRNA", "tRNA", "IGT"] #"oRNA"
|
|
67
|
+
|
|
68
|
+
if chimeras_or_fragments == "chimeras":
|
|
69
|
+
df["i"] = df.index
|
|
70
|
+
df = df[["RNA1_annotation", "RNA2_annotation", "i"]]
|
|
71
|
+
small_df = df.groupby(["RNA1_annotation", "RNA2_annotation"]).count()
|
|
72
|
+
small_df_pairs = small_df.index
|
|
73
|
+
amount = small_df["i"].values
|
|
74
|
+
else:
|
|
75
|
+
df = df[["RNA1_annotation", "RNA2_annotation", "interactions"]]
|
|
76
|
+
small_df = df.groupby(["RNA1_annotation", "RNA2_annotation"]).sum()
|
|
77
|
+
small_df_pairs = small_df.index
|
|
78
|
+
amount = small_df["interactions"].values
|
|
79
|
+
dic = {}
|
|
80
|
+
for i in range(len(amount)):
|
|
81
|
+
dic[small_df_pairs[i]] = amount[i]
|
|
82
|
+
results = pd.DataFrame(0, index=options, columns=options)
|
|
83
|
+
for option1 in options:
|
|
84
|
+
for option2 in options:
|
|
85
|
+
if (option1, option2) in small_df_pairs:
|
|
86
|
+
results.loc[option2, option1] = dic[(option1, option2)]
|
|
87
|
+
for annot in [True, False]:
|
|
88
|
+
plt.figure()
|
|
89
|
+
sns.heatmap(results, annot=annot, cmap='Blues', fmt=".6g", annot_kws={"size": 8})
|
|
90
|
+
plt.xlabel("RNA1")
|
|
91
|
+
plt.ylabel("RNA2")
|
|
92
|
+
with_annot = "with_annot" if annot else "without_annot"
|
|
93
|
+
plt.savefig(os.path.join(output_path, f"{experiment}_{chimeras_or_fragments}_{with_annot}.png"))
|
|
94
|
+
|
|
95
|
+
|
|
96
|
+
def get_RNAs_type_fractions(df, options, chimeras_or_fragments):
|
|
97
|
+
"""
|
|
98
|
+
:param df: chimeras data-frame
|
|
99
|
+
:param options: the annotations
|
|
100
|
+
:param chimeras_or_fragments: if "chimeras" calculate the fraction according to the amount of chimeras. Else, according
|
|
101
|
+
to the amount of fragments.
|
|
102
|
+
:return: a list of the fraction of each annotation
|
|
103
|
+
"""
|
|
104
|
+
if df.empty:
|
|
105
|
+
return [0] * len(options)
|
|
106
|
+
amount_dic = {i:0 for i in options}
|
|
107
|
+
for RNA in "12":
|
|
108
|
+
small_df = df[[f"RNA{RNA}_annotation", "interactions"]]
|
|
109
|
+
small_df = small_df.groupby([f"RNA{RNA}_annotation"])
|
|
110
|
+
if chimeras_or_fragments == "chimeras":
|
|
111
|
+
small_df = small_df.count()
|
|
112
|
+
elif chimeras_or_fragments == "fragments":
|
|
113
|
+
small_df = small_df.sum()
|
|
114
|
+
indexes = small_df.index
|
|
115
|
+
for index in indexes:
|
|
116
|
+
amount_dic[index] += small_df["interactions"][index]
|
|
117
|
+
amount_list = [amount_dic[i] for i in options]
|
|
118
|
+
amount_sum = sum(amount_list)
|
|
119
|
+
return [i/amount_sum for i in amount_list]
|
|
120
|
+
|
|
121
|
+
|
|
122
|
+
def chimeras_annotations(chr_dic, experiments, base_path, annotation_path, rna_types_excel, chimeras_or_fragments):
|
|
123
|
+
"""
|
|
124
|
+
Creates a bar plot of the annotation fraction for within and between chromosomes for each time point.
|
|
125
|
+
:param chimeras_or_fragments: if "chimeras" create the bar plot according to the amount of chimeras. Else, according
|
|
126
|
+
to the amount of fragments.
|
|
127
|
+
"""
|
|
128
|
+
genes = get_annotation(annotation_path, separate_id_name=True)["name"].values.tolist()
|
|
129
|
+
sRNAs, tRNAs, oRNAs = get_RNAs_types(rna_types_excel)
|
|
130
|
+
options = ["3UTR", "sRNA", "CDS", "5UTR", "IGR", "AS", "tRNA", "oRNA", "IGT"]
|
|
131
|
+
final_dic = {}
|
|
132
|
+
chr1, chr2 = chr_dic.keys()
|
|
133
|
+
chr1_name = chr_dic[chr1]
|
|
134
|
+
chr2_name = chr_dic[chr2]
|
|
135
|
+
for experiment in experiments:
|
|
136
|
+
df = pd.read_excel(os.path.join(base_path, "RILseq_unified_results.xlsx"), sheet_name=experiment)
|
|
137
|
+
df["RNA1_annotation"] = df["RNA1 name"].apply(get_gene_annotation, genes=genes, tRNAs=tRNAs, sRNAs=sRNAs, oRNAs=oRNAs)
|
|
138
|
+
df["RNA2_annotation"] = df["RNA2 name"].apply(get_gene_annotation, genes=genes, tRNAs=tRNAs, sRNAs=sRNAs, oRNAs=oRNAs)
|
|
139
|
+
chr1_df = df[(df["RNA1 chromosome"] == chr1) & (df["RNA2 chromosome"] == chr1)]
|
|
140
|
+
chr2_df = df[(df["RNA1 chromosome"] == chr2) & (df["RNA2 chromosome"] == chr2)]
|
|
141
|
+
chr1_chr2 = df[((df["RNA1 chromosome"] == chr1) & (df["RNA2 chromosome"] == chr2)) |
|
|
142
|
+
((df["RNA1 chromosome"] == chr2) & (df["RNA2 chromosome"] == chr1))]
|
|
143
|
+
if chimeras_or_fragments == "chimeras":
|
|
144
|
+
chr1_amount = chr1_df.shape[0]
|
|
145
|
+
chr1_chr2_amount = chr1_chr2.shape[0]
|
|
146
|
+
chr2_amount = chr2_df.shape[0]
|
|
147
|
+
else:
|
|
148
|
+
chr1_amount = chr1_df["interactions"].sum()
|
|
149
|
+
chr1_chr2_amount = chr1_chr2["interactions"].sum()
|
|
150
|
+
chr2_amount = chr2_df["interactions"].sum()
|
|
151
|
+
final_dic[f"{chr1_name}-{chr1_name} {experiment} ({chr1_amount})"] = get_RNAs_type_fractions(chr1_df, options, chimeras_or_fragments)
|
|
152
|
+
final_dic[f"{chr1_name}-{chr2_name} {experiment} ({chr1_chr2_amount})"] = get_RNAs_type_fractions(chr1_chr2, options, chimeras_or_fragments)
|
|
153
|
+
final_dic[f"{chr2_name}-{chr2_name} {experiment} ({chr2_amount})"] = get_RNAs_type_fractions(chr2_df, options, chimeras_or_fragments)
|
|
154
|
+
df = pd.DataFrame.from_dict(final_dic, orient="index", columns=options)
|
|
155
|
+
df = df[df.columns[(df != 0).any()]]
|
|
156
|
+
fig = plt.figure()
|
|
157
|
+
h = df.plot(kind="bar", linewidth=0, stacked=True, grid=False, cmap="tab20c")
|
|
158
|
+
plt.subplots_adjust(bottom=0.35, right=0.7)
|
|
159
|
+
plt.xticks(rotation=-45, ha='left')
|
|
160
|
+
handles, labels = h.get_legend_handles_labels()
|
|
161
|
+
plt.legend(handles[::-1], labels[::-1], loc=(1.1, 0))
|
|
162
|
+
plt.tight_layout()
|
|
163
|
+
plt.savefig(os.path.join(base_path, f"{chimeras_or_fragments}_annotation_fractions.png"))
|
|
164
|
+
|
|
165
|
+
|
|
166
|
+
def main():
|
|
167
|
+
parser = argparse.ArgumentParser(description="Create annotation heatmaps and annotation fraction plots for RIL-seq chimeras and fragments.")
|
|
168
|
+
|
|
169
|
+
parser.add_argument("config", help="Path to the YAML configuration file.")
|
|
170
|
+
|
|
171
|
+
args = parser.parse_args()
|
|
172
|
+
config = load_config(args.config)
|
|
173
|
+
|
|
174
|
+
for type_ in ("fragments", "chimeras"):
|
|
175
|
+
for chrom in config["chr_dic"].keys():
|
|
176
|
+
RNA1_RNA2_annotations(config["chr_dic"], config["base_path"], config["experiments"], config["rna_types_excel"], config["annotation_path"], type_, chrom)
|
|
177
|
+
RNA1_RNA2_annotations(config["chr_dic"], config["base_path"], config["experiments"], config["rna_types_excel"], config["annotation_path"], type_)
|
|
178
|
+
|
|
179
|
+
chimeras_annotations(config["chr_dic"], config["experiments"], config["base_path"], config["annotation_path"], config["rna_types_excel"], type_)
|
|
180
|
+
|
|
181
|
+
|
|
182
|
+
|
|
183
|
+
|
|
184
|
+
|
|
185
|
+
|