예제 #1
0
class FDRSet(
        make_struct("FDRSet", [
            'total_q_value', 'peptide_q_value', 'glycan_q_value',
            'glycopeptide_q_value'
        ])):
    __slots__ = ()
    packer = struct.Struct("!ffff")

    def pack(self):
        return self.packer.pack(*self)

    @classmethod
    def unpack(cls, binary):
        return cls(*cls.packer.unpack(binary))

    @classmethod
    def default(cls):
        return cls(1.0, 1.0, 1.0, 1.0)

    def __lt__(self, other):
        if self.total_q_value < other.total_q_value:
            return True
        elif abs(self.total_q_value - other.total_q_value) > 1e-3:
            return False

        if self.peptide_q_value < other.peptide_q_value:
            return True
        elif abs(self.peptide_q_value - other.peptide_q_value) > 1e-3:
            return False

        if self.glycan_q_value < other.glycan_q_value:
            return True
        elif abs(self.glycan_q_value - other.glycan_q_value) > 1e-3:
            return False

        if self.glycopeptide_q_value < other.glycopeptide_q_value:
            return True
        return False

    def __gt__(self, other):
        if self.total_q_value > other.total_q_value:
            return True
        elif abs(self.total_q_value - other.total_q_value) > 1e-3:
            return False

        if self.peptide_q_value > other.peptide_q_value:
            return True
        elif abs(self.peptide_q_value - other.peptide_q_value) > 1e-3:
            return False

        if self.glycan_q_value > other.glycan_q_value:
            return True
        elif abs(self.glycan_q_value - other.glycan_q_value) > 1e-3:
            return False

        if self.glycopeptide_q_value > other.glycopeptide_q_value:
            return True
        return False
예제 #2
0
    |int| or |None| if no match

    '''
    if exact:
        comparator = exact_ordering_inclusion
    else:
        comparator = topological_inclusion
    tree_root = root(subtree)
    for node in tree:
        if comparator(tree_root, node):
            return node.id
    return None


#: Results Container for :func:`maximum_common_subgraph`
MaximumCommonSubtreeResults = make_struct(
    "MaximumCommonSubtreeResults", ("score", "tree", "similarity_matrix"))


def compare_nodes(node_a, node_b, include_substituents=True, exact=False, visited=None):
    '''
    Score the pair of `node_a` and `node_b` and all pairings of their children.

    Returns
    -------
    float:
        The similarity score between the input nodes
    '''
    if visited is None:
        visited = set()
    score = 0.
    if (node_a.id, node_b.id) in visited:  # pragma: no cover
예제 #3
0
from scipy.misc import comb
import numpy as np

import math
from collections import defaultdict

from glypy.utils import make_struct

#: Store whether a fragment was observed for the reducing or non-reducing end of a particular glycosidic bond
GlycosidicBondMatch = make_struct("GlycosidicBondMatch",
                                  ["reducing", "non_reducing"])

#: Store how many times a fragment was observed for the reducing, non-reducing, or non-bisecting cross-ring
#: permutations of a particular monosaccharide
CrossringMatch = make_struct("CrossringMatch",
                             ["reducing", "non_reducing", "non_bisecting"])


def is_primary_fragment(f):
    return f.break_count == 1


class FragmentScorer(object):
    """Score the data with respect to structure characterization.

    Attributes
    ----------
    crossring_map : dict
        Mapping of residue id to CrossringMatch
    crossring_score : float
        Score derived from cross-ring coverage
예제 #4
0
from scipy.misc import comb
import numpy as np

import math
from collections import defaultdict

from glypy.utils import make_struct


#: Store whether a fragment was observed for the reducing or non-reducing end of a particular glycosidic bond
GlycosidicBondMatch = make_struct("GlycosidicBondMatch", ["reducing", "non_reducing"])

#: Store how many times a fragment was observed for the reducing, non-reducing, or non-bisecting cross-ring
#: permutations of a particular monosaccharide
CrossringMatch = make_struct("CrossringMatch", ["reducing", "non_reducing", "non_bisecting"])


def is_primary_fragment(f):
    return f.break_count == 1


class FragmentScorer(object):
    """Score the data with respect to structure characterization.

    Attributes
    ----------
    crossring_map : dict
        Mapping of residue id to CrossringMatch
    crossring_score : float
        Score derived from cross-ring coverage
    final_score : float
예제 #5
0
        node = self.get_model_node_for(scan, target, *args, **kwargs)
        return node.model(scan, target, *args, **kwargs)

    def load_peaks(self, scan):
        return self.model.load_peaks(scan)


class SpectrumMatchClassification(Enum):
    target_peptide_target_glycan = 0
    target_peptide_decoy_glycan = 1
    decoy_peptide_target_glycan = 2
    decoy_peptide_decoy_glycan = decoy_peptide_target_glycan | target_peptide_decoy_glycan


_ScoreSet = make_struct(
    "ScoreSet",
    ['glycopeptide_score', 'peptide_score', 'glycan_score', 'glycan_coverage'])


class ScoreSet(_ScoreSet):
    __slots__ = ()
    packer = struct.Struct("!ffff")

    def __len__(self):
        return 4

    def __lt__(self, other):
        if self.glycopeptide_score < other.glycopeptide_score:
            return True
        elif abs(self.glycopeptide_score - other.glycopeptide_score) > 1e-3:
            return False
예제 #6
0
class partition_cell(make_struct("partition_cell", ("subset", "fit", "spec"))):
    def __len__(self):
        return len(self.subset)
예제 #7
0
    None: identity,
    "all": identity,
    "top_n_peaks": top_n_peaks,
    "percent_of_max": percent_of_max
}


crossring_pattern = re.compile(r"\d,\d")

PROTON = Composition("H+").mass
DEFAULT_MS2_MATCH_TOLERANCE = 2e-5
DEFAULT_MS1_MATCH_TOLERANCE = 1e-5
MACHINE_EPSILON = _machine_epsilon()


FragmentMatch = make_struct("FragmentMatch", ["match_key", "mass", "ppm_error",
                                              "intensity", "charge", "peak_id"])
MergedMatch = make_struct("MergedMatch", ["match_key", "mass", "ppm_error", "intensity",
                                          "charge", "peak_id", "matches"])
MassShift = make_struct("MassShift", ["name", "mass"])
NoShift = MassShift("", 0.0)


def split_match_key(match_key):
    key, shift = match_key.split(":")
    return key, shift


def strip_shift_label(match_key):
    return match_key.split(":")[0]

    def __call__(self, scan, target, *args, **kwargs):
        node = self.get_model_node_for(scan, target, *args, **kwargs)
        return node.model(scan, target, *args, **kwargs)

    def load_peaks(self, scan):
        return self.model.load_peaks(scan)


class SpectrumMatchClassification(Enum):
    target_peptide_target_glycan = 0
    target_peptide_decoy_glycan = 1
    decoy_peptide_target_glycan = 2
    decoy_peptide_decoy_glycan = decoy_peptide_target_glycan | target_peptide_decoy_glycan


_ScoreSet = make_struct("ScoreSet", ['glycopeptide_score', 'peptide_score', 'glycan_score'])


class ScoreSet(_ScoreSet):
    __slots__ = ()
    packer = struct.Struct("!fff")

    @classmethod
    def from_spectrum_matcher(cls, match):
        return cls(match.score, match.peptide_score(), match.glycan_score())

    def pack(self):
        return self.packer.pack(*self)

    @classmethod
    def unpack(cls, binary):
예제 #9
0
        return self.position

    @property
    def end(self):
        return self.position + 1

    @classmethod
    def fromxml(cls, feature):
        position = int(
            feature.find(".//up:position", nsmap).attrib['position']) - 1
        glycosylation_type = feature.attrib["description"].split(" ")[0]
        return cls(position, glycosylation_type)


UniProtProtein = make_struct("UniProtProtein",
                             ("sequence", "features", "recommended_name",
                              "gene_name", "names", "accessions", "keywords"))


def get_etree_for(accession):
    tree = etree.parse(uri_template.format(accession=accession))
    return tree


def get_features_for(accession, error=False):
    tree = etree.parse(uri_template.format(accession=accession))
    seq = tree.find(".//up:entry/up:sequence", nsmap).text.replace("\n", '')
    names = [
        el.text for el in tree.findall(".//up:protein/*/up:fullName", nsmap)
    ]
    recommended_name_tag = tree.find(".//up:protein/*/up:recommendedName",
예제 #10
0
파일: database.py 프로젝트: husince/glypy
import os
import sqlite3
import logging
import functools
from collections import Counter, Iterable, Callable

import glypy

from glypy.utils import pickle, classproperty, make_struct
from glypy.io.nomenclature.identity import naive_name_monosaccharide
from glypy.algorithms import subtree_search

logger = logging.getLogger(__name__)
logger.addHandler(logging.NullHandler())

Taxon = make_struct("Taxon", ("tax_id", "name", 'entries'))
Aglyca = make_struct("Aglyca", ("name", "reducing", 'entries'))
DatabaseEntry = make_struct("DatabaseEntry", ("database", "id"))
Motif = make_struct("Motif", ("name", "id", "motif_class"))


def _resolve_column_data_mro(cls):
    '''
    Given a class with :attr:`__column_data_map` mangled attributes
    from its class hierarchy, extract in descending order each
    `dict`, overwriting old settings as it approaches the most
    recently descended class.

    Parameters
    ----------
    cls: type