Created
January 11, 2020 01:58
-
-
Save kounkou/4741aabbd8e32c51854b82bd4b1ca70a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import math | |
read_lin = 4 | |
read_len = 16 | |
def allindices(string, sub, listindex=[], offset=0): | |
i = string.find(sub, offset) | |
while i >= 0: | |
listindex.append(i) | |
i = string.find(sub, i + 1) | |
return listindex | |
def search(kmer): | |
with open('reads.fa') as f: | |
results = [] | |
cont = f.read() | |
print('kmer : ', kmer) | |
results = allindices(cont, kmer) | |
f.close() | |
print('indices : ', results) | |
reads = [ math.floor(x / (read_len + 1)) for x in results ] | |
reads.sort(reverse = False) | |
reads = list(dict.fromkeys(reads)) | |
print('reads : ', reads) | |
temp = [] | |
for x in reads: | |
if x >= int(read_lin / 2): | |
temp.append(int(x / (read_lin / 2))) | |
else: | |
temp.append(x) | |
temp.sort(reverse = False) | |
temp = list(dict.fromkeys(temp)) | |
print('results : ', len(temp)) | |
results.clear() | |
reads.clear() | |
if __name__ == '__main__': | |
kmers = [ 'jacques' ] | |
for kmer in kmers: | |
search(kmer) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment