def _copy_analysis_across_file_boundaries(database_connection, source, hypothesis_name, identifier=None): source_handle = DatabaseBoundOperation(source) source_analysis_id = None source_analysis_name = None try: hypothesis_id = int(identifier) inst = source_handle.query(Analysis).get(hypothesis_id) if inst is not None: source_analysis_id = hypothesis_id source_analysis_name = inst.name except TypeError: hypothesis_name = identifier inst = source_handle.query(Analysis).filter( Analysis.name == hypothesis_name).first() if inst is not None: source_analysis_id = inst.id source_analysis_name = inst.name if hypothesis_name is None: hypothesis_name = source_analysis_name mover = GlycanAnalysisHypothesisSerializer( source, source_analysis_id, hypothesis_name, database_connection) mover.run() return mover.hypothesis_id
class HypothesisGlycanSourceValidator(GlycanSourceValidatorBase): def __init__(self, database_connection, source, source_type, source_identifier=None): super(HypothesisGlycanSourceValidator, self).__init__(database_connection, source, source_type, source_identifier) self.handle = DatabaseBoundOperation(source) def validate(self): if self.source_identifier is None: click.secho("No value passed through --glycan-source-identifier.", fg='magenta') return False try: hypothesis_id = int(self.source_identifier) inst = self.handle.query(GlycanHypothesis).get(hypothesis_id) return inst is not None except TypeError: hypothesis_name = self.source inst = self.handle.query(GlycanHypothesis).filter( GlycanHypothesis.name == hypothesis_name).first() return inst is not None
def mass_search_dispatch(uuid): try: arguments, state = request_arguments_and_context() record = _locate_hypothesis(uuid) handle = DatabaseBoundOperation(record.path) hypothesis = handle.query(GlycanHypothesis).filter( GlycanHypothesis.uuid == record.uuid).first() if hypothesis is not None: return search_glycan_hypothesis(hypothesis.uuid, arguments['mass'], arguments['tolerance']) hypothesis = handle.query(GlycopeptideHypothesis).filter( GlycopeptideHypothesis.uuid == record.uuid).first() if hypothesis is not None: return search_glycopeptide_hypothesis(hypothesis.uuid, arguments['mass'], arguments['tolerance']) return jsonify(*[]) except Exception, e: logging.exception("An exception occurred for %r", request.get_json(), exc_info=e) return jsonify(*[])
def _copy_hypothesis_across_file_boundaries(database_connection, source, hypothesis_name, identifier=None): source_handle = DatabaseBoundOperation(source) source_hypothesis_id = None source_hypothesis_name = None try: hypothesis_id = int(identifier) inst = source_handle.query(GlycanHypothesis).get(hypothesis_id) if inst is not None: source_hypothesis_id = hypothesis_id source_hypothesis_name = inst.name except TypeError: hypothesis_name = identifier inst = source_handle.query(GlycanHypothesis).filter( GlycanHypothesis.name == hypothesis_name).first() if inst is not None: source_hypothesis_id = inst.id source_hypothesis_name = inst.name if source == database_connection: return source_hypothesis_id mover = GlycanHypothesisCopier(database_connection, [(source, source_hypothesis_id)], hypothesis_name=source_hypothesis_name) mover.run() return mover.hypothesis_id
def _copy_hypothesis_across_file_boundaries(database_connection, source, hypothesis_name, identifier=None): source_handle = DatabaseBoundOperation(source) source_hypothesis_id = None source_hypothesis_name = None try: hypothesis_id = int(identifier) inst = source_handle.query(GlycanHypothesis).get(hypothesis_id) if inst is not None: source_hypothesis_id = hypothesis_id source_hypothesis_name = inst.name except TypeError: hypothesis_name = identifier inst = source_handle.query(GlycanHypothesis).filter( GlycanHypothesis.name == hypothesis_name).first() if inst is not None: source_hypothesis_id = inst.id source_hypothesis_name = inst.name if source == database_connection: return source_hypothesis_id mover = GlycanHypothesisCopier( database_connection, [(source, source_hypothesis_id)], hypothesis_name=source_hypothesis_name) mover.run() return mover.hypothesis_id
def _copy_analysis_across_file_boundaries(database_connection, source, hypothesis_name, identifier=None): source_handle = DatabaseBoundOperation(source) source_analysis_id = None source_analysis_name = None try: hypothesis_id = int(identifier) inst = source_handle.query(Analysis).get(hypothesis_id) if inst is not None: source_analysis_id = hypothesis_id source_analysis_name = inst.name except TypeError: hypothesis_name = identifier inst = source_handle.query(Analysis).filter( Analysis.name == hypothesis_name).first() if inst is not None: source_analysis_id = inst.id source_analysis_name = inst.name if hypothesis_name is None: hypothesis_name = source_analysis_name mover = GlycanAnalysisHypothesisSerializer(source, source_analysis_id, hypothesis_name, database_connection) mover.run() return mover.hypothesis_id
def validate_unique_name(context, database_connection, name, klass): handle = DatabaseBoundOperation(database_connection) obj = handle.query(klass).filter(klass.name == name).first() if obj is not None: return klass.make_unique_name(handle.session, name) else: return name
def validate_unique_name(context, database_connection, name, klass): handle = DatabaseBoundOperation(database_connection) obj = handle.query(klass).filter( klass.name == name).first() if obj is not None: return klass.make_unique_name(handle.session, name) else: return name
class HypothesisGlycanSourceValidator(GlycanSourceValidatorBase): def __init__(self, database_connection, source, source_type, source_identifier=None): super(HypothesisGlycanSourceValidator, self).__init__( database_connection, source, source_type, source_identifier) self.handle = DatabaseBoundOperation(source) def validate(self): if self.source_identifier is None: click.secho("No value passed through --glycan-source-identifier.", fg='magenta') return False try: hypothesis_id = int(self.source_identifier) inst = self.handle.query(GlycanHypothesis).get(hypothesis_id) return inst is not None except TypeError: hypothesis_name = self.source inst = self.handle.query(GlycanHypothesis).filter(GlycanHypothesis.name == hypothesis_name).first() return inst is not None
def view_hypothesis_dispatch(uuid): try: arguments, state = request_arguments_and_context() record = _locate_hypothesis(uuid) handle = DatabaseBoundOperation(record.path) hypothesis = handle.query(GlycanHypothesis).filter( GlycanHypothesis.uuid == record.uuid).first() if hypothesis is not None: return handle_glycan_hypothesis(hypothesis) hypothesis = handle.query(GlycopeptideHypothesis).filter( GlycopeptideHypothesis.uuid == record.uuid).first() if hypothesis is not None: return handle_glycopeptide_hypothesis(hypothesis) return Response("<h2>%s</h2>" % record.name) except Exception as e: logging.exception("An exception occurred for %r", request.get_json(), exc_info=e) return Response("<h2>No display method is implemented for %s </h2>" % request.get_json())
class GlycopeptideAnalysisGlycanCompositionExtractionHypothesisSerializer( GlycanHypothesisSerializerBase): def __init__(self, input_connection, analysis_id, hypothesis_name, output_connection=None): if output_connection is None: output_connection = input_connection self.input_connection = DatabaseBoundOperation(input_connection) self.output_connection = DatabaseBoundOperation(output_connection) GlycanHypothesisSerializerBase.__init__(self, output_connection, hypothesis_name) self.analysis_id = analysis_id self.seen_cache = set() def get_all_compositions(self): return self.input_connection.query(DBGlycanComposition).join( GlycanCombinationGlycanComposition).join( Glycopeptide, GlycanCombinationGlycanComposition.c.combination_id == Glycopeptide.glycan_combination_id).join( IdentifiedGlycopeptide, IdentifiedGlycopeptide.structure_id == Glycopeptide.id).filter( IdentifiedGlycopeptide.analysis_id == self.analysis_id) def extract_composition(self, db_obj): composition = GlycanComposition.parse(db_obj.composition) if str(composition) in self.seen_cache: return self.seen_cache.add(str(composition)) mass = composition.mass() composition_string = composition.serialize() formula_string = formula(composition.total_composition()) inst = DBGlycanComposition(calculated_mass=mass, formula=formula_string, composition=composition_string, hypothesis_id=self.hypothesis_id) self.output_connection.session.add(inst) self.output_connection.session.flush() for sc in db_obj.structure_classes: self.output_connection.session.execute( GlycanCompositionToClass.insert(), dict(glycan_id=inst.id, class_id=sc.id)) self.output_connection.session.flush() def run(self): q = self.get_all_compositions() for gc in q: self.extract_composition(gc) self.output_connection.session.commit()
class GlycopeptideAnalysisGlycanCompositionExtractionHypothesisSerializer(GlycanHypothesisSerializerBase): def __init__(self, input_connection, analysis_id, hypothesis_name, output_connection=None): if output_connection is None: output_connection = input_connection self.input_connection = DatabaseBoundOperation(input_connection) self.output_connection = DatabaseBoundOperation(output_connection) GlycanHypothesisSerializerBase.__init__(self, output_connection, hypothesis_name) self.analysis_id = analysis_id self.seen_cache = set() def get_all_compositions(self): return self.input_connection.query(DBGlycanComposition).join(GlycanCombinationGlycanComposition).join( Glycopeptide, GlycanCombinationGlycanComposition.c.combination_id == Glycopeptide.glycan_combination_id).join( IdentifiedGlycopeptide, IdentifiedGlycopeptide.structure_id == Glycopeptide.id).filter( IdentifiedGlycopeptide.analysis_id == self.analysis_id) def extract_composition(self, db_obj): composition = GlycanComposition.parse(db_obj.composition) if str(composition) in self.seen_cache: return self.seen_cache.add(str(composition)) mass = composition.mass() composition_string = composition.serialize() formula_string = formula(composition.total_composition()) inst = DBGlycanComposition( calculated_mass=mass, formula=formula_string, composition=composition_string, hypothesis_id=self.hypothesis_id) self.output_connection.session.add(inst) self.output_connection.session.flush() for sc in db_obj.structure_classes: self.output_connection.session.execute( GlycanCompositionToClass.insert(), dict(glycan_id=inst.id, class_id=sc.id)) self.output_connection.session.flush() def run(self): q = self.get_all_compositions() for gc in q: self.extract_composition(gc) self.output_connection.session.commit()
def get_glycopeptide_hypothesis(uuid): record = g.manager.hypothesis_manager.get(uuid) handle = DatabaseBoundOperation(record.path) hypothesis = handle.query(GlycopeptideHypothesis).filter( GlycopeptideHypothesis.uuid == record.uuid).first() return hypothesis