示例#1
0
    def test_getKeys_exclusive(self):
        # test getKeys with some keys excluded
        expectedSpectrumKeys = set(['total ion current chromatogram', 'time array', '32-bit float', 'total ion current chromatogram', 'no compression', 'total ion current'])
        expectedPrecursorKeys = set([])

        
        msrun = pymzml.run.Reader(testFolder+'mzml_testFIle_withBinary.mzML')
        actualSpectrumKeys, actualPrecursorKeys, spectrumList = mzmlFunctions.getKeys(msrun, excludeList = ['scan time', 'filter string', 'PY:0000000', 'precursors', 'id', 'profile mass spectrum','collision-induced dissociation', '64-bit float', 'defaultArrayLength', 'm/z array', 'charge state', 'None', 'ms level', 'intensity array', 'BinaryArrayOrder', 'encodedData', 'mz'])
        
        self.assertSetEqual(expectedSpectrumKeys, actualSpectrumKeys)
        self.assertSetEqual(expectedPrecursorKeys, actualPrecursorKeys)
示例#2
0
    def test_getKeys_default(self):    
        # test getKeys with default, so no excluded or included keys
        expectedSpectrumKeys = set(['no compression', 'total ion current', 'scan time', 'filter string', 'id', 'profile mass spectrum',
                                     '64-bit float', 'defaultArrayLength', 'm/z array', 'ms level', 'intensity array',
                                     'BinaryArrayOrder', '32-bit float', 'total ion current chromatogram', 'time array'])
        expectedPrecursorKeys = set([])
       
        msrun = pymzml.run.Reader(testFolder+'mzml_testFIle_withBinary.mzML')
        actualSpectrumKeys, actualPrecursorKeys, spectrumList = mzmlFunctions.getKeys(msrun)

        self.assertSetEqual(expectedSpectrumKeys, actualSpectrumKeys)
        self.assertSetEqual(expectedPrecursorKeys, actualPrecursorKeys)
示例#3
0
文件: output.py 项目: npklein/pyMSA
    def __init__(self, path, msrun):
        # using r in front of doc string because otherwise \t isn't recognised
        r"""

		@type path: string
		@param path: path for output file
		@type msrun: pymzml.run.Reader
		@param msrun: An instance of pymzml.run.Reader()

		B{Example}:

		Write an instance of pymzml.run.Reader to a csv file:

		>>> msrun = pymzml.run.Reader('example_mzML_file.mzML')						# instance of pymzml.run.Reader
		>>> writer = MsrunCsvWriter('example_outfile.csv', msrun)					# write the csv file
		"""

        # Use the FileHandler class to open the file and close if after writing is done
        with FileWriter(path) as fw:
            # a list of all the columns the user do not want in the ms/ms file from the configfile

            excludeList = config.get(
                'data', 'excludeMsrunCsvColumns').strip(' ').split(',')
            # a list of all the columns the user want sin the ms/ms file from the configfile that are not in feature.keys()
            includeList = config.get(
                'data', 'includeMsrunCsvColumns').strip(' ').split(',')
            # spectrumKeys will contain the column header names
            spectrumKeys, precursorKeys, spectrumList = mzmlFunctions.getKeys(
                msrun, excludeList, includeList)

            # write the column names
            fw.csvWriteLine(list(spectrumKeys))

            # loop through the spectra that were used in mzmlFunctions.getKeys (spectrumList) and the ones left over in msrun
            # itertools.izip makes an iterator of two lists
            for spectrum in itertools.izip(spectrumList, msrun):
                if spectrum[0]['id'] != 'TIC':
                    # list to contain the content for each row
                    rowContent = []
                    # only the keys specefied by spectrumKeys above
                    for key in spectrumKeys:
                        try:
                            if key in precursorKeys:
                                rowContent.append(
                                    spectrum[0]['precursors'][0][key])
                            else:
                                rowContent.append(spectrum[0][key])
                        except KeyError:
                            rowContent.append('N/A')
                    fw.csvWriteLine(rowContent)
示例#4
0
文件: output.py 项目: davidmam/pyMSA
	def __init__(self, path, msrun):
	# using r in front of doc string because otherwise \t isn't recognised
		r"""

		@type path: string
		@param path: path for output file
		@type msrun: pymzml.run.Reader
		@param msrun: An instance of pymzml.run.Reader()

		B{Example}:

		Write an instance of pymzml.run.Reader to a csv file:

		>>> msrun = pymzml.run.Reader('example_mzML_file.mzML')						# instance of pymzml.run.Reader
		>>> writer = MsrunCsvWriter('example_outfile.csv', msrun)					# write the csv file
		"""		

		# Use the FileHandler class to open the file and close if after writing is done
		with FileWriter(path) as fw:
			# a list of all the columns the user do not want in the ms/ms file from the configfile

			excludeList = config.get('data', 'excludeMsrunCsvColumns').strip(' ').split(',')
			# a list of all the columns the user want sin the ms/ms file from the configfile that are not in feature.keys() 
			includeList = config.get('data','includeMsrunCsvColumns').strip(' ').split(',')
			# spectrumKeys will contain the column header names
			spectrumKeys, precursorKeys, spectrumList = mzmlFunctions.getKeys(msrun, excludeList, includeList)
				
			# write the column names
			fw.csvWriteLine(list(spectrumKeys))

			# loop through the spectra that were used in mzmlFunctions.getKeys (spectrumList) and the ones left over in msrun
			# itertools.izip makes an iterator of two lists
			for spectrum in itertools.izip(spectrumList, msrun):
				if spectrum[0]['id'] != 'TIC':
					# list to contain the content for each row
					rowContent = []
					# only the keys specefied by spectrumKeys above
					for key in spectrumKeys:
						try:
							if key in precursorKeys:
								rowContent.append(spectrum[0]['precursors'][0][key])
							else:
								rowContent.append(spectrum[0][key])
						except KeyError:
							rowContent.append('N/A')
					fw.csvWriteLine(rowContent)
示例#5
0
    def test_getKeys_default(self):
        # test getKeys with default, so no excluded or included keys
        expectedSpectrumKeys = set([
            'no compression', 'total ion current', 'scan time',
            'filter string', 'id', 'profile mass spectrum', '64-bit float',
            'defaultArrayLength', 'm/z array', 'ms level', 'intensity array',
            'BinaryArrayOrder', '32-bit float',
            'total ion current chromatogram', 'time array'
        ])
        expectedPrecursorKeys = set([])

        msrun = pymzml.run.Reader(testFolder + 'mzml_testFIle_withBinary.mzML')
        actualSpectrumKeys, actualPrecursorKeys, spectrumList = mzmlFunctions.getKeys(
            msrun)

        self.assertSetEqual(expectedSpectrumKeys, actualSpectrumKeys)
        self.assertSetEqual(expectedPrecursorKeys, actualPrecursorKeys)
示例#6
0
    def test_getKeys_inclusive(self):
        # test getKeys with some keys excluded and some keys includes
        expectedSpectrumKeys = set([
            'no compression', 'total ion current', 'time array',
            '32-bit float', 'total ion current chromatogram'
        ])
        expectedPrecursorKeys = set([])

        msrun = pymzml.run.Reader(testFolder + 'mzml_testFIle_withBinary.mzML')
        actualSpectrumKeys, actualPrecursorKeys, spectrumList = mzmlFunctions.getKeys(
            msrun,
            excludeList=[
                'charge', 'scan time', 'filter string', 'PY:0000000',
                'precursors', 'id', 'profile mass spectrum', 'charge',
                'collision-induced dissociation', '64-bit float',
                'defaultArrayLength', 'm/z array', 'charge state', 'None',
                'ms level', 'intensity array', 'BinaryArrayOrder',
                'encodedData', 'charge'
            ])

        self.assertSetEqual(expectedSpectrumKeys, actualSpectrumKeys)
        self.assertSetEqual(expectedPrecursorKeys, actualPrecursorKeys)