Exemple #1
0
def Alignment2CDNA(alignment,
                   query_from=0,
                   sbjct_from=0,
                   genome=None,
                   remove_frameshifts=0):
    """build cDNA sequence from genomic fragment and
    return alignment of query to it.
    """

    fragments = []
    sbjct_pos = 0
    map_query2sbjct = alignlib_lite.py_makeAlignmentVector()

    # count in nucleotides for query
    query_pos = query_from * 3
    sbjct_pos = sbjct_from
    # position in cDNA
    cdna_pos = 0
    for state, l_query, l_sbjct in alignment:

        # count as nucleotides
        l_query *= 3

        keep = False

        if state == "M":
            keep = True
        elif state == "S":
            l_query = l_sbjct
            keep = True
        elif state == "F" and not remove_frameshifts:
            keep = True
        elif state == "G":
            if l_sbjct > 0:
                keep = True
        elif state == "P":
            keep = False

        if keep:
            if genome:
                fragments.append(genome[sbjct_pos:sbjct_pos + l_sbjct])

            if l_query > 0 and l_sbjct > 0:
                alignlib_lite.py_addDiagonal2Alignment(map_query2sbjct,
                                                       query_pos,
                                                       query_pos + l_query,
                                                       cdna_pos - query_pos)
            cdna_pos += l_sbjct

        query_pos += l_query
        sbjct_pos += l_sbjct

    return map_query2sbjct, fragments.join("")
Exemple #2
0
def Alignment2CDNA(alignment,
                   query_from=0,
                   sbjct_from=0,
                   genome=None,
                   remove_frameshifts=0):
    """build cDNA sequence from genomic fragment and
    return alignment of query to it.
    """

    fragments = []
    sbjct_pos = 0
    map_query2sbjct = alignlib_lite.py_makeAlignmentVector()

    # count in nucleotides for query
    query_pos = query_from * 3
    sbjct_pos = sbjct_from
    # position in cDNA
    cdna_pos = 0
    for state, l_query, l_sbjct in alignment:

        # count as nucleotides
        l_query *= 3

        keep = False

        if state == "M":
            keep = True
        elif state == "S":
            l_query = l_sbjct
            keep = True
        elif state == "F" and not remove_frameshifts:
            keep = True
        elif state == "G":
            if l_sbjct > 0:
                keep = True
        elif state == "P":
            keep = False

        if keep:
            if genome:
                fragments.append(genome[sbjct_pos:sbjct_pos + l_sbjct])

            if l_query > 0 and l_sbjct > 0:
                alignlib_lite.py_addDiagonal2Alignment(map_query2sbjct,
                                                       query_pos,
                                                       query_pos + l_query,
                                                       cdna_pos - query_pos)
            cdna_pos += l_sbjct

        query_pos += l_query
        sbjct_pos += l_sbjct

    return map_query2sbjct, fragments.join("")
Exemple #3
0
def Alignment2PeptideAlignment(alignment,
                               query_from=0,
                               sbjct_from=0,
                               genomic_sequence=None):
    """convert a Peptide2DNA aligment to a Peptide2Peptide alignment.

    How to handle frameshifts?
    """

    map_query2sbjct = alignlib_lite.py_makeAlignmentVector()

    query_pos = query_from
    sbjct_pos = 0
    sbjct_genome_pos = sbjct_from
    sbjct_residues = []
    codon = ""

    for state, l_query, l_sbjct in alignment:

        query_increment = 0
        sbjct_increment = 0

        if state == "M":

            query_increment = l_query
            sbjct_increment = l_sbjct / 3
            if genomic_sequence:
                codon = genomic_sequence[sbjct_genome_pos:sbjct_genome_pos +
                                         l_sbjct]

        elif state == "S":
            if l_query:
                sbjct_increment = 1
                query_increment = 1

            if genomic_sequence:
                codon += genomic_sequence[sbjct_genome_pos:sbjct_genome_pos +
                                          l_sbjct]

        elif state == "G":
            query_increment = l_query
            sbjct_increment = l_sbjct / 3
            if genomic_sequence:
                codon += genomic_sequence[sbjct_genome_pos:sbjct_genome_pos +
                                          l_sbjct]

        elif state == "P":
            # only increment query, sbjct does not advance.
            query_increment = l_query

        if query_increment and sbjct_increment:
            alignlib_lite.py_addDiagonal2Alignment(map_query2sbjct, query_pos,
                                                   query_pos + query_increment,
                                                   sbjct_pos - query_pos)

        if sbjct_increment and genomic_sequence:
            for x in range(0, len(codon), 3):
                sbjct_residues.append(MapCodon2AA(codon[x:x + 3]))
            codon = ""

        query_pos += query_increment
        sbjct_pos += sbjct_increment

        sbjct_genome_pos += l_sbjct

    return map_query2sbjct, "".join(sbjct_residues)
Exemple #4
0
def Alignment2PeptideAlignment(alignment,
                               query_from=0,
                               sbjct_from=0,
                               genomic_sequence=None):
    """convert a Peptide2DNA aligment to a Peptide2Peptide alignment.

    How to handle frameshifts?
    """

    map_query2sbjct = alignlib_lite.py_makeAlignmentVector()

    query_pos = query_from
    sbjct_pos = 0
    sbjct_genome_pos = sbjct_from
    sbjct_residues = []
    codon = ""

    for state, l_query, l_sbjct in alignment:

        query_increment = 0
        sbjct_increment = 0

        if state == "M":

            query_increment = l_query
            sbjct_increment = l_sbjct / 3
            if genomic_sequence:
                codon = genomic_sequence[
                    sbjct_genome_pos:sbjct_genome_pos + l_sbjct]

        elif state == "S":
            if l_query:
                sbjct_increment = 1
                query_increment = 1

            if genomic_sequence:
                codon += genomic_sequence[sbjct_genome_pos:
                                          sbjct_genome_pos + l_sbjct]

        elif state == "G":
            query_increment = l_query
            sbjct_increment = l_sbjct / 3
            if genomic_sequence:
                codon += genomic_sequence[sbjct_genome_pos:
                                          sbjct_genome_pos + l_sbjct]

        elif state == "P":
            # only increment query, sbjct does not advance.
            query_increment = l_query

        if query_increment and sbjct_increment:
            alignlib_lite.py_addDiagonal2Alignment(map_query2sbjct,
                                                   query_pos, query_pos +
                                                   query_increment,
                                                   sbjct_pos - query_pos)

        if sbjct_increment and genomic_sequence:
            for x in range(0, len(codon), 3):
                sbjct_residues.append(MapCodon2AA(codon[x:x + 3]))
            codon = ""

        query_pos += query_increment
        sbjct_pos += sbjct_increment

        sbjct_genome_pos += l_sbjct

    return map_query2sbjct, "".join(sbjct_residues)