Exemple #1
0
def spectrumDescriptionToMZ(description):
    if 'MultiplierzMGF' in description:
        return float(standard_title_parse(description)['mz'])
    try:
        return float(description.split('-|')[0].split('-')[-1])
    except ValueError:
        return float(description.split("|")[1])
Exemple #2
0
def mgf_to_ms2(mgfFile, outputfile=None):
    """
    Converts the commonly-used MGF format to an MS2 file.
    """

    if not outputfile:
        outputfile = mgfFile[:-4] + '.ms2'

    mgf = parse_mgf(mgfFile, header=False)
    ms2 = MS2Writer(outputfile,
                    date=time.localtime(),
                    extractor='Converted from MGF by Multiplierz',
                    extractorVersion=__version__,
                    extractorOptions="None")

    sampleTitle = mgf.values()[0]['title']
    if 'MultiplierzMGF' in sampleTitle:
        titleMode = 'standard'
    elif sampleTitle.count('.') > 2 and sampleTitle.split(
            '.')[1] == sampleTitle.split('.')[2] and '|' in sampleTitle:
        titleMode = 'classic'  # From that old, barbaric format.
    else:
        titleMode = 'mysterious!'
        print "WARNING: Spectrum title format not recognized; original spectrum numbering will be lost!"
        scanNum = 0

    for entry in mgf.values():
        if titleMode == 'standard':
            info = standard_title_parse(entry['title'])
            scanNum = info['scan']
        elif titleMode == 'classic':
            scanNum = entry['title'].split('.')[1]
        else:
            scanNum += 1

        ms2.write(
            entry['spectrum'],
            scanNum=scanNum,
            charge=entry.get('charge',
                             0),  # TODO Add default charge to PyComet?
            precursorMZ=entry['pepmass'])

    ms2.close()

    return outputfile
Exemple #3
0
def spectrumDescriptionToScanNumber(description):
    if 'MultiplierzMGF' in description:
        return int(standard_title_parse(description)['scan'])
    else:
        return int(description.split('.')[1])
Exemple #4
0
 def _getReporters(row):
     attrib = standard_title_parse(row['Spectrum Description'])
     return [float(attrib[x.lower()]) for x in isobaric_labels[isobaric]]