I am having two small sequences, which I search in a "long string". If both sequences are found, the key of the "long string" is appended to a list (the string I search IN is a dictionary value).
Now I am looking for a way, to acquire/calculate the distance between the two substrings (if they were found).
So, for example:
String: ABCDEFGHIJKL
sequence1: ABC
sequence2: JKL
I want to get the length of DEFGHI, which would be 6.
Here is my code for finding the substrings, with some "pseudo-codish" idea of what I want (variables start and end). This code does not work (ofc)
def search (myDict, list1, list2):
# initialize empty list to store found keys
a=[]
# iterating through dictionary
for key, value in myDict.items():
# if -35nt motif is found between -40 and -20
for item in thirtyFive:
if item in value[60:80]:
start=myDict[:item]
# it is checked for the -10nt motif from -40 to end
for item in ten:
if item in value[80:]:
end=myDict[:item]
# if both conditions are true, the IDs are
# appended to the list
a.append(key)
distance=start-end
return a, distance
Second Idea: So far, I found some stuff on how getting the string between two substrings. So, the next thing I could imagine is, to get the sequence and do sth like len(sequence).
So, I would like to know, if my first idea, to somehow do it while I am finding the small sequences, is somehow possible and, if I am thinking in the right direction with my second idea.
Thanks in advance :)
SOLUTION following @Carlos using str.find method
def search (myDict, list1, list2):
# initialize empty list to store found keys
a=[]
# iterating through dictionary
for key, value in myDict.items():
# if -35nt motif is found between -40 and -20
for item in thirtyFive:
if item in value[60:80]:
start=value.find(item)
# it is checked for the -10nt motif from -20 to end
for item in ten:
if item in value[80:]:
end=value.find(item)
# if both conditions are true, the IDs are
# appended to the list
a.append(key)
search.distance=end-start-len(item)
return a
# calling search function
x=search(d,thirtyFive,ten)
#some other things I need to print
y=len(x)
print(str(x))
print(y)
# desired output
print(search.distance)