()
| 229 | |
| 230 | @report |
| 231 | def testDatastructuresTutorial(): |
| 232 | |
| 233 | ################################### |
| 234 | # Spectrum |
| 235 | # ******** |
| 236 | ################################### |
| 237 | |
| 238 | spectrum = MSSpectrum() |
| 239 | mz = range(1500, 500, -100) |
| 240 | i = [0 for mass in mz] |
| 241 | spectrum.set_peaks([mz, i]) |
| 242 | |
| 243 | # Sort the peaks according to ascending mass-to-charge ratio |
| 244 | spectrum.sortByPosition() |
| 245 | |
| 246 | # Iterate over spectrum of those peaks |
| 247 | for p in spectrum: |
| 248 | print(p.getMZ(), p.getIntensity()) |
| 249 | |
| 250 | # More efficient peak access |
| 251 | for mz, i in zip(*spectrum.get_peaks()): |
| 252 | print(mz, i) |
| 253 | |
| 254 | # Access a peak by index |
| 255 | print(spectrum[1].getMZ(), spectrum[1].getIntensity()) |
| 256 | |
| 257 | |
| 258 | ################################### |
| 259 | ################################### |
| 260 | |
| 261 | spectrum = MSSpectrum() |
| 262 | spectrum.setDriftTime(25) # 25 ms |
| 263 | spectrum.setRT(205.2) # 205.2 s |
| 264 | spectrum.setMSLevel(3) # MS3 |
| 265 | p = Precursor() |
| 266 | p.setIsolationWindowLowerOffset(1.5) |
| 267 | p.setIsolationWindowUpperOffset(1.5) |
| 268 | p.setMZ(600) # isolation at 600 +/- 1.5 Th |
| 269 | p.setActivationEnergy(40) # 40 eV |
| 270 | p.setCharge(4) # 4+ ion |
| 271 | spectrum.setPrecursors( [p] ) |
| 272 | |
| 273 | fda = FloatDataArray() |
| 274 | fda.setName("Signal to Noise Array") |
| 275 | fda.push_back(15) |
| 276 | sda = StringDataArray() |
| 277 | sda.setName("Peak annotation") |
| 278 | sda.push_back("y15++") |
| 279 | spectrum.setFloatDataArrays( [fda] ) |
| 280 | spectrum.setStringDataArrays( [sda] ) |
| 281 | spectrum.set_peaks( ([401.5], [900]) ) |
| 282 | |
| 283 | # Store as mzML |
| 284 | exp = MSExperiment() |
| 285 | exp.addSpectrum(spectrum) |
| 286 | spectrum = MSSpectrum() |
| 287 | spectrum.set_peaks( ([1, 2], [1, 2]) ) |
| 288 | exp.addSpectrum(spectrum) |
nothing calls this directly
no test coverage detected