Exemplo n.º 1
0
	def test_getSpectra_rtWindow(self):
		mzmlInstance = pymzml.run.Reader(testFolder+'mzml_test_file_1.mzML')
		spectraLocation = getWindow.SpectraLocation(mzmlInstance)
		spectraList = []
		for spectrum in spectraLocation.getSpectra_rtWindow(300, 500):
			spectraList.append(spectrum)
		
		self.assertIs(1, len(spectraList))
Exemplo n.º 2
0
	def test_getSpectra_mzWindow(self):
		mzmlInstance = pymzml.run.Reader(testFolder+'mzml_testFIle_withBinary.mzML')
		spectraLocation = getWindow.SpectraLocation(mzmlInstance)
		spectraList = []
		for spectrum in spectraLocation.getSpectra_mzWindow(400, 500):
			spectraList.append(spectrum)
		
		self.assertEqual(12998, len(spectraList))
Exemplo n.º 3
0
 def getIntensityFromMZwindow(self, lowerMass, upperMass):
     """
     Get the summed intensity per run time. Iterate through the spectra, take the MS1 spectrum, isolate the mass range and sum the intensity, 
     returning the sum of intensity and RT as a dictionary (with RT as key, intensity as value).
  
     Essentially you are taking the area under the intensity-m/z curve as the single intensity point.
 
     @type lowerMass: Number
     @param lowerMass: The lower boundary of the m/z window to calculate the XIC over
     @type lowerMass: Number
     @param lowerMass: The upper boundary of the m/z window to calculate the XIC over
     @raise TypeError: lowerMass not of int
     @raise TypeError: upperMass not of type int
     @raise RuntimeError: No spectra with MS 1 in that window
     @rtype: Two lists
     @return: List of retention times and corresponding summed intensity. Both are sorted.
     
     B{Example:}
     
     >>> import pymzml
     >>> mzmlInstance = pymzml.run.Reader('/example_file.mzML')
     >>> print massWindow_XIC_plot(mzmlInstance, 800, 804)
     """
     if not isinstance(lowerMass, int) and not isinstance(lowerMass, float):
         raise TypeError, 'lowerMass given to massWindow_XIC_plot is not of type int or float. Instead, is of type: '+str(type(lowerMass))
     if not isinstance(upperMass, int) and not isinstance(upperMass, float):
         raise TypeError, 'upperMass given to massWindow_XIC_plot is not of type int or float. Instead, is of type: '+str(type(upperMass))
         
     if not self.spectrumLocation:
         self.spectrumLocation = getWindow.SpectraLocation(self.mzmlInstance)
 
     # dict of intensity per retention time (retention time as key,  intensity as value). Is defaultdict so intensity can be added to the value to sum
     intensityDict = collections.defaultdict(int)
     
     # counter for # of spectra
     specCount = 0
     for spectrum, intensity in self.spectrumLocation.getSpectra_mzWindow(lowerMass, upperMass):
         if spectrum['ms level'] > 1:
             # make seconds out of the retention time and use as key in dict. sum the intensity
             intensityDict[(float(spectrum['scan time'])*60)] += float(intensity)
             specCount += 1
     
     if specCount == 0:
         raise RuntimeError, 'No spectra with MS level 1 in that mz window'
     
     # sort the keys of intensityDict
     sortedRetentionTime = sorted(intensityDict.iterkeys())
     sortedIntensity = []
     for key in sortedRetentionTime:
         sortedIntensity.append(intensityDict[key])
     
     del intensityDict
     
     return sortedRetentionTime, sortedIntensity
Exemplo n.º 4
0
	def test_getSpectra_rtWindowException(self):
		mzmlInstance = pymzml.run.Reader(testFolder+'mzml_test_file_1.mzML')
		spectraLocation = getWindow.SpectraLocation(mzmlInstance)
		self.assertRaises(TypeError, lambda: spectraLocation.getSpectra_rtWindow, 'not an int', 1)
		self.assertRaises(TypeError, lambda: spectraLocation.getSpectra_rtWindow , 1, 'not an int')