Skip to content

Addition of a Seq.join() method #1731

Closed

Description

@widdowquinn

Setup

I would like to be able to use the string-like concatenation/addition behaviour of Seq objects in the same way as using 'some_string'.join(), but this behaviour is not currently available.

Expected behaviour

spacer = Seq('NNNNN')
seqlist = list(SeqIO.parse('myfile.fasta', 'fasta'))
concatenated = spacer.join(seqlist)

Actual behaviour

Not implemented.

I appreciate that this is a minefield for resolving alphabets…

Activity

  1. peterjc commented on Jul 10, 2018

    @peterjc
    Member

    If we leave aside mixing Seq and SeqRecord objects, I agree this would be nice and fits with the long term goal of making the Seq object more like the Pyhton string:

    from Bio.Seq import Seq
    from Bio import SeqIO
    
    spacer = Seq('NNNNN')
    concatenated = spacer.join(record.seq for record in SeqIO.parse('myfile.fasta', 'fasta'))

    i.e. Define Seq object .join method taking an iterable of strings/other Seq-type objects.

    This is relatively easy other than dealing with picking a consensus alphabet - although we can probably just follow the precedent elsewhere (e.g. for the MultipleSeqAlignment ),

    https://github.com/biopython/biopython/blob/biopython-172/Bio/Alphabet/__init__.py#L324

    In the special case of joining with an empty sequence, does its alphabet need consideration?

  2. self-assigned this
    on Jul 10, 2018
  3. widdowquinn commented on Jul 10, 2018

    @widdowquinn
    ContributorAuthor

    Yeah, sorry about the mix-up of classes with SeqIO.parse() there… ;)

  4. kaskales commented on Jul 30, 2018

    @kaskales
    Contributor

    @peterjc I see this issue is still open. Is it ok if I give it a shot as well?

  5. added a commit that references this issue on Jul 30, 2018
    c608b7d
  6. peterjc commented on Jul 31, 2018

    @peterjc
    Member

    @kaskales did you have any thoughts on examples like Seq("").join(some_dna_seqs) vs Seq("", some_generic_alphabet).join(some_dna_seqs) where in some senses the default/generic alphabet of the empty sequence space is not important for the combined sequence (which in this example might be expected to be DNA from the alphabet attributes set in some_dna_seqs)

  7. kaskales commented on Jul 31, 2018

    @kaskales
    Contributor

    @peterjc In your case where the spacer is an empty string, that would be the only time it might be good to assume the same alphabet as some_dna_seqs by default. Otherwise the spacer alphabet will take into consideration, where it should be up to the user to correctly identify the alphabet used in the spacer.

  8. peterjc commented on Aug 1, 2018

    @peterjc
    Member

    Yes, I'm talking about the special case where the spacer is a zero length sequence.

  9. peterjc commented on Mar 15, 2019

    @peterjc
    Member

    Applied as e856cd3 from #1746. Thank you all.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions