def __init__(self, input_queue, output_queue, producer_done_event, consumer_done_event, scorer_type, evaluation_args, spectrum_map, mass_shift_map, log_handler, solution_packer): Process.__init__(self) if evaluation_args is None: evaluation_args = dict() self.daemon = True self.input_queue = input_queue self.output_queue = output_queue self.producer_done_event = producer_done_event self.consumer_done_event = consumer_done_event self.scorer_type = scorer_type self.evaluation_args = evaluation_args self.solution_packer = solution_packer self.spectrum_map = spectrum_map self.mass_shift_map = mass_shift_map self.local_scan_map = LRUMapping(1000) self.local_mass_shift_map = dict({Unmodified.name: Unmodified}) self.solution_map = dict() self._work_complete = Event() self._work_complete.clear() self.log_handler = log_handler self.token = uid() self.items_handled = 0 self.result_buffer = [] self.buffer_size = 1000 self.last_sent_result = time.time()
def __init__(self, name, links=None, composition=None, id=None, can_nh_derivatize=None, is_nh_derivatizable=None, derivatize=False, attachment_composition=None): if links is None: links = OrderedMultiMap() self.name = name self.links = links if composition is None: composition = substituent_compositions[self._name] elif composition is not None and not is_registered(self._name): self.register( name, composition, can_nh_derivatize=can_nh_derivatize, is_nh_derivatizable=is_nh_derivatizable, attachment_composition=attachment_composition) self.composition = composition self.id = id or uid() self._degree = self.order() try: if can_nh_derivatize is is_nh_derivatizable is None: derivatize_pathway = derivatize_info[self.name] self.can_nh_derivatize = derivatize_pathway.can_nh_derivatize self.is_nh_derivatizable = derivatize_pathway.is_nh_derivatizable else: self.can_nh_derivatize = can_nh_derivatize or False self.is_nh_derivatizable = is_nh_derivatizable or False except KeyError: self.can_nh_derivatize = can_nh_derivatize or False self.is_nh_derivatizable = is_nh_derivatizable or False self._derivatize = derivatize self.attachment_composition = attachment_composition if attachment_composition is not None\ else attachment_composition_info.get(self.name, default_attachment_composition)
def get(self, key=None): if key is None: _key = "" else: _key = key if key in self.cache: return self.cache[key] name = "%s_%x" % (_key, uid()) path = os.path.join(self.base_directory, name) self.cache[key] = path return path
def __init__(self, parent, child, parent_position=-1, child_position=-1, parent_loss=None, child_loss=None, id=None, attach=True): ''' Defines a bond between `parent` and `child` between the molecule positions specified. The bond may represent a partial loss of elemental composition from the parent and/or child molecules. Instantiating the |Link| object will automatically attach it to its endpoints, mutating them unless `attach=False`. If not attached on instantiation, the bond can be realized by calling :meth:`Link.apply()` at a later time. Parameters ---------- parent: :class:`Monosaccharide` or :class:`Substituent` child: :class:`Monosaccharide` or :class:`Substituent` parent_position: int The position on the parent to attach to Defaults to -1 child_position: int The position on the child to attach to. Defaults to -1 parent_loss: :class:`Composition` or str The elemental composition deducted from the parent when the bond is applied child_loss: :class:`Composition` or str The elemental composition deducted from the child when the bond is applied id: int A locally unique identifier within a graph. If |None|, uuid4 is used to generate one. Defaults to |None| attach: bool Whether to immediately attach the |Link| object to the `parent` and `child` molecules on instantiation by using :meth:`Link.apply` ''' if id is None: id = uid() if parent_loss is None: parent_loss = default_parent_loss elif isinstance(parent_loss, basestring): parent_loss = Composition(formula=parent_loss) if child_loss is None: child_loss = default_child_loss elif isinstance(child_loss, basestring): child_loss = Composition(formula=child_loss) self.parent = parent self.child = child self.parent_position = parent_position self.child_position = child_position self.parent_loss = parent_loss self.child_loss = child_loss self.id = id self.label = None self._attached = False if attach: self.apply()
def _handle_reduction_and_derivatization(self, reduced): if reduced: reduced = ReducedEnd(Composition(reduced)) self.reducing_end = reduced deriv = None for key in self: deriv = has_derivatization(key) if deriv: break if deriv: # strip_derivatization(self) # derivatize(self, deriv) self._derivatized(deriv.clone(), make_counter(uid()), include_reducing_end=False)
def __init__(self, retention_time=None, scan_id=None, children=None, members=None, node_type=Unmodified): if children is None: children = [] if members is None: members = [] self.retention_time = retention_time self.scan_id = scan_id self.children = children self.members = members self.node_type = node_type self._most_abundant_member = None self._neutral_mass = 0 self._charge_states = set() self._recalculate() self._has_msms = None self.node_id = uid()
def deindex(self): ''' When combining two Glycan structures, very often their component ids will overlap, making it impossible to differentiate between a cycle and the new graph. This function mangles all of the node and link ids so that they are distinct from the pre-existing nodes. ''' if self.index is not None and len(self.index) > 0: base = uid() for node in self.index: node.id += base node.id *= -1 for j, subst in node.substituents(): subst.id += base subst.id *= -1 for link in self.link_index: link.id += base link.id *= -1 return self
def __init__(self, input_queue, output_queue, done_event, scorer_type, evaluation_args, spectrum_map, mass_shift_map, log_handler): Process.__init__(self) self.daemon = True self.input_queue = input_queue self.output_queue = output_queue self.done_event = done_event self.scorer_type = scorer_type self.evaluation_args = evaluation_args self.spectrum_map = spectrum_map self.mass_shift_map = mass_shift_map self.local_scan_map = dict() self.local_mass_shift_map = dict({ Unmodified.name: Unmodified }) self.solution_map = dict() self._work_complete = Event() self.log_handler = log_handler self.token = uid()
def __getitem__(self, key): x = dict.__getitem__(self, key) # ret = deepcopy(x) ret = x.clone() ret.id = uid() return ret