Spectra¶
Spectrum¶
Spectrum
¶
A 2D spectrum loaded from a Sparky .ucsf file: the data array plus its
per-axis unit-conversion objects (for ppm <-> point conversions).
Attributes:
| Name | Type | Description |
|---|---|---|
data |
ndarray
|
The intensity array (axis 0 = indirect/N, axis 1 = direct/H). |
uc |
list
|
One nmrglue unit-conversion object per axis. |
Source code in makeshift/spectra/spectrum.py
from_ucsf
classmethod
¶
Read a Sparky .ucsf file into a Spectrum.
Source code in makeshift/spectra/spectrum.py
estimate_background
¶
Noise-floor estimate: median absolute intensity over n randomly
sampled points. Deterministic for a given seed.
pick_peaks
¶
Pick peaks in the amide region of this 2D ¹H-¹⁵N spectrum.
Peaks above baseline × the noise floor (estimated within the ¹H
window) are picked with nmrglue.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
baseline
|
float
|
Threshold multiple of the noise floor. |
10
|
algorithm
|
str
|
nmrglue peak-picking algorithm ('downward' or 'connected'). |
'downward'
|
est_params
|
bool
|
Have nmrglue estimate linewidths/volumes. |
True
|
h_ppm_min
|
float
|
¹H window to search (ppm). |
6.0
|
h_ppm_max
|
float
|
¹H window to search (ppm). |
6.0
|
Returns:
| Type | Description |
|---|---|
DataFrame
|
One row per picked peak with columns N_axis, H_axis, N_lw, H_lw,
est_vol, cid, N_ppm, H_ppm. |
Source code in makeshift/spectra/spectrum.py
Peak-list matching¶
map_peaklists
¶
map_peaklists(left, right, offset=None, tol=1, label_cols=('assn_label', 'assn_label'), how='inner')
Align two peak lists in (H_ppm, N_ppm) and match them one-to-one.
Align two peak lists in (H_ppm, N_ppm) and match them one-to-one.
right (e.g. a reference assignment list) is shifted by a translation
offset — grid-searched if offset is None — then Hungarian-matched to
left (treated as fixed) within tolerance. Right-side peaks that lost a
close match to a competitor are flagged in a conflict column.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
left
|
DataFrame
|
Peak tables with H_ppm/N_ppm columns (pass a PeakList's |
required |
right
|
DataFrame
|
Peak tables with H_ppm/N_ppm columns (pass a PeakList's |
required |
offset
|
(float, float) or None
|
(Δ¹H, Δ¹⁵N) applied to |
None
|
tol
|
float
|
Multiplier on the default matching tolerances (0.03, 0.3) ppm. |
1
|
label_cols
|
(str, str)
|
Label columns on (left, right); either may be None. |
('assn_label', 'assn_label')
|
how
|
(inner, left, right, outer)
|
pandas-merge semantics for |
"inner"
|
Returns:
| Name | Type | Description |
|---|---|---|
left_out |
DataFrame
|
Matched peaks with the right label + |
right_mapped |
DataFrame
|
Full right peaklist after the offset (for plotting). |
Source code in makeshift/spectra/matching.py
Plotting¶
plot_spectrum
¶
plot_spectrum(ref_data, contour_levels=8, cmap='plasma', contour_color=None, linewidth=0.8, vmax_scale=0.5, xlim=None, ylim=None, baseline=10, figsize=(8, 7), ax=None)
Plot 2D spectrum contours.
Use plot_peaklist to overlay peak markers/labels on the returned axes
Source code in makeshift/spectra/plotting.py
plot_peaklist
¶
plot_peaklist(peaks_df=None, ax=None, marker='x', peaks_xcol='H_ppm', peaks_ycol='N_ppm', color='limegreen', markersize=3, text='assn_label', label_fontsize=6, label=None, hue=None, palette=None, figsize=(8, 6))
Plot peak markers (and optional labels), optionally onto an existing axes.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
peaks_df
|
DataFrame
|
Peaks to plot. |
None
|
ax
|
matplotlib Axes or None
|
Axes to plot onto. If None, a new figure is created with inverted axes (H on x, N on y, both increasing toward origin as in NMR convention). |
None
|
markersize
|
float
|
Marker size for peak positions. |
3
|
text
|
str or None
|
Column in peaks_df to use for per-peak text annotations. Pass None to suppress these. |
'assn_label'
|
label
|
str or None
|
Legend label for this peaklist. When hue is None, passed straight to ax.plot (and a legend is drawn if set). When hue is set, this is ignored — each hue group gets its own legend entry instead. |
None
|
hue
|
str or None
|
Column in peaks_df to colour peaks by. When set, each unique value gets
its own colour from |
None
|
palette
|
dict or None
|
Maps hue values to matplotlib colours. Values absent from the dict fall back to 'gray'. Ignored when hue is None. |
None
|
Source code in makeshift/spectra/plotting.py
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 | |
plot_csp
¶
plot_csp(peaks_df1, peaks_df2, on, xcol='H_ppm', ycol='N_ppm', color1='steelblue', color2='tab:orange', line_color='gray', line_alpha=0.5, marker='o', markersize=4, text=None, label_fontsize=6, hue=None, palette=None, ax=None, figsize=(8, 6))
Plot two matched peaklists and draw connecting lines between paired peaks.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
peaks_df1
|
DataFrame
|
The two peaklists to compare (e.g. apo and holo, or two conditions). |
required |
peaks_df2
|
DataFrame
|
The two peaklists to compare (e.g. apo and holo, or two conditions). |
required |
on
|
str or list of str
|
Column(s) to merge on — the shared identifier between the two peaklists (e.g. 'assn_label', 'Seq_ID', or ['chain', 'Seq_ID']). |
required |
xcol
|
str
|
Column names for H and N chemical shifts in both DataFrames. |
'H_ppm'
|
ycol
|
str
|
Column names for H and N chemical shifts in both DataFrames. |
'H_ppm'
|
color1
|
str
|
Marker colours for peaks_df1 and peaks_df2 respectively. Ignored when hue is set. |
'steelblue'
|
color2
|
str
|
Marker colours for peaks_df1 and peaks_df2 respectively. Ignored when hue is set. |
'steelblue'
|
line_color
|
(str, float)
|
Style for the connecting lines. |
'gray'
|
line_alpha
|
(str, float)
|
Style for the connecting lines. |
'gray'
|
marker
|
str
|
Matplotlib marker string applied to peaks_df1. peaks_df2 is always drawn with a triangle marker ("^"). |
'o'
|
markersize
|
float
|
|
4
|
text
|
str or None
|
Column in peaks_df1 to use for per-peak annotations. Pass None to suppress. |
None
|
label_fontsize
|
int
|
|
6
|
hue
|
str or None
|
Column in peaks_df1 to colour matched pairs by. |
None
|
palette
|
dict, str, list, or None
|
Colour mapping for hue values. A dict maps values straight to colours Ignored when hue is None. |
None
|
ax
|
matplotlib Axes or None
|
Axes to plot onto. Creates a new figure if None. |
None
|
figsize
|
tuple
|
|
(8, 6)
|
Source code in makeshift/spectra/plotting.py
174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 | |