Reads MS-GF+ PSM results from a mzIdentML file and returns a list of
    :class:`Sii <maspy.core.Sii>` elements.

    :param filelocation: file path of the percolator result file
    :param specfile: optional, unambiguous identifier of a ms-run file. Is also
        used as a reference to other MasPy file containers. If specified all
        the ``.specfile`` attribute of all ``Sii`` are set to this value, else
        it is read from the mzIdentML file.

    :returns: [sii, sii, sii, ...]

def readMsgfMzidResults(filelocation, specfile=None):
    """Reads MS-GF+ PSM results from a mzIdentML file and returns a list of
    :class:`Sii <maspy.core.Sii>` elements.

    :param filelocation: file path of the percolator result file
    :param specfile: optional, unambiguous identifier of a ms-run file. Is also
        used as a reference to other MasPy file containers. If specified all
        the ``.specfile`` attribute of all ``Sii`` are set to this value, else
        it is read from the mzIdentML file.

    :returns: [sii, sii, sii, ...]
    """
    readSpecfile = True if specfile is None else False

    unimod = pyteomics.mass.mass.Unimod()
    _tempMods = dict()
    mzid_refs = pyteomics.mzid.read(filelocation, retrieve_refs=True,
                                    iterative=False)

    siiList = list()
    for mzidEntry in mzid_refs:
        mzidSii = mzidEntry['SpectrumIdentificationItem'][0]
        scanNumber = str(int(mzidEntry['scan number(s)']))
        if readSpecfile:
            specfile = os.path.splitext(mzidEntry['name'])[0]

        sii = maspy.core.Sii(scanNumber, specfile)
        sii.isValid = mzidSii['passThreshold']
        sii.rank = mzidSii['rank']
        sii.eValue = mzidSii['MS-GF:EValue']
        sii.charge = mzidSii['chargeState']
        sii.sequence = mzidSii['PeptideSequence']
        sii.specEValue = mzidSii['MS-GF:SpecEValue']
        sii.score = numpy.log10(sii.eValue)*-1

        if 'Modification' in mzidSii:
            modifications = list()
            for modEntry in mzidSii['Modification']:
                try:
                    modSymbolMaspy = _tempMods[modEntry['name']]
                except KeyError:
                    unimodEntry = unimod.by_title(modEntry['name'])
                    if len(unimodEntry) != 0:
                        modSymbol = 'u:'+str(unimodEntry['record_id'])
                    else:
                        modSymbol = modEntry['name']
                    modSymbolMaspy = '[' + modSymbol + ']'
                    _tempMods[modEntry['name']] = modSymbolMaspy
                modifications.append((modEntry['location'], modSymbolMaspy))
            modifications.sort(key=ITEMGETTER(0))

            _lastPos = 0
            _peptide = list()
            for pos, mod in modifications:
                 _peptide.extend((sii.sequence[_lastPos:pos], mod))
                 _lastPos = pos
            _peptide.append(sii.sequence[_lastPos:])

            sii.peptide = ''.join(_peptide)
        else:
            sii.peptide = sii.sequence
        siiList.append(sii)
    return siiList