annotate maplot.py @ 0:835867b8ebd9 draft default tip

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