# ---
# jupyter:
#   jupytext:
#     text_representation:
#       extension: .py
#       format_name: light
#       format_version: '1.5'
#       jupytext_version: 1.14.4
#   kernelspec:
#     display_name: Python 3
#     language: python
#     name: python3
# ---

# ## Create function to count kmers 

import pandas as pd 


# +
def kmer_counter(sequence, kmer_length):
    sequence_length=len(sequence)
    number_of_kmers=((sequence_length-kmer_length)+1)
    
    kmer_counts_dict={}
    
    for i in range(number_of_kmers):
        kmer=sequence[i:(i+kmer_length)]
        if kmer in kmer_counts_dict: # here we could use kmer_counts_dict.keys() also
            kmer_counts_dict[kmer]+=1
        else:
            kmer_counts_dict[kmer]=1
    return kmer_counts_dict

kmer_example2=kmer_counter("AAAAAAAAAGGGGGGGAAAAAAAAAGGG", 4)

kmer_example2
# -

# ### Make a dictionary of VO guide name and seq key value pairs.
#

# +

VO_2016_guides=pd.read_csv("VO_guides_2016.csv")
VO_2016_guides_cleaned=VO_2016_guides.drop(VO_2016_guides.index[96:1475])
spacer_name=list(VO_2016_guides_cleaned['Spacer '])
spacer_seq=list(VO_2016_guides_cleaned['Spacer sequence'])
VO_Guide_dictionary=dict(zip(spacer_name, spacer_seq))
print(VO_Guide_dictionary)
# -

# ### make a dictionary of VO guide kmers 
# with key=(guide_name,seq) value=kmer count dictionary 

# +
VO_2016_kmers={}

for seq_id, sequence in VO_Guide_dictionary.items():
    seq_kmer=kmer_counter(sequence, 4)
    VO_2016_kmers[(seq_id,sequence)]=seq_kmer

print(VO_2016_kmers)
# -



StarcoderdataJupyterScriptsDedupFiltered