text
stringlengths
0
828
# - Add protein entries to the protein database - #
for fastaHeader, sequence in _readFastaFile(filePath):
#TODO: function, make protein entry or something like this.
header, isDecoy = _removeHeaderTag(fastaHeader, decoyTag)
header, isContaminant = _removeHeaderTag(header, contaminationTag)
headerInfo = _parseFastaHeader(header, headerParser, forceId)
proteinId = _idFromHeaderInfo(headerInfo, isDecoy, decoyTag)
proteinName = _nameFromHeaderInfo(headerInfo, isDecoy, decoyTag)
if not isDecoy:
isDecoy = _proteinTagPresent(header, decoyTag)
if not isContaminant:
isContaminant = _proteinTagPresent(header, contaminationTag)
proteindb._addProtein(
proteinId, proteinName, sequence, fastaHeader, headerInfo,
isDecoy=isDecoy, isContaminant=isContaminant
)
# - Perform an insilico digestion and add peptides to the proteindb - #
for proteinId in proteindb.proteins:
sequence = proteindb.proteins[proteinId].sequence
digestInfo = maspy.peptidemethods.digestInSilico(
sequence, cleavageRule, missedCleavage, removeNtermM,
minLength, maxLength
)
for sequence, info in digestInfo:
proteindb._addPeptide(sequence, proteinId, info)
#Define wheter a peptide is unique to one protein entry
for peptide, peptideEntry in viewitems(proteindb.peptides):
if len(peptideEntry.proteins) == 1:
peptideEntry.isUnique = True
else:
peptideEntry.isUnique = False
#Add peptide as shared or unique to its protein entries
for peptide, peptideEntry in viewitems(proteindb.peptides):
for proteinId in peptideEntry.proteins:
if peptideEntry.isUnique:
proteindb.proteins[proteinId].uniquePeptides.add(peptide)
else:
proteindb.proteins[proteinId].sharedPeptides.add(peptide)
#Define unique proteins, i.e. have at least one unique peptide
for proteinEntry in viewvalues(proteindb.proteins):
if len(proteinEntry.uniquePeptides) > 0:
proteinEntry.isUnique = True
else:
proteinEntry.isUnique = False
return proteindb"
3743,"def fastaParserSpectraClusterPy(header):
""""""Custom parser for fasta headers adapted from
ERROR: type should be string, got " https://github.com/spectra-cluster/spectra-cluster-py"
:param header: str, protein entry header from a fasta file
:returns: dict, parsed header
""""""
isUniprot = lambda h: h[0:3] in ['sp|', 'tr|', 'up|']
if isUniprot(header):
start = 3
end = header.find('|', start)
else:
start = 0
breakPositions = [header.find(' '), header.find('|')]
breakPositions = [i if i > 0 else len(header) for i in breakPositions]
end = min(breakPositions)
return {'id': header[start:end]}"
3744,"def _removeHeaderTag(header, tag):
""""""Removes a tag from the beginning of a header string.
:param header: str
:param tag: str
:returns: (str, bool), header without the tag and a bool that indicates
wheter the tag was present.
""""""
if header.startswith(tag):
tagPresent = True
header = header[len(tag):]
else:
tagPresent = False
return header, tagPresent"
3745,"def _parseFastaHeader(fastaHeader, parser=None, forceId=False):
""""""Parses a fasta header and returns extracted information in a dictionary.
Unless a custom parser is specified, a ``Pyteomics`` function is used, which
provides parsers for the formats of UniProtKB, UniRef, UniParc and UniMES
(UniProt Metagenomic and Environmental Sequences), described at
`www.uniprot.org <http://www.uniprot.org/help/fasta-headers>_`.
:param fastaHeader: str, protein entry header from a fasta file
:param parser: is a function that takes a fastaHeader string and returns a
dictionary, containing at least the key ""id"". If None the parser
function from pyteomics ``pyteomics.fasta.parse()`` is used.
:param forceId: bool, if True and no id can be extracted from the fasta