コード例 #1
0
def build_combinatorial_hypothesis(rule_file, database_connection, reduction,
                                   derivatization, name, channel):
    if name is not None:
        name = validate_glycan_hypothesis_name(None, database_connection, name)
        channel.send(Message("Building Glycan Hypothesis %s" % name, 'info'))
    try:
        reduction = str(reduction) if reduction is not None else None
        validate_reduction(None, reduction)
    except Abort:
        channel.send(Message("Could not validate reduction %s" % reduction),
                     'error')
        return
    try:
        derivatization = str(
            derivatization) if derivatization is not None else None
        validate_derivatization(None, derivatization)
    except Abort:
        channel.send(
            Message("Could not validate derivatization %s" % derivatization,
                    'error'))
        return
    try:
        builder = CombinatorialGlycanHypothesisSerializer(
            rule_file,
            database_connection,
            reduction=reduction,
            derivatization=derivatization,
            hypothesis_name=name)
        builder.start()
        record = project_hypothesis.HypothesisRecordSet(database_connection)
        hypothesis_record = None

        for item in record:
            if item.uuid == builder.hypothesis.uuid:
                hypothesis_record = item
                hypothesis_record = hypothesis_record._replace(
                    user_id=channel.user.id)
                channel.send(
                    Message(hypothesis_record.to_json(), "new-hypothesis"))
                break
        else:
            channel.send(
                Message("Something went wrong (%r)" % (list(record), )))
    except Exception:
        channel.send(Message.traceback())
        raise
def mzid_glycopeptide(database_connection, mzid_file, name, occupied_glycosites, target_protein,
                      processes, glycan_source, glycan_source_type, glycan_source_identifier,
                      channel):
    context = None
    proteins = validate_mzid_proteins(
        context, mzid_file, target_protein, [])
    try:
        validate_glycan_source(context, database_connection,
                               glycan_source, glycan_source_type,
                               glycan_source_identifier)
    except Abort:
        channel.abort("Could not validate the glycan source, %s, %s" % (glycan_source, glycan_source_type))
    if name is not None:
        name = validate_glycopeptide_hypothesis_name(
            context, database_connection, name)

    glycan_hypothesis_id = _glycan_hypothesis_builders[
        glycan_source_type](database_connection, glycan_source,
                            name, glycan_source_identifier)

    builder = MultipleProcessMzIdentMLGlycopeptideHypothesisSerializer(
        mzid_file, database_connection,
        glycan_hypothesis_id=glycan_hypothesis_id,
        hypothesis_name=name,
        target_proteins=proteins,
        max_glycosylation_events=occupied_glycosites,
        n_processes=processes)
    try:
        builder.start()
        record = project_hypothesis.HypothesisRecordSet(database_connection)
        hypothesis_record = None

        for item in record:
            if item.uuid == builder.hypothesis.uuid:
                hypothesis_record = item
                hypothesis_record = hypothesis_record._replace(user_id=channel.user.id)
                channel.send(Message(hypothesis_record.to_json(), "new-hypothesis"))
                break
        else:
            channel.send(Message("Something went wrong (%r)" % (list(record),)))
    except Exception:
        channel.abort(Message.traceback())
コード例 #3
0
def merge_glycan_hypothesis(database_connection, hypothesis_ids, name, channel):
        if name is not None:
            name = validate_glycan_hypothesis_name(None, database_connection, name)
            channel.send(Message("Merging Glycan Hypothesis %s" % name, 'info'))
        try:
            task = GlycanCompositionHypothesisMerger(database_connection, [
                (conn, hid) for conn, hid in hypothesis_ids], name)
            task.start()
            record = project_hypothesis.HypothesisRecordSet(database_connection)
            hypothesis_record = None

            for item in record:
                if item.uuid == task.hypothesis.uuid:
                    hypothesis_record = item
                    hypothesis_record = hypothesis_record._replace(user_id=channel.user.id)
                    channel.send(Message(hypothesis_record.to_json(), "new-hypothesis"))
                    break
            else:
                channel.send(Message("Something went wrong (%r)" % (list(record),)))

        except Exception:
            channel.send(Message.traceback())
            channel.abort("An error occurred during merging.")
コード例 #4
0
def fasta_glycopeptide(database_connection, fasta_file, enzyme,
                       missed_cleavages, occupied_glycosites, name,
                       constant_modification, variable_modification, processes,
                       glycan_source, glycan_source_type,
                       glycan_source_identifier, peptide_length_range,
                       semispecific_digest, generate_full_crossproduct,
                       generate_reverse_decoys, channel):
    context = None
    try:
        validate_modifications(context,
                               constant_modification + variable_modification)
    except Exception:
        channel.abort(
            "Could not validate the modification specification, Constant: %s, Variable: %s"
            % (constant_modification, variable_modification))
    try:
        validate_glycan_source(context, database_connection, glycan_source,
                               glycan_source_type, glycan_source_identifier)
    except Abort:
        channel.abort("Could not validate the glycan source, %s, %s" %
                      (glycan_source, glycan_source_type))

    if name is not None:
        name = validate_glycopeptide_hypothesis_name(context,
                                                     database_connection, name)

    mt = RestrictedModificationTable(None, constant_modification,
                                     variable_modification)
    constant_modification = [mt[c] for c in constant_modification]
    variable_modification = [mt[c] for c in variable_modification]

    glycan_hypothesis_id = _glycan_hypothesis_builders[glycan_source_type](
        database_connection, glycan_source, name, glycan_source_identifier)

    builder = MultipleProcessFastaGlycopeptideHypothesisSerializer(
        fasta_file,
        database_connection,
        glycan_hypothesis_id=glycan_hypothesis_id,
        protease=enzyme,
        constant_modifications=constant_modification,
        variable_modifications=variable_modification,
        max_missed_cleavages=missed_cleavages,
        max_glycosylation_events=occupied_glycosites,
        hypothesis_name=name,
        peptide_length_range=peptide_length_range,
        semispecific=semispecific_digest,
        n_processes=processes,
        full_cross_product=generate_full_crossproduct)

    decoy_builder = None
    decoy_database_connection = None
    if generate_reverse_decoys:
        prefix, ext = database_connection.rsplit(".", 1)
        decoy_database_connection = "%s.decoy.%s" % (prefix, ext)

        try:
            validate_glycan_source(context, decoy_database_connection,
                                   glycan_source, glycan_source_type,
                                   glycan_source_identifier)
        except Abort:
            channel.abort("Could not validate the glycan source, %s, %s" %
                          (glycan_source, glycan_source_type))

        decoy_glycan_hypothesis_id = _glycan_hypothesis_builders[
            glycan_source_type](decoy_database_connection, glycan_source, name,
                                glycan_source_identifier)

        decoy_builder = ReversingMultipleProcessFastaGlycopeptideHypothesisSerializer(
            fasta_file,
            decoy_database_connection,
            glycan_hypothesis_id=decoy_glycan_hypothesis_id,
            protease=enzyme,
            constant_modifications=constant_modification,
            variable_modifications=variable_modification,
            max_missed_cleavages=missed_cleavages,
            max_glycosylation_events=occupied_glycosites,
            hypothesis_name=name,
            peptide_length_range=peptide_length_range,
            semispecific=semispecific_digest,
            n_processes=processes,
            full_cross_product=generate_full_crossproduct)

    try:
        builder.start()
        record = project_hypothesis.HypothesisRecordSet(database_connection)
        hypothesis_record = None
        decoy_hypothesis_record = None

        if decoy_builder:
            decoy_builder.start()
            decoy_record = project_hypothesis.HypothesisRecordSet(
                decoy_database_connection)
            for item in decoy_record:
                if item.uuid == decoy_builder.hypothesis.uuid:
                    decoy_hypothesis_record = item._replace(
                        user_id=channel.user.id,
                        options={
                            'full_crossproduct': generate_full_crossproduct
                        })
                    break
            else:
                channel.send(
                    Message("Something went wrong (%r)" % (list(record), )))
                channel.abort("Could not extract decoy hypothesis")

        for item in record:
            if item.uuid == builder.hypothesis.uuid:
                hypothesis_record = item
                hypothesis_record = hypothesis_record._replace(
                    user_id=channel.user.id,
                    options={'full_crossproduct': generate_full_crossproduct})
                if decoy_hypothesis_record is not None:
                    hypothesis_record = hypothesis_record._replace(
                        decoy_hypothesis=decoy_hypothesis_record)
                channel.send(
                    Message(hypothesis_record.to_json(), "new-hypothesis"))
                break
        else:
            channel.send(
                Message("Something went wrong (%r)" % (list(record), )))
    except Exception:
        channel.send(Message.traceback())
コード例 #5
0
def mzid_glycopeptide(database_connection, mzid_file, name,
                      occupied_glycosites, target_protein, processes,
                      glycan_source, glycan_source_type,
                      glycan_source_identifier, peptide_length_range,
                      generate_full_crossproduct, generate_reverse_decoys,
                      channel):
    context = None
    proteins = validate_mzid_proteins(context, mzid_file, target_protein, [])
    try:
        validate_glycan_source(context, database_connection, glycan_source,
                               glycan_source_type, glycan_source_identifier)
    except Abort:
        channel.abort("Could not validate the glycan source, %s, %s" %
                      (glycan_source, glycan_source_type))
    if name is not None:
        name = validate_glycopeptide_hypothesis_name(context,
                                                     database_connection, name)

    glycan_hypothesis_id = _glycan_hypothesis_builders[glycan_source_type](
        database_connection, glycan_source, name, glycan_source_identifier)

    builder = MultipleProcessMzIdentMLGlycopeptideHypothesisSerializer(
        mzid_file,
        database_connection,
        glycan_hypothesis_id=glycan_hypothesis_id,
        hypothesis_name=name,
        target_proteins=proteins,
        max_glycosylation_events=occupied_glycosites,
        peptide_length_range=peptide_length_range,
        n_processes=processes,
        full_cross_product=generate_full_crossproduct)

    decoy_builder = None
    decoy_database_connection = None
    if generate_reverse_decoys:
        # TODO Implement reversing mzIdentML database build
        prefix, ext = database_connection.rsplit(".", 1)
        decoy_database_connection = "%s.decoy.%s" % (prefix, ext)
        try:
            validate_glycan_source(context, decoy_database_connection,
                                   glycan_source, glycan_source_type,
                                   glycan_source_identifier)
        except Abort:
            channel.abort("Could not validate the glycan source, %s, %s" %
                          (glycan_source, glycan_source_type))
        channel.abort("Cannot build a reversed mzIdentML hypothesis")
        # decoy_glycan_hypothesis_id = _glycan_hypothesis_builders[
        #     glycan_source_type](decoy_database_connection, glycan_source,
        #                         name, glycan_source_identifier)
        # decoy_builder = ReversingMultipleProcessFastaGlycopeptideHypothesisSerializer(
        #     mzid_file, decoy_database_connection,
        #     glycan_hypothesis_id=decoy_glycan_hypothesis_id,
        #     max_glycosylation_events=occupied_glycosites,
        #     hypothesis_name="Reverse " + name,
        #     peptide_length_range=peptide_length_range,
        #     n_processes=processes,
        #     full_cross_product=full_cross_product)

    try:
        builder.start()
        record = project_hypothesis.HypothesisRecordSet(database_connection)
        hypothesis_record = None
        decoy_hypothesis_record = None

        if decoy_builder:
            decoy_builder.start()
            decoy_record = project_hypothesis.HypothesisRecordSet(
                decoy_database_connection)
            for item in decoy_record:
                if item.uuid == decoy_builder.hypothesis.uuid:
                    decoy_hypothesis_record = item
                    decoy_hypothesis_record = decoy_hypothesis_record._replace(
                        user_id=channel.user.id,
                        options={
                            'full_cross_product': generate_full_crossproduct
                        })
                    break

        for item in record:
            if item.uuid == builder.hypothesis.uuid:
                hypothesis_record = item
                hypothesis_record = hypothesis_record._replace(
                    user_id=channel.user.id,
                    options={'full_cross_product': generate_full_crossproduct})
                if decoy_hypothesis_record is not None:
                    hypothesis_record = hypothesis_record._replace(
                        decoy_hypothesis=decoy_hypothesis_record)
                channel.send(
                    Message(hypothesis_record.to_json(), "new-hypothesis"))
                break
        else:
            channel.send(
                Message("Something went wrong (%r)" % (list(record), )))
    except Exception:
        channel.abort(Message.traceback())
コード例 #6
0
def build_prebuilt_hypothesis(recipes, database_connection, reduction,
                              derivatization, name, channel):

    if not validate_database_unlocked(database_connection):
        channel.send(Message("Database is locked.", "error"))
        return

    if name is not None:
        name = validate_glycan_hypothesis_name(None, database_connection, name)
        channel.send(Message("Building Glycan Hypothesis %s" % name, 'info'))
    try:
        reduction = str(reduction) if reduction is not None else None
        validate_reduction(None, reduction)
    except Abort:
        channel.send(Message("Could not validate reduction %s" % reduction),
                     'error')
        return
    try:
        derivatization = str(
            derivatization) if derivatization is not None else None
        validate_derivatization(None, derivatization)
    except Abort:
        channel.send(
            Message("Could not validate derivatization %s" % derivatization,
                    'error'))
        return
    try:
        if len(recipes) == 1:
            task = recipes[0]
            builder = task(database_connection,
                           reduction=reduction,
                           derivatization=derivatization,
                           hypothesis_name=name)
        else:
            sub_builders = []
            for task in recipes:
                builder = task(database_connection,
                               reduction=reduction,
                               derivatization=derivatization)
                sub_builders.append(builder)
            builder = GlycanCompositionHypothesisMerger(
                database_connection,
                [(database_connection, s.hypothesis.id) for s in sub_builders],
                hypothesis_name=name)
            builder.start()

        record = project_hypothesis.HypothesisRecordSet(database_connection)
        hypothesis_record = None

        for item in record:
            if item.uuid == builder.hypothesis.uuid:
                hypothesis_record = item
                hypothesis_record = hypothesis_record._replace(
                    user_id=channel.user.id)
                channel.send(
                    Message(hypothesis_record.to_json(), "new-hypothesis"))
                break
        else:
            channel.send(
                Message("Something went wrong (%r)" % (list(record), )))

    except Exception:
        channel.send(Message.traceback())
def fasta_glycopeptide(database_connection, fasta_file, enzyme,
                       missed_cleavages, occupied_glycosites, name,
                       constant_modification, variable_modification, processes,
                       glycan_source, glycan_source_type,
                       glycan_source_identifier, channel):
    context = None
    try:
        validate_modifications(context,
                               constant_modification + variable_modification)
    except Exception:
        channel.abort(
            "Could not validate the modification specification, Constant: %s, Variable: %s"
            % (constant_modification, variable_modification))
    try:
        validate_glycan_source(context, database_connection, glycan_source,
                               glycan_source_type, glycan_source_identifier)
    except Abort:
        channel.abort("Could not validate the glycan source, %s, %s" %
                      (glycan_source, glycan_source_type))

    if name is not None:
        name = validate_glycopeptide_hypothesis_name(context,
                                                     database_connection, name)

    mt = RestrictedModificationTable(None, constant_modification,
                                     variable_modification)
    constant_modification = [mt[c] for c in constant_modification]
    variable_modification = [mt[c] for c in variable_modification]

    glycan_hypothesis_id = _glycan_hypothesis_builders[glycan_source_type](
        database_connection, glycan_source, name, glycan_source_identifier)

    builder = MultipleProcessFastaGlycopeptideHypothesisSerializer(
        fasta_file,
        database_connection,
        glycan_hypothesis_id=glycan_hypothesis_id,
        protease=enzyme,
        constant_modifications=constant_modification,
        variable_modifications=variable_modification,
        max_missed_cleavages=missed_cleavages,
        max_glycosylation_events=occupied_glycosites,
        hypothesis_name=name,
        n_processes=processes)

    try:
        builder.start()
        record = project_hypothesis.HypothesisRecordSet(database_connection)
        hypothesis_record = None

        for item in record:
            if item.uuid == builder.hypothesis.uuid:
                hypothesis_record = item
                hypothesis_record = hypothesis_record._replace(
                    user_id=channel.user.id)
                channel.send(
                    Message(hypothesis_record.to_json(), "new-hypothesis"))
                break
        else:
            channel.send(
                Message("Something went wrong (%r)" % (list(record), )))
    except Exception:
        channel.send(Message.traceback())