Mercurial > repos > iuc > maplot
annotate maplot.py @ 0:e9212adafd7a draft default tip
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
author | iuc |
---|---|
date | Thu, 15 May 2025 12:55:13 +0000 |
parents | |
children |
rev | line source |
---|---|
0
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
1 import argparse |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
2 from typing import Dict, List, Tuple |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
3 |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
4 import matplotlib.pyplot as plt |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
5 import numpy as np |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
6 import pandas as pd |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
7 import plotly.graph_objects as go |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
8 import plotly.io as pio |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
9 import plotly.subplots as sp |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
10 import statsmodels.api as sm # to build a LOWESS model |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
11 from scipy.stats import gaussian_kde |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
12 |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
13 |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
14 # subplot titles |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
15 def make_subplot_titles(sample_names: List[str]) -> List[str]: |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
16 """Generates subplot titles for the MA plot. |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
17 |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
18 Args: |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
19 sample_names (list): List of sample names. |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
20 |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
21 Returns: |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
22 list: List of subplot titles. |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
23 """ |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
24 subplot_titles = [] |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
25 num_samples = len(sample_names) |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
26 for i in range(num_samples): |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
27 for j in range(num_samples): |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
28 if i == j: |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
29 subplot_titles.append(f"{sample_names[i]}") |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
30 else: |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
31 subplot_titles.append(f"{sample_names[i]} vs. {sample_names[j]}") |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
32 return subplot_titles |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
33 |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
34 |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
35 def densities(x: np.ndarray, y: np.ndarray) -> np.ndarray: |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
36 """Calculates the density of points for a scatter plot. |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
37 |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
38 Args: |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
39 x (array-like): X-axis values. |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
40 y (array-like): Y-axis values. |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
41 |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
42 Returns: |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
43 array: Density values for the points. |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
44 """ |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
45 values = np.vstack([x, y]) |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
46 return gaussian_kde(values)(values) |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
47 |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
48 |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
49 def movingaverage(data: np.ndarray, window_width: int) -> np.ndarray: |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
50 """Calculates the moving average of the data. |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
51 |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
52 Args: |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
53 data (array-like): Input data. |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
54 window_width (int): Width of the moving window. |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
55 |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
56 Returns: |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
57 array: Moving average values. |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
58 """ |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
59 cumsum_vec = np.cumsum(np.insert(data, 0, 0)) |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
60 ma_vec = (cumsum_vec[window_width:] - cumsum_vec[:-window_width]) / window_width |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
61 return ma_vec |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
62 |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
63 |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
64 def update_max(current: float, values: np.ndarray) -> float: |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
65 """Updates the maximum value. |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
66 |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
67 Args: |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
68 current (float): Current maximum value. |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
69 values (array-like): Array of values to compare. |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
70 |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
71 Returns: |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
72 float: Updated maximum value. |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
73 """ |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
74 return max(current, np.max(values)) |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
75 |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
76 |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
77 def get_indices( |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
78 num_samples: int, num_cols: int, plot_num: int |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
79 ) -> Tuple[int, int, int, int]: |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
80 """Calculates the indices for subplot placement. |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
81 |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
82 Args: |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
83 num_samples (int): Number of samples. |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
84 num_cols (int): Number of columns in the subplot grid. |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
85 plot_num (int): Plot number. |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
86 |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
87 Returns: |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
88 tuple: Indices for subplot placement (i, j, col, row). |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
89 """ |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
90 i = plot_num // num_samples |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
91 j = plot_num % num_samples |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
92 col = plot_num % num_cols + 1 |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
93 row = plot_num // num_cols + 1 |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
94 return i, j, col, row |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
95 |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
96 |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
97 def create_subplot_data( |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
98 frac: float, |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
99 it: int, |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
100 num_bins: int, |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
101 window_width: int, |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
102 samples: pd.DataFrame, |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
103 i: int, |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
104 j: int, |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
105 ) -> Dict: |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
106 """Creates data for a single subplot. |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
107 |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
108 Args: |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
109 frac (float): LOESS smoothing parameter. |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
110 it (int): Number of iterations for LOESS smoothing. |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
111 num_bins (int): Number of bins for histogram. |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
112 window_width (int): Window width for moving average. |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
113 samples (DataFrame): DataFrame containing sample data. |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
114 i (int): Index of the first sample. |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
115 j (int): Index of the second sample. |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
116 |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
117 Returns: |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
118 dict: Data for the subplot. |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
119 """ |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
120 subplot_data = {} |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
121 subplot_data["mean"] = np.log(samples.iloc[:, [i, j]].mean(axis=1)) |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
122 if i == j: |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
123 counts, bins = np.histogram(subplot_data["mean"], bins=num_bins) |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
124 subplot_data["bins"] = bins |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
125 subplot_data["counts"] = counts |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
126 subplot_data["counts_smoothed"] = movingaverage(counts, window_width) |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
127 subplot_data["max_counts"] = np.max(counts) |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
128 else: |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
129 subplot_data["log_fold_change"] = np.log2( |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
130 samples.iloc[:, i] / samples.iloc[:, j] |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
131 ) |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
132 subplot_data["max_log_fold_change"] = np.max(subplot_data["log_fold_change"]) |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
133 subplot_data["densities"] = densities( |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
134 subplot_data["mean"], subplot_data["log_fold_change"] |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
135 ) |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
136 subplot_data["regression"] = sm.nonparametric.lowess( |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
137 subplot_data["log_fold_change"], subplot_data["mean"], frac=frac, it=it |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
138 ) |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
139 return subplot_data |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
140 |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
141 |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
142 def create_plot_data( |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
143 frac: float, |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
144 it: int, |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
145 num_bins: int, |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
146 window_width: int, |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
147 samples: pd.DataFrame, |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
148 num_samples: int, |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
149 num_plots: int, |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
150 num_cols: int, |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
151 ) -> List[Dict]: |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
152 """Creates data for all subplots. |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
153 |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
154 Args: |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
155 frac (float): LOESS smoothing parameter. |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
156 it (int): Number of iterations for LOESS smoothing. |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
157 num_bins (int): Number of bins for histogram. |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
158 window_width (int): Window width for moving average. |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
159 samples (DataFrame): DataFrame containing sample data. |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
160 num_samples (int): Number of samples. |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
161 num_plots (int): Number of plots. |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
162 num_cols (int): Number of columns in the subplot grid. |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
163 |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
164 Returns: |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
165 list: List of data for each subplot. |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
166 """ |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
167 plots_data = [] |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
168 for plot_num in range(num_plots): |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
169 i, j, _, _ = get_indices(num_samples, num_cols, plot_num) |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
170 subplot_data = create_subplot_data( |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
171 frac, it, num_bins, window_width, samples, i, j |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
172 ) |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
173 plots_data.append(subplot_data) |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
174 return plots_data |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
175 |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
176 |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
177 def ma_plots_plotly( |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
178 num_rows: int, |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
179 num_cols: int, |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
180 num_plots: int, |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
181 plots_data: List[Dict], |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
182 sample_names: List[str], |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
183 size: int, |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
184 ylim_hist: float, |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
185 ylim_ma: float, |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
186 features: np.ndarray, |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
187 ) -> go.Figure: |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
188 """Generates MA plots using Plotly. |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
189 |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
190 Args: |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
191 num_rows (int): Number of rows in the subplot grid. |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
192 num_cols (int): Number of columns in the subplot grid. |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
193 num_plots (int): Number of plots. |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
194 plots_data (list): List of data for each subplot. |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
195 sample_names (list): List of sample names. |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
196 size (int): Size of the plot. |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
197 ylim_hist (float): Y-axis limit for histograms. |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
198 ylim_ma (float): Y-axis limit for MA plots. |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
199 features (array-like): Feature names. |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
200 |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
201 Returns: |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
202 Figure: Plotly figure object. |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
203 """ |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
204 fig = sp.make_subplots( |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
205 rows=num_rows, |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
206 cols=num_cols, |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
207 shared_xaxes="all", |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
208 subplot_titles=make_subplot_titles(sample_names), |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
209 ) |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
210 |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
211 for plot_num in range(num_plots): |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
212 i, j, col, row = get_indices(len(sample_names), num_cols, plot_num) |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
213 subplot_data = plots_data[plot_num] |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
214 |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
215 mean = subplot_data["mean"] |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
216 |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
217 if i == j: |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
218 # Plot histogram on the diagonal |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
219 hist_bar = go.Bar( |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
220 x=subplot_data["bins"], |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
221 y=subplot_data["counts"], |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
222 ) |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
223 fig.add_trace(hist_bar, row=row, col=col) |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
224 |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
225 hist_line = go.Scatter( |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
226 x=subplot_data["bins"], |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
227 y=subplot_data["counts_smoothed"], |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
228 marker=dict( |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
229 color="red", |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
230 ), |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
231 ) |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
232 fig.add_trace(hist_line, row=row, col=col) |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
233 fig.update_yaxes( |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
234 title_text="Counts", |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
235 range=[0, ylim_hist], |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
236 matches="y1", |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
237 showticklabels=True, |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
238 row=row, |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
239 col=col, |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
240 ) |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
241 else: |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
242 log_fold_change = subplot_data["log_fold_change"] |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
243 scatter = go.Scatter( |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
244 x=mean, |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
245 y=log_fold_change, |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
246 mode="markers", |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
247 marker=dict( |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
248 color=subplot_data["densities"], symbol="circle", colorscale="jet" |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
249 ), |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
250 name=f"{sample_names[i]} vs {sample_names[j]}", |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
251 text=features, |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
252 hovertemplate="<b>%{text}</b><br>Log Mean: %{x}<br>Log2 Fold Change: %{y}<extra></extra>", |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
253 ) |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
254 fig.add_trace(scatter, row=row, col=col) |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
255 |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
256 regression = subplot_data["regression"] |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
257 line = go.Scatter( |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
258 x=regression[:, 0], |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
259 y=regression[:, 1], |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
260 mode="lines", |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
261 line=dict(color="red"), |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
262 name=f"LOWESS {sample_names[i]} vs. {sample_names[j]}", |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
263 ) |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
264 fig.add_trace(line, row=row, col=col) |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
265 |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
266 fig.update_yaxes( |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
267 title_text="Log2 Fold Change", |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
268 range=[-ylim_ma, ylim_ma], |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
269 matches="y2", |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
270 showticklabels=True, |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
271 row=row, |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
272 col=col, |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
273 ) |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
274 fig.update_xaxes( |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
275 title_text="Log Mean Intensity", showticklabels=True, row=row, col=col |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
276 ) |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
277 |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
278 # Update layout for the entire figure |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
279 fig.update_layout( |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
280 height=size * num_rows, |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
281 width=size * num_cols, |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
282 showlegend=False, |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
283 template="simple_white", # Apply the 'plotly_white' template |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
284 ) |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
285 return fig |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
286 |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
287 |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
288 def ma_plots_matplotlib( |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
289 num_rows: int, |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
290 num_cols: int, |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
291 num_plots: int, |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
292 pots_data: List[Dict], |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
293 sample_names: List[str], |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
294 size: int, |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
295 ylim_hist: float, |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
296 ylim_ma: float, |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
297 window_width: int, |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
298 ) -> plt.Figure: |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
299 """Generates MA plots using Matplotlib. |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
300 |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
301 Args: |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
302 num_rows (int): Number of rows in the subplot grid. |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
303 num_cols (int): Number of columns in the subplot grid. |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
304 num_plots (int): Number of plots. |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
305 pots_data (list): List of data for each subplot. |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
306 sample_names (list): List of sample names. |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
307 size (int): Size of the plot. |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
308 ylim_hist (float): Y-axis limit for histograms. |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
309 ylim_ma (float): Y-axis limit for MA plots. |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
310 window_width (int): Window width for moving average. |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
311 |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
312 Returns: |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
313 Figure: Matplotlib figure object. |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
314 """ |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
315 subplot_titles = make_subplot_titles(sample_names) |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
316 fig, axes = plt.subplots( |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
317 num_rows, |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
318 num_cols, |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
319 figsize=(size * num_cols / 100, size * num_rows / 100), |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
320 dpi=300, |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
321 sharex="all", |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
322 ) |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
323 axes = axes.flatten() |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
324 |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
325 for plot_num in range(num_plots): |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
326 i, j, _, _ = get_indices(len(sample_names), num_cols, plot_num) |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
327 subplot_data = pots_data[plot_num] |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
328 |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
329 mean = subplot_data["mean"] |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
330 |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
331 ax = axes[plot_num] |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
332 |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
333 if i == j: |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
334 # Plot histogram on the diagonal |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
335 ax.bar( |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
336 subplot_data["bins"][:-1], |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
337 subplot_data["counts"], |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
338 width=np.diff(subplot_data["bins"]), |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
339 edgecolor="black", |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
340 align="edge", |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
341 ) |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
342 |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
343 # Plot moving average line |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
344 ax.plot( |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
345 subplot_data["bins"][window_width // 2: -window_width // 2], |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
346 subplot_data["counts_smoothed"], |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
347 color="red", |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
348 ) |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
349 |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
350 ax.set_ylabel("Counts") |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
351 ax.set_ylim(0, ylim_hist) |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
352 else: |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
353 # Scatter plot |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
354 ax.scatter( |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
355 mean, |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
356 subplot_data["log_fold_change"], |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
357 c=subplot_data["densities"], |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
358 cmap="jet", |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
359 edgecolor="black", |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
360 label=f"{sample_names[i]} vs {sample_names[j]}", |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
361 ) |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
362 |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
363 # Regression line |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
364 regression = subplot_data["regression"] |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
365 ax.plot( |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
366 regression[:, 0], |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
367 regression[:, 1], |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
368 color="red", |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
369 label=f"LOWESS {sample_names[i]} vs. {sample_names[j]}", |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
370 ) |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
371 |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
372 ax.set_ylabel("Log2 Fold Change") |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
373 ax.set_ylim(-ylim_ma, ylim_ma) |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
374 |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
375 ax.set_xlabel("Log Mean Intensity") |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
376 ax.tick_params(labelbottom=True) # Force showing x-tick labels |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
377 ax.set_title(subplot_titles[plot_num]) # Add subplot title |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
378 |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
379 # Adjust layout |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
380 plt.tight_layout() |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
381 return fig |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
382 |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
383 |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
384 def main(): |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
385 """Main function to generate MA plots.""" |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
386 parser = argparse.ArgumentParser(description="Generate MA plots.") |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
387 parser.add_argument("--file_path", type=str, help="Path to the input CSV file") |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
388 parser.add_argument("--file_extension", type=str, help="File extension") |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
389 parser.add_argument( |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
390 "--frac", type=float, default=4 / 5, help="LOESS smoothing parameter" |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
391 ) |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
392 parser.add_argument( |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
393 "--it", type=int, default=5, help="Number of iterations for LOESS smoothing" |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
394 ) |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
395 parser.add_argument( |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
396 "--num_bins", type=int, default=100, help="Number of bins for histogram" |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
397 ) |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
398 parser.add_argument( |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
399 "--window_width", type=int, default=5, help="Window width for moving average" |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
400 ) |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
401 parser.add_argument("--size", type=int, default=500, help="Size of the plot") |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
402 parser.add_argument( |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
403 "--scale", type=int, default=3, help="Scale factor for the plot" |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
404 ) |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
405 parser.add_argument( |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
406 "--y_scale_factor", type=float, default=1.1, help="Y-axis scale factor" |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
407 ) |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
408 parser.add_argument( |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
409 "--max_num_cols", |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
410 type=int, |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
411 default=100, |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
412 help="Maximum number of columns in the plot", |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
413 ) |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
414 parser.add_argument( |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
415 "--interactive", |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
416 action="store_true", |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
417 help="Generate interactive plot using Plotly", |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
418 ) |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
419 parser.add_argument( |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
420 "--output_format", |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
421 type=str, |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
422 default="pdf", |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
423 choices=["pdf", "png", "html"], |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
424 help="Output format for the plot", |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
425 ) |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
426 parser.add_argument( |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
427 "--output_file", |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
428 type=str, |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
429 default="ma_plot", |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
430 help="Output file name without extension", |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
431 ) |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
432 |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
433 args = parser.parse_args() |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
434 |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
435 # Load the data |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
436 file_extension = args.file_extension.lower() |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
437 if file_extension == "csv": |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
438 data = pd.read_csv(args.file_path) |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
439 elif file_extension in ["txt", "tsv", "tabular"]: |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
440 data = pd.read_csv(args.file_path, sep="\t") |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
441 elif file_extension == "parquet": |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
442 data = pd.read_parquet(args.file_path) |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
443 else: |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
444 raise ValueError(f"Unsupported file format: {file_extension}") |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
445 |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
446 features = data.iloc[:, 0] # Assuming the first column is the feature names |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
447 samples = data.iloc[:, 1:] # and the rest are samples |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
448 |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
449 # Create a subplot figure |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
450 num_samples = samples.shape[1] |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
451 sample_names = samples.columns |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
452 num_plots = num_samples**2 |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
453 num_cols = min(num_samples, args.max_num_cols) |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
454 num_rows = int(np.ceil(num_plots / num_cols)) |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
455 |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
456 plots_data = create_plot_data( |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
457 args.frac, |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
458 args.it, |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
459 args.num_bins, |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
460 args.window_width, |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
461 samples, |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
462 num_samples, |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
463 num_plots, |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
464 num_cols, |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
465 ) |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
466 |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
467 count_max = np.max([x.get("max_counts", 0) for x in plots_data]) |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
468 log_fold_change_max = np.max([x.get("max_log_fold_change", 0) for x in plots_data]) |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
469 |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
470 ylim_hist = count_max * args.y_scale_factor |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
471 ylim_ma = log_fold_change_max * args.y_scale_factor |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
472 |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
473 if args.interactive: |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
474 fig = ma_plots_plotly( |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
475 num_rows, |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
476 num_cols, |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
477 num_plots, |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
478 plots_data, |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
479 sample_names, |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
480 args.size, |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
481 ylim_hist, |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
482 ylim_ma, |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
483 features, |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
484 ) |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
485 fig.show() |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
486 if args.output_format == "html": |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
487 fig.write_html(f"{args.output_file}") |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
488 else: |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
489 pio.write_image( |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
490 fig, |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
491 f"{args.output_file}", |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
492 format=args.output_format, |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
493 width=args.size * num_cols, |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
494 height=args.size * num_rows, |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
495 scale=args.scale, |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
496 ) |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
497 else: |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
498 fig = ma_plots_matplotlib( |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
499 num_rows, |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
500 num_cols, |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
501 num_plots, |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
502 plots_data, |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
503 sample_names, |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
504 args.size, |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
505 ylim_hist, |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
506 ylim_ma, |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
507 args.window_width, |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
508 ) |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
509 plt.show() |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
510 fig.savefig(f"{args.output_file}", format=args.output_format, dpi=300) |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
511 return 0 |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
512 |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
513 |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
514 if __name__ == "__main__": |
e9212adafd7a
planemo upload for repository https://github.com/galaxyproject/tools-iuc commit d5065f0bdf2d38c2344d96d68537223c1096daab
iuc
parents:
diff
changeset
|
515 main() |