I am successfully checking, if a string matches any value in a dictionary. The string is a substring of the value (if matching). Upon matching, I append the key of the value, where the substring was found, to a list.
Is there any way in python to introduce something like an if condition, to do the following:
"only append to the list, if the substring matches at position 60+ (of 100) in the value"
My code so far:
#!/usr/bin/python3
# imports
import re,sys
import itertools
# handling stdin
faFile=sys.argv[1]
pat=sys.argv[2]
pat2=sys.argv[3]
# opening .fa-File and building dictionary
with open (faFile) as f:
# reading file-content line by line
content=f.readlines()
# stripping linebreaks and >
content=[x.strip()for x in content]
content=[x.strip('>') for x in content]
# building dictionary from content
# IDs are keys, sequences are values
d=dict(itertools.zip_longest(*[iter(content)]*2, fillvalue=""))
# motif- search function
def search (myDict, search1, search2):
# initialize empty list to store found keys
search.a=[]
# iterating through dictionary
for key, value in myDict.items():
if search1 in value:
if search2 in value:
search.a.append(key)
search(d,pat,pat2)
print(search.a)
Command-line call:
./search.py file.fa pat pat2
I thought of something like introducing a counter, but couldn't figure it out yet