示例#1
0
def run(start=1, end='', gap_open=11, gap_extend=1, local_=False, global_=False, semiglobal=False,
        protein=False, translate=False, inter=False, table=False, mutations=False, strict=False,
        pep1=False, pep3=False, limit=1, verbose=False, target=None, query=None):
    """
    Performs an alignment between the query and target.
    """

    # Alignments over this size will take a long time!
    MAX_LEN = 100000

    # Set the verbosity of the process.
    utils.set_verbosity(logger, level=int(verbose))

    # Reset counter (needed for consistency during testing).
    jsonrec.reset_sequence_names()

    # This method requires two inputs.
    if not (query and target):
        utils.error(f"Please specify a TARGET and a QUERY")

    if global_:
        mode = const.GLOBAL_ALIGN
    elif local_:
        mode = const.LOCAL_ALIGN
    elif semiglobal:
        mode = const.SEMIGLOBAL_ALIGN
    else:
        mode = const.GLOBAL_ALIGN

    # A parameter for each record.
    common = dict(
        protein=protein, translate=translate, mutations=mutations, pep1=pep1, pep3=pep3,
        table=table, strict=strict, start=start, end=end, gap_open=gap_open, gap_extend=gap_extend,
        mode=mode
    )

    # Create parameters to represent each data.
    param_t = objects.Param(acc=target, **common)
    param_q = objects.Param(acc=query, **common)

    # Fill JSON data for parameters.
    param_t.json = fetch.get_json(param_t.acc, inter=inter, strict=True)[:limit]
    param_q.json = fetch.get_json(param_q.acc, inter=inter, strict=True)[:limit]

    # Each data object may contain several records.
    #
    # For more than one record we iterate in pairs
    #
    for rec1, rec2 in zip(param_q.json, param_t.json):
        qrecs = fastarec.get_fasta(rec1, param=param_q)
        trecs = fastarec.get_fasta(rec2, param=param_t)
        for qseq, tseq in zip(qrecs, trecs):

            if (len(qseq) > MAX_LEN):
                utils.error(f"query is longer than maximum: {len(qseq):,} > {MAX_LEN:,}")

            if (len(tseq) > MAX_LEN):
                utils.error(f"target sequence is longer than maximum: {len(tseq):,} > {MAX_LEN:,}")

            biopython_align(qseq=qseq, tseq=tseq, param=param_q)
示例#2
0
def run(start=1,
        end='',
        mode=LOCAL_ALIGN,
        gap_open=11,
        gap_extend=1,
        protein=False,
        translate=False,
        inter=False,
        verbose=False,
        query='',
        target=''):
    """
    Handles an alignment request.
    """

    # Set the verbosity of the process.
    utils.set_verbosity(logger, level=int(verbose))

    # Ensure counter is reset.
    jsonrec.reset_counter()

    # Requires two inputs.
    if not (query and target):
        utils.error(f"Please specify both a QUERY and a TARGET")

    param1 = objects.Param(name=query,
                           protein=protein,
                           translate=translate,
                           start=start,
                           end=end,
                           gap_open=gap_open,
                           gap_extend=gap_extend,
                           mode=mode)
    param2 = objects.Param(name=target,
                           protein=protein,
                           translate=translate,
                           start=start,
                           end=end,
                           gap_open=gap_open,
                           gap_extend=gap_extend,
                           mode=mode)

    # Get the JSON data.
    param1.json = storage.get_json(param1.name, inter=inter, strict=True)
    param2.json = storage.get_json(param2.name, inter=inter, strict=True)

    for rec1 in param1.json:

        for rec2 in param2.json:

            qrecs = fastarec.get_fasta(rec1, param=param1)
            trecs = fastarec.get_fasta(rec2, param=param2)

            for qseq in qrecs:
                for tseq in trecs:
                    parasail_align(qseq=qseq, tseq=tseq, param=param1)
示例#3
0
    def make_param(acc):
        """
        Creates a parameter for each accession.

        """
        # Set the verbosity
        utils.set_verbosity(logger, level=int(verbose))

        # A simple wrapper class to carry all parameters around.
        p = objects.Param(start=start,
                          end=end,
                          seqid=seqid,
                          protein=protein,
                          revcomp=revcomp,
                          acc=acc,
                          translate=translate,
                          reverse=reverse,
                          uid=id_,
                          gff=gff,
                          complement=complement,
                          name=name,
                          inter=inter,
                          features=features,
                          fasta=fasta,
                          type=type,
                          gene=gene,
                          regexp=match,
                          transcribe=transcribe)

        # Fill the json data for the parameter if not an update
        p.json = fetch.get_json(p.acc, seqid=seqid, inter=inter)

        return p
示例#4
0
def run(update=False,
        rename='',
        seqid='',
        protein=False,
        verbose=False,
        *data):
    """
    Fetches and manages data in storage.
    """

    # Set the verbosity
    utils.set_verbosity(logger, level=int(verbose))

    # Reset counter (needed for consistency during testing).
    jsonrec.reset_counter()

    # A simple wrapper class to represent input parameters.
    param = objects.Param(seqid=seqid,
                          rename=rename,
                          start=1,
                          protein=protein,
                          update=update)

    # Fetch the data.
    fetch_data(data, param=param)

    # Renaming after fetching.
    if rename:
        rename_data(data, param=param, newname=rename)
示例#5
0
文件: main.py 项目: zghnbv/deepgo
    def make_param(name):
        """
        Creates a parameter for each accession.

        """
        # Set the verbosity
        utils.set_verbosity(logger, level=int(verbose))

        # A very common error to pass a fragment as
        if name.startswith("-"):
            msg = f"Invalid accession number: {name}"
            utils.error(msg)

        # A simple wrapper class to carry all parameters around.
        p = objects.Param(start=start, end=end, seqid=seqid, protein=protein, revcomp=revcomp,
                        update=update, name=name, gff=gff, translate=translate, reverse=reverse, complement=complement,
                        fasta=fasta, type=type, gene=gene, regexp=match, transcribe=transcribe)

        # Fill the json data for the parameter.
        p.json = storage.get_json(p.name, seqid=seqid, inter=inter)
        return p
示例#6
0
文件: align.py 项目: Natay/bio-2
def run(start=1,
        end='',
        gap_open=11,
        gap_extend=1,
        local_=False,
        global_=False,
        semiglobal=False,
        protein=False,
        translate=False,
        inter=False,
        verbose=False,
        query=None,
        target=None):
    """
    Performs an alignment between the query and target.
    """

    # Set the verbosity of the process.
    utils.set_verbosity(logger, level=int(verbose))

    # Ensure counter is reset.
    jsonrec.reset_counter()

    # Requires two inputs.
    if not (query and target):
        utils.error(f"Please specify both a QUERY and a TARGET")

    if global_:
        mode = const.GLOBAL_ALIGN
    elif local_:
        mode = const.LOCAL_ALIGN
    elif semiglobal:
        mode = const.SEMIGLOBAL_ALIGN
    else:
        mode = const.SEMIGLOBAL_ALIGN

    param1 = objects.Param(acc=query,
                           protein=protein,
                           translate=translate,
                           start=start,
                           end=end,
                           gap_open=gap_open,
                           gap_extend=gap_extend,
                           mode=mode)
    param2 = objects.Param(acc=target,
                           protein=protein,
                           translate=translate,
                           start=start,
                           end=end,
                           gap_open=gap_open,
                           gap_extend=gap_extend,
                           mode=mode)

    # Get the JSON data.
    param1.json = storage.get_json(param1.acc, inter=inter, strict=True)
    param2.json = storage.get_json(param2.acc, inter=inter, strict=True)

    for rec1 in param1.json:

        for rec2 in param2.json:

            qrecs = fastarec.get_fasta(rec1, param=param1)
            trecs = fastarec.get_fasta(rec2, param=param2)

            for qseq in qrecs:
                for tseq in trecs:
                    parasail_align(qseq=qseq, tseq=tseq, param=param1)
示例#7
0
def run(start=1,
        end='',
        gap_open=11,
        gap_extend=1,
        local_=False,
        global_=False,
        semiglobal=False,
        protein=False,
        translate=False,
        inter=False,
        table=False,
        strict=False,
        pep1=False,
        pep3=False,
        verbose=False,
        target=None,
        query=None):
    """
    Performs an alignment between the query and target.
    """

    # Alignments over this size will take a long time!
    MAX_LEN = 100000

    # Set the verbosity of the process.
    utils.set_verbosity(logger, level=int(verbose))

    # Reset counter (needed for consistency during testing).
    jsonrec.reset_counter()

    # This method requires two inputs.
    if not (query and target):
        utils.error(f"Please specify both a QUERY and a TARGET")

    if global_:
        mode = const.GLOBAL_ALIGN
    elif local_:
        mode = const.LOCAL_ALIGN
    elif semiglobal:
        mode = const.SEMIGLOBAL_ALIGN
    else:
        mode = const.GLOBAL_ALIGN

    # A parameter for each record.
    param1 = objects.Param(acc=query,
                           protein=protein,
                           translate=translate,
                           pep1=pep1,
                           pep3=pep3,
                           start=start,
                           end=end,
                           gap_open=gap_open,
                           gap_extend=gap_extend,
                           mode=mode)

    param2 = objects.Param(acc=target,
                           protein=protein,
                           translate=translate,
                           start=start,
                           end=end,
                           gap_open=gap_open,
                           gap_extend=gap_extend,
                           mode=mode)

    # Get the JSON data.
    param1.json = storage.get_json(param1.acc, inter=inter, strict=True)
    param2.json = storage.get_json(param2.acc, inter=inter, strict=True)

    # Each data object may contain several records.
    for rec1 in param1.json:
        for rec2 in param2.json:

            qrecs = fastarec.get_fasta(rec1, param=param1)
            trecs = fastarec.get_fasta(rec2, param=param2)

            for qseq in qrecs:
                for tseq in trecs:

                    if (len(qseq) > MAX_LEN):
                        utils.error(
                            f"query is longer than maximum: {len(qseq):,} > {MAX_LEN:,}"
                        )

                    if (len(tseq) > MAX_LEN):
                        utils.error(
                            f"target sequence is longer than maximum: {len(tseq):,} > {MAX_LEN:,}"
                        )

                    biopython_align(qseq=qseq,
                                    tseq=tseq,
                                    param=param1,
                                    table=table,
                                    strict=strict)