phylogenetics/tools/df_editor.py
def split_sequence(df,uid,split_site):
    """
    Split a sequence in half, creating a new entry.  If a tree has already
    been loaded, this will create a polytomy at the new position.
    """

    _check_uid(df,uid)

    # Grab sequence to split
    sequence_to_split = df[df.uid == uid].sequence.tolist()[0]
    s1 = sequence_to_split[:split_site]
    s2 = sequence_to_split[split_site:]

    # Place to split frame
    i = np.where(df.uid == uid)[0][0]

    # Split frame
    df1 = df.iloc[:i].copy()
    df2 = df.iloc[np.array((i,i))].copy()
    df3 = df.iloc[(i+1):].copy()

    # Create new uid for new sequence
    uid_size = len(df.iloc[i].uid)
    new_uid = "".join([random.choice(string.ascii_letters)
                       for i in range(uid_size)])
    # Update entries with splits and new id
    df2 = df2.reset_index(drop=True)
    df2.at[0,"sequence"] = s1
    df2.at[1,"sequence"] = s2
    df2.at[1,"uid"] = new_uid

    # Concatenate and reindex
    new_df = pd.concat([df1,df2,df3],ignore_index=True,axis=0)
    new_df = new_df.reset_index(drop=True)

    return new_df

    Split a sequence in half, creating a new entry.  If a tree has already
    been loaded, this will create a polytomy at the new position.
    
Split a sequence in half, creating a new entry.  If a tree has already
been loaded, this will create a polytomy at the new position.
Split a sequence in half creating a new entry . If a tree has already been loaded this will create a polytomy at the new position .
def split_sequence(df,uid,split_site):
    _check_uid(df,uid)
    sequence_to_split = df[df.uid == uid].sequence.tolist()[0]
    s1 = sequence_to_split[:split_site]
    s2 = sequence_to_split[split_site:]
    i = np.where(df.uid == uid)[0][0]
    df1 = df.iloc[:i].copy()
    df2 = df.iloc[np.array((i,i))].copy()
    df3 = df.iloc[(i+1):].copy()
    uid_size = len(df.iloc[i].uid)
    new_uid = "".join([random.choice(string.ascii_letters)
                       for i in range(uid_size)])
    df2 = df2.reset_index(drop=True)
    df2.at[0,"sequence"] = s1
    df2.at[1,"sequence"] = s2
    df2.at[1,"uid"] = new_uid
    new_df = pd.concat([df1,df2,df3],ignore_index=True,axis=0)
    new_df = new_df.reset_index(drop=True)
    return new_df
def split_sequence ( df , uid , split_site ) : _check_uid ( df , uid ) sequence_to_split = df [ df . uid == uid ] . sequence . tolist ( ) [ 0 ] s1 = sequence_to_split [ : split_site ] s2 = sequence_to_split [ split_site : ] i = np . where ( df . uid == uid ) [ 0 ] [ 0 ] df1 = df . iloc [ : i ] . copy ( ) df2 = df . iloc [ np . array ( ( i , i ) ) ] . copy ( ) df3 = df . iloc [ ( i + 1 ) : ] . copy ( ) uid_size = len ( df . iloc [ i ] . uid ) new_uid = "" . join ( [ random . choice ( string . ascii_letters ) for i in range ( uid_size ) ] ) df2 = df2 . reset_index ( drop = True ) df2 . at [ 0 , "sequence" ] = s1 df2 . at [ 1 , "sequence" ] = s2 df2 . at [ 1 , "uid" ] = new_uid new_df = pd . concat ( [ df1 , df2 , df3 ] , ignore_index = True , axis = 0 ) new_df = new_df . reset_index ( drop = True ) return new_df
Split a sequence in half, creating a new entry.
Split a sequence in half creating a new entry .
"""
    Split a sequence in half, creating a new entry.  If a tree has already
    been loaded, this will create a polytomy at the new position.
    """ # Grab sequence to split # Place to split frame # Split frame # Create new uid for new sequence # Update entries with splits and new id # Concatenate and reindex
df
uid
split_site