#!/usr/bin/env python
# coding: utf-8
import numpy as np

def find_add_srows(lst_no_anno, check_inds, k):
    """
    Finds pairs of repeated structures, representated as diagonals of a 
    certain length, k, that start at the same time step as previously found 
    pairs of repeated structures of the same length.  
        
    Args
    ----
    lst_no_anno: np.array 
        list of pairs of repeats
        
    check_inds: np.array
        list of ending indices for repeats of length k that we 
        use to check lst_no_anno for more repeats of length k 
       
    k: int
        length of repeats that we are looking for
            
    Returns
    -------
    add_rows: np.array
        List of newly found pairs of repeats of length K that are 
        contained in larger repeats in lst_no_anno
            
    """

    # Logical, which pair of repeats has a length greater than k (T returns 1, F returns 0)
    search_inds = (L[:,4] > k)

    # Multipy the starting index of all repeats "I" by search_inds
    SI = np.multiply(L[:,0], search_inds)

    # Multiply the starting index of all repeats "J" by search_inds
    SJ = np.multiply(L[:,2], search_inds)

    # Loop over check_inds
    for i in range(check_inds.size):
        ci = check_inds[i] 
            
    # Left check: check for CI on the left side of the pairs 
        # Check if the starting index of repeat "I" of pair of repeats "IJ" equals CI
        lnds = (SI == ci) 
        print("lnds:", lnds)
        #print(lnds.sum(axis = 0))
        
        # If the sum across (row) is greater than 0 
        if lnds.sum(axis = 0) > 0: 
            # Find the 2nd entry of the row (lnds) whose starting index of repeat "I" equals CI 
            SJ_li = L[lnds, 2] 
            #print("SJ_li", SJ_li)
            
            # Used for the length of found pair of repeats 
            l_num = SJ_li.shape[0] #Dim 0 corresponds to rows, wouldn't l_num always be 1? 
            #print("l_num:", l_num)
        
            # Found pair of repeats on the left side 
            one_lsi = L[lnds, 0]            #Starting index of found repeat i
            one_lei = L[lnds, 0] + k - 1    #Ending index of found repeat i
            one_lsj = SJ_li                 #Starting index of found repeat j
            one_lej = SJ_li + k - 1         #Ending index of found repeat j
            one_lk = np.ones((l_num, 1))*k  #Length of found pair of repeats, i and j 
            l_add = np.concatenate((one_lsi, one_lei, one_lsj, one_lej, one_lk), axis = None)
            #print("l_add:", l_add)
            
            # Found pair of repeats on the right side 
            two_lsi = L[lnds, 0] + k        #Starting index of found repeat i 
            two_lei = L[lnds, 1]            #Ending index of ofund repeat i
            two_lsj = SJ_li + k             #Starting index of found repeat j 
            two_lej = L[lnds, 3]            #Ending index of found repeat j
            two_lk = L[lnds, 4] - k         #Length of found pair of repeats, i and j 
            l_add_right = np.concatenate((two_lsi, two_lei, two_lsj, two_lej, two_lk), axis = None)
            #print("l_add_right:", l_add_right)
            
            # Stack the found rows vertically 
            add_rows = np.vstack((l_add, l_add_right))
            
            # Stack all the rows found on the left side of the pairs 
            add_rows = np.concatenate((add_rows, add_rows), axis = 0)
            #print("add_rows:", add_rows)
            
            #print()
    # Right Check: check for CI on the right side of the pairs 
        # Check if the the starting index of repeat "J" of the pair "IJ" equals CI
        rnds = (SJ == ci) 
        #print("rnds:", rnds)

        if rnds.sum(axis = 0) > 0:
            SJ_ri = L[rnds, 0]
            r_num = SJ_ri.shape[0] 
          
            # Found pair of repeats on the left side 
            one_rsi = SJ_ri                 #Starting index of found repeat i 
            one_rei = SJ_ri + k - 1         #Ending index of found repeat i 
            one_rsj = L[rnds, 2]            #Starting index of found repeat j
            one_rej = L[rnds, 2] + k - 1    #Ending index of found repeat j 
            one_rk = k*np.ones((r_num, 1))  #Length of found pair or repeats, i and j 
            r_add = np.concatenate((one_rsi, one_rei, one_rsj, one_rej, one_rk), axis = None)
            
            # Found pairs on the right side 
            two_rsi = SJ_ri + k             #Starting index of found repeat i  
            two_rei = L[rnds, 1]            #Ending index of found repeat i 
            two_rsj = L[rnds, 2] + k        #Starting index of found repeat j
            two_rej = L[rnds,3]             #Ending index of found repeat j 
            two_rk = L[rnds, 4] - k         #Length of found pair or repeats, i and j 
            r_add_right = np.concatenate((two_rsi, two_rei, two_rsj, two_rej, two_rk), axis = None) 
            
            # Stack the found rows vertically 
            add_rows = np.vstack((r_add, r_add_right))
            
            # Stack all the rows found on the right side of the pairs 
            add_rows = np.concatenate((add_rows, add_rows), axis = 0).astype(int)
            #print(add_rows)
            
    return add_rows 




80191946c8ac70f66144a67047763a5cd921cd23
<mask token>

<mask token>


def find_add_srows(lst_no_anno, check_inds, k):
    """
    Finds pairs of repeated structures, representated as diagonals of a 
    certain length, k, that start at the same time step as previously found 
    pairs of repeated structures of the same length.  
        
    Args
    ----
    lst_no_anno: np.array 
        list of pairs of repeats
        
    check_inds: np.array
        list of ending indices for repeats of length k that we 
        use to check lst_no_anno for more repeats of length k 
       
    k: int
        length of repeats that we are looking for
            
    Returns
    -------
    add_rows: np.array
        List of newly found pairs of repeats of length K that are 
        contained in larger repeats in lst_no_anno
            
    """
    search_inds = L[:, 4] > k
    SI = np.multiply(L[:, 0], search_inds)
    SJ = np.multiply(L[:, 2], search_inds)
    for i in range(check_inds.size):
        ci = check_inds[i]
        lnds = SI == ci
        print('lnds:', lnds)
        if lnds.sum(axis=0) > 0:
            SJ_li = L[lnds, 2]
            l_num = SJ_li.shape[0]
            one_lsi = L[lnds, 0]
            one_lei = L[lnds, 0] + k - 1
            one_lsj = SJ_li
            one_lej = SJ_li + k - 1
            one_lk = np.ones((l_num, 1)) * k
            l_add = np.concatenate((one_lsi, one_lei, one_lsj, one_lej,
                one_lk), axis=None)
            two_lsi = L[lnds, 0] + k
            two_lei = L[lnds, 1]
            two_lsj = SJ_li + k
            two_lej = L[lnds, 3]
            two_lk = L[lnds, 4] - k
            l_add_right = np.concatenate((two_lsi, two_lei, two_lsj,
                two_lej, two_lk), axis=None)
            add_rows = np.vstack((l_add, l_add_right))
            add_rows = np.concatenate((add_rows, add_rows), axis=0)
        rnds = SJ == ci
        if rnds.sum(axis=0) > 0:
            SJ_ri = L[rnds, 0]
            r_num = SJ_ri.shape[0]
            one_rsi = SJ_ri
            one_rei = SJ_ri + k - 1
            one_rsj = L[rnds, 2]
            one_rej = L[rnds, 2] + k - 1
            one_rk = k * np.ones((r_num, 1))
            r_add = np.concatenate((one_rsi, one_rei, one_rsj, one_rej,
                one_rk), axis=None)
            two_rsi = SJ_ri + k
            two_rei = L[rnds, 1]
            two_rsj = L[rnds, 2] + k
            two_rej = L[rnds, 3]
            two_rk = L[rnds, 4] - k
            r_add_right = np.concatenate((two_rsi, two_rei, two_rsj,
                two_rej, two_rk), axis=None)
            add_rows = np.vstack((r_add, r_add_right))
            add_rows = np.concatenate((add_rows, add_rows), axis=0).astype(int)
    return add_rows

import numpy as np


def find_add_srows(lst_no_anno, check_inds, k):
    """
    Finds pairs of repeated structures, representated as diagonals of a 
    certain length, k, that start at the same time step as previously found 
    pairs of repeated structures of the same length.  
        
    Args
    ----
    lst_no_anno: np.array 
        list of pairs of repeats
        
    check_inds: np.array
        list of ending indices for repeats of length k that we 
        use to check lst_no_anno for more repeats of length k 
       
    k: int
        length of repeats that we are looking for
            
    Returns
    -------
    add_rows: np.array
        List of newly found pairs of repeats of length K that are 
        contained in larger repeats in lst_no_anno
            
    """
    search_inds = L[:, 4] > k
    SI = np.multiply(L[:, 0], search_inds)
    SJ = np.multiply(L[:, 2], search_inds)
    for i in range(check_inds.size):
        ci = check_inds[i]
        lnds = SI == ci
        print('lnds:', lnds)
        if lnds.sum(axis=0) > 0:
            SJ_li = L[lnds, 2]
            l_num = SJ_li.shape[0]
            one_lsi = L[lnds, 0]
            one_lei = L[lnds, 0] + k - 1
            one_lsj = SJ_li
            one_lej = SJ_li + k - 1
            one_lk = np.ones((l_num, 1)) * k
            l_add = np.concatenate((one_lsi, one_lei, one_lsj, one_lej,
                one_lk), axis=None)
            two_lsi = L[lnds, 0] + k
            two_lei = L[lnds, 1]
            two_lsj = SJ_li + k
            two_lej = L[lnds, 3]
            two_lk = L[lnds, 4] - k
            l_add_right = np.concatenate((two_lsi, two_lei, two_lsj,
                two_lej, two_lk), axis=None)
            add_rows = np.vstack((l_add, l_add_right))
            add_rows = np.concatenate((add_rows, add_rows), axis=0)
        rnds = SJ == ci
        if rnds.sum(axis=0) > 0:
            SJ_ri = L[rnds, 0]
            r_num = SJ_ri.shape[0]
            one_rsi = SJ_ri
            one_rei = SJ_ri + k - 1
            one_rsj = L[rnds, 2]
            one_rej = L[rnds, 2] + k - 1
            one_rk = k * np.ones((r_num, 1))
            r_add = np.concatenate((one_rsi, one_rei, one_rsj, one_rej,
                one_rk), axis=None)
            two_rsi = SJ_ri + k
            two_rei = L[rnds, 1]
            two_rsj = L[rnds, 2] + k
            two_rej = L[rnds, 3]
            two_rk = L[rnds, 4] - k
            r_add_right = np.concatenate((two_rsi, two_rei, two_rsj,
                two_rej, two_rk), axis=None)
            add_rows = np.vstack((r_add, r_add_right))
            add_rows = np.concatenate((add_rows, add_rows), axis=0).astype(int)
    return add_rows

#!/usr/bin/env python
# coding: utf-8
import numpy as np

def find_add_srows(lst_no_anno, check_inds, k):
    """
    Finds pairs of repeated structures, representated as diagonals of a 
    certain length, k, that start at the same time step as previously found 
    pairs of repeated structures of the same length.  
        
    Args
    ----
    lst_no_anno: np.array 
        list of pairs of repeats
        
    check_inds: np.array
        list of ending indices for repeats of length k that we 
        use to check lst_no_anno for more repeats of length k 
       
    k: int
        length of repeats that we are looking for
            
    Returns
    -------
    add_rows: np.array
        List of newly found pairs of repeats of length K that are 
        contained in larger repeats in lst_no_anno
            
    """

    # Logical, which pair of repeats has a length greater than k (T returns 1, F returns 0)
    search_inds = (L[:,4] > k)

    # Multipy the starting index of all repeats "I" by search_inds
    SI = np.multiply(L[:,0], search_inds)

    # Multiply the starting index of all repeats "J" by search_inds
    SJ = np.multiply(L[:,2], search_inds)

    # Loop over check_inds
    for i in range(check_inds.size):
        ci = check_inds[i] 
            
    # Left check: check for CI on the left side of the pairs 
        # Check if the starting index of repeat "I" of pair of repeats "IJ" equals CI
        lnds = (SI == ci) 
        print("lnds:", lnds)
        #print(lnds.sum(axis = 0))
        
        # If the sum across (row) is greater than 0 
        if lnds.sum(axis = 0) > 0: 
            # Find the 2nd entry of the row (lnds) whose starting index of repeat "I" equals CI 
            SJ_li = L[lnds, 2] 
            #print("SJ_li", SJ_li)
            
            # Used for the length of found pair of repeats 
            l_num = SJ_li.shape[0] #Dim 0 corresponds to rows, wouldn't l_num always be 1? 
            #print("l_num:", l_num)
        
            # Found pair of repeats on the left side 
            one_lsi = L[lnds, 0]            #Starting index of found repeat i
            one_lei = L[lnds, 0] + k - 1    #Ending index of found repeat i
            one_lsj = SJ_li                 #Starting index of found repeat j
            one_lej = SJ_li + k - 1         #Ending index of found repeat j
            one_lk = np.ones((l_num, 1))*k  #Length of found pair of repeats, i and j 
            l_add = np.concatenate((one_lsi, one_lei, one_lsj, one_lej, one_lk), axis = None)
            #print("l_add:", l_add)
            
            # Found pair of repeats on the right side 
            two_lsi = L[lnds, 0] + k        #Starting index of found repeat i 
            two_lei = L[lnds, 1]            #Ending index of ofund repeat i
            two_lsj = SJ_li + k             #Starting index of found repeat j 
            two_lej = L[lnds, 3]            #Ending index of found repeat j
            two_lk = L[lnds, 4] - k         #Length of found pair of repeats, i and j 
            l_add_right = np.concatenate((two_lsi, two_lei, two_lsj, two_lej, two_lk), axis = None)
            #print("l_add_right:", l_add_right)
            
            # Stack the found rows vertically 
            add_rows = np.vstack((l_add, l_add_right))
            
            # Stack all the rows found on the left side of the pairs 
            add_rows = np.concatenate((add_rows, add_rows), axis = 0)
            #print("add_rows:", add_rows)
            
            #print()
    # Right Check: check for CI on the right side of the pairs 
        # Check if the the starting index of repeat "J" of the pair "IJ" equals CI
        rnds = (SJ == ci) 
        #print("rnds:", rnds)

        if rnds.sum(axis = 0) > 0:
            SJ_ri = L[rnds, 0]
            r_num = SJ_ri.shape[0] 
          
            # Found pair of repeats on the left side 
            one_rsi = SJ_ri                 #Starting index of found repeat i 
            one_rei = SJ_ri + k - 1         #Ending index of found repeat i 
            one_rsj = L[rnds, 2]            #Starting index of found repeat j
            one_rej = L[rnds, 2] + k - 1    #Ending index of found repeat j 
            one_rk = k*np.ones((r_num, 1))  #Length of found pair or repeats, i and j 
            r_add = np.concatenate((one_rsi, one_rei, one_rsj, one_rej, one_rk), axis = None)
            
            # Found pairs on the right side 
            two_rsi = SJ_ri + k             #Starting index of found repeat i  
            two_rei = L[rnds, 1]            #Ending index of found repeat i 
            two_rsj = L[rnds, 2] + k        #Starting index of found repeat j
            two_rej = L[rnds,3]             #Ending index of found repeat j 
            two_rk = L[rnds, 4] - k         #Length of found pair or repeats, i and j 
            r_add_right = np.concatenate((two_rsi, two_rei, two_rsj, two_rej, two_rk), axis = None) 
            
            # Stack the found rows vertically 
            add_rows = np.vstack((r_add, r_add_right))
            
            # Stack all the rows found on the right side of the pairs 
            add_rows = np.concatenate((add_rows, add_rows), axis = 0).astype(int)
            #print(add_rows)
            
    return add_rows 



