treetime/seq_utils.py
def seq2array(seq, fill_overhangs=True, ambiguous_character='N'):
    """
    Take the raw sequence, substitute the "overhanging" gaps with 'N' (missequenced),
    and convert the sequence to the numpy array of chars.

    Parameters
    ----------
     seq : Biopython.SeqRecord, str, iterable
        Sequence as an object of SeqRecord, string or iterable

     fill_overhangs : bool
        If True, substitute the "overhanging" gaps with ambiguous character symbol

     ambiguous_character : char
        Specify the character for ambiguous state ('N' default for nucleotide)

    Returns
    -------
     sequence : np.array
        Sequence as 1D numpy array of chars

    """
    try:
        sequence = ''.join(seq)
    except TypeError:
        sequence = seq

    sequence = np.array(list(sequence))
    # substitute overhanging unsequenced tails
    if fill_overhangs:
        sequence [:np.where(sequence != '-')[0][0]] = ambiguous_character
        sequence [np.where(sequence != '-')[0][-1]+1:] = ambiguous_character
    return sequence
def seq2array(seq, fill_overhangs=True, ambiguous_character='N'):
    """
    Take the raw sequence, substitute the "overhanging" gaps with 'N' (missequenced),
    and convert the sequence to the numpy array of chars.

    Parameters
    ----------
     seq : Biopython.SeqRecord, str, iterable
        Sequence as an object of SeqRecord, string or iterable

     fill_overhangs : bool
        If True, substitute the "overhanging" gaps with ambiguous character symbol

     ambiguous_character : char
        Specify the character for ambiguous state ('N' default for nucleotide)

    Returns
    -------
     sequence : np.array
        Sequence as 1D numpy array of chars

    """
    try:
        sequence = ''.join(seq)
    except TypeError:
        sequence = seq

    sequence = np.array(list(sequence))
    # substitute overhanging unsequenced tails
    if fill_overhangs:
        sequence [:np.where(sequence != '-')[0][0]] = ambiguous_character
        sequence [np.where(sequence != '-')[0][-1]+1:] = ambiguous_character
    return sequence
Take the raw sequence, substitute the "overhanging" gaps with 'N' (missequenced),
    and convert the sequence to the numpy array of chars.

    Parameters
    ----------
     seq : Biopython.SeqRecord, str, iterable
        Sequence as an object of SeqRecord, string or iterable

     fill_overhangs : bool
        If True, substitute the "overhanging" gaps with ambiguous character symbol

     ambiguous_character : char
        Specify the character for ambiguous state ('N' default for nucleotide)

    Returns
    -------
     sequence : np.array
        Sequence as 1D numpy array of chars