Skip to content

Improve documentation of Bio.codonalign.build() function #1840

Closed

Description

@vanya-antonov

I am new to the github and this is my first post, so I am sorry if it is not very appropriate..

Anyway, I was thinking to use Biopython to create a nucleotide alignment based on a protein alignment, i.e. to do what was asked on Biostars a while ago: https://www.biostars.org/p/89741/

Apparently, this Biopython function was developed to help with similar tasks. However, the example from this function documentation may be a bit confusing because the final nucleotide alignment has a single gap while I would only expect triple-gaps in a codon alignment:

>>> print(codon_aln)
    CodonAlphabet(Standard) CodonAlignment with 2 rows and 69 columns (23 codons)
    TCAGGGACTGCGAGAACCAAGCTACTGCTGCTGCTGGCTGCGCTCTGCGCCGCAGGT...GAG pro1
    TCAGGGACTTCGAGAACCAAGCG-CTCCTGCTGCTGGCTGCGCTCGGCGCCGCAGGT...GAG pro2

I think that the original idea of this example was to demonstrate that the function is able to handle frameshifts caused by single nucleotide insertions. At the same time this may not be the most important feature of the function and an example that converts a single gap from a protein alignment into triple gaps in the nucleotide one may be more informative.

Activity

  1. peterjc commented on Nov 1, 2018

    @peterjc
    Member

    Which bit of the Biopython documentation specifically are you referring to?

  2. vanya-antonov commented on Nov 1, 2018

    @vanya-antonov
    ContributorAuthor

    Hello Peter,
    I am talking about this part from the "biopython/Bio/codonalign/init.py" file:

    """Build a codon alignment from protein alignment and corresponding nucleotides.
    Arguments:
    - pro_align - a protein MultipleSeqAlignment object
    - nucl_align - an object returned by SeqIO.parse or SeqIO.index
    or a collection of SeqRecord.
    - alphabet - alphabet for the returned codon alignment
    - corr_dict - a dict that maps protein id to nucleotide id
    - complete_protein - whether the sequence begins with a start
    codon
    - frameshift - whether to apply frameshift detection
    Return a CodonAlignment object
    >>> from Bio.Alphabet import IUPAC
    >>> from Bio.Seq import Seq
    >>> from Bio.SeqRecord import SeqRecord
    >>> from Bio.Align import MultipleSeqAlignment
    >>> seq1 = SeqRecord(Seq('TCAGGGACTGCGAGAACCAAGCTACTGCTGCTGCTGGCTGCGCTCTGCGCCGCAGGTGGGGCGCTGGAG',
    ... alphabet=IUPAC.IUPACUnambiguousDNA()), id='pro1')
    >>> seq2 = SeqRecord(Seq('TCAGGGACTTCGAGAACCAAGCGCTCCTGCTGCTGGCTGCGCTCGGCGCCGCAGGTGGAGCACTGGAG',
    ... alphabet=IUPAC.IUPACUnambiguousDNA()), id='pro2')
    >>> pro1 = SeqRecord(Seq('SGTARTKLLLLLAALCAAGGALE', alphabet=IUPAC.protein),id='pro1')
    >>> pro2 = SeqRecord(Seq('SGTSRTKRLLLLAALGAAGGALE', alphabet=IUPAC.protein),id='pro2')
    >>> aln = MultipleSeqAlignment([pro1, pro2])
    >>> codon_aln = build(aln, [seq1, seq2])
    >>> print(codon_aln)
    CodonAlphabet(Standard) CodonAlignment with 2 rows and 69 columns (23 codons)
    TCAGGGACTGCGAGAACCAAGCTACTGCTGCTGCTGGCTGCGCTCTGCGCCGCAGGT...GAG pro1
    TCAGGGACTTCGAGAACCAAGCG-CTCCTGCTGCTGGCTGCGCTCGGCGCCGCAGGT...GAG pro2
    """

  3. peterjc commented on Nov 1, 2018

    @peterjc
    Member

    Could you contribute a more typical example to insert above this one?

  4. vanya-antonov commented on Nov 1, 2018

    @vanya-antonov
    ContributorAuthor

    Well, we can even use the sequences from the Biostars question:

    >>> from Bio.Alphabet import IUPAC, generic_protein
    >>> from Bio.Seq import Seq
    >>> from Bio.SeqRecord import SeqRecord
    >>> from Bio.Align import MultipleSeqAlignment
    >>> from Bio.codonalign import build
    >>> seq1 = SeqRecord(Seq('ATGTCTCGT', alphabet=IUPAC.IUPACUnambiguousDNA()), id='pro1')
    >>> seq2 = SeqRecord(Seq('ATGCGT', alphabet=IUPAC.IUPACUnambiguousDNA()), id='pro2')
    >>> pro1 = SeqRecord(Seq('MSR', alphabet=generic_protein), id='pro1')
    >>> pro2 = SeqRecord(Seq('M-R', alphabet=generic_protein), id='pro2')
    >>> aln = MultipleSeqAlignment([pro1, pro2])
    >>> codon_aln = build(aln, [seq1, seq2])
    >>> print(codon_aln)
    CodonAlphabet(Standard) CodonAlignment with 2 rows and 9 columns (3 codons)
    ATGTCTCGT pro1
    ATG---CGT pro2
    
  5. vanya-antonov commented on Nov 1, 2018

    @vanya-antonov
    ContributorAuthor

    BTW, there are also some typos in the documentation.

    1. The second argument of the function is nucl_seqs, however in the documentation it is called nucl_align:

      - nucl_align - an object returned by SeqIO.parse or SeqIO.index

      I believe nucl_align should be changed to nucl_seqs in documentation.

    2. The documentation mentions the frameshift argument:

      - frameshift - whether to apply frameshift detection

      However, there is no such argument in the function definition..

  6. peterjc commented on Nov 1, 2018

    @peterjc
    Member

    That sounds good - do you fancy turning this into a pull request? You can do it all from the GitHub website if you like (without running git at the command line).

  7. added a commit that references this issue on Nov 2, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions