<jupyter_start><jupyter_text>the MEME function  import all needed packages<jupyter_code>import numpy as np
import pandas as pd
import os

ROOT_DIR = os.getcwd()[:os.getcwd().rfind('Express')] + 'ExpressYeaself/'<jupyter_output><empty_output><jupyter_text>set up the direct path<jupyter_code>data = ROOT_DIR + 'expressyeaself/models/lstm/lstm_result.csv'<jupyter_output><empty_output><jupyter_text>set up the range of motif length and repeat time<jupyter_code>motif_length = 6
repeat_time = 8<jupyter_output><empty_output><jupyter_text>the search function<jupyter_code>def meme(string, length = 6, return_max = False, exact_length = False, amount = 5):
    """
    this function is the meme function to 
    search the repeat sequences
    
    Args:
    -----
        string (str) -- the linked string of all sequences
        length (int) -- the length of the motif

    Returns:
    -----
         repeated_motif (dict) -- the motif sequences repeat 
                                  for no more than set up 
                                  repeat time
    """
    n=len(string)
    dic={}
    for i in range(0,n-length):
        tmp=string[i:i+length]
        if '0' not in tmp:
            if tmp not in dic:
                dic[tmp]=1
            else:
                dic[tmp]+=1
    max_value = max(zip(dic.values(),dic.keys()))[0]
    if return_max == True:
        return max_value
#     if max_value < repeat_time:
#         return print('no such motif, the maximum repeat time is:', max_value)
#         return '0'
    dic = dict(sorted(dic.items(),key = lambda dic:dic[1],reverse=True))
    for seq in list(dic):
        if dic[seq] == 1:
            dic.pop(seq)
    if exact_length == True:
        if amount > len(dic):
            return print('the amount is larger than the actual motif amount, the repeated motif with size', length, 'is', len(dic))
        else:
            return sorted(dic.items(),key = lambda dic:dic[1],reverse=True)[:amount]
    repeated_motif = dic
    return repeated_motif<jupyter_output><empty_output><jupyter_text>the linking function<jupyter_code>high_acc_seqs = pd.read_csv(data)
linked_sequences = ''
for seq in high_acc_seqs['seq']:
    seq = seq + '0'
    linked_sequences = linked_sequences + seq
# linked_sequences<jupyter_output><empty_output><jupyter_text>figure out the max length of repeated motif<jupyter_code>def max_length(linked_sequences):
    """
    this function is the function to find the maximum 
    length of repeated motif
    
    Args:
    -----
        linked_sequences (str) -- the linked string of all sequences

    Returns:
    -----
        max_value (int) -- the maximum length of repeated motif
    """
    for i in range(4,100):
        res = meme(linked_sequences, length = i, return_max = True)
        if res > 1:
            continue
        else:
            break
    max_value = i-1
    return max_value

max_value = max_length(linked_sequences)<jupyter_output><empty_output><jupyter_text>find all repeated motif<jupyter_code>def search_all_motif(linked_sequences, max_value, amount = 30):
    """
    this function is the function to find the all repeated motifs
    
    Args:
    -----
        linked_sequences (str) -- the linked string of all sequences
        amount (int) -- the amount of return motif with highest repeat time

    Returns:
    -----
        res (list) -- the motifs with highest repeat time
    """
    res_dic = {}
    for i in range(6,max_value):
        tmp_res = meme(linked_sequences, length = i)
    #     new_res = tmp_res
        res_dic = dict(res_dic, **tmp_res)
    res_dic = sorted(res_dic.items(),key = lambda res_dic:res_dic[1],reverse=True)
    res = res_dic[:amount]
    return res

search_all_motif(linked_sequences, max_value = max_value, amount = 20)<jupyter_output><empty_output><jupyter_text>find out motif with exact length<jupyter_code>length = 6
amount = 5
meme(linked_sequences, length = length, exact_length = True, amount = amount)<jupyter_output><empty_output><jupyter_text>the searching function for the given motif we can search in the sequence and see which sequence has this motif<jupyter_code>def search_motif(seqs, motif):
    """
    this function is the meme function for a given motif 
    and search for the sequences which contains this motif
    Args:
    -----
        seqs (list) -- the original sequences list
        motif (str) -- the given motif

    Returns:
    -----
        sequences (list) -- the list of the sequences 
                            which contant the given motif
    """
    sequences=[]
    for seq in seqs:
        if motif in seq:
            sequences.append(seq)
    return sequences
search_motif(high_acc_seqs['seq'], 'GTGGGC')<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.09945217024863043, 'fraction_numerical': 0.0058997050147492625, 'mean_word_length': 2.7525691699604744, 'pattern_counts': {'":': 0, '<': 38, '<?xml version=': 0, '>': 39, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '9', 'dir': 'jupyter-structured-clean-dedup', 'id': '247262', 'license': 'MIT', 'n_tokens_mistral': 1527, 'n_tokens_neox': 1464, 'n_words': 421, 'path': 'expressyeaself/meme.ipynb', 'repo_name': 'yeastpro/expressYeaself', 'size': '4746'}