I got this function to looking for some specific characters in a string and if it is found it add a value at that position in the array, ex:
def skew_array(text):
import numpy as np
skew = np.zeros(len(text))
for i in range(0, len(text)):
if text[i] == 'G':
skew[i] += 1
elif text[i] == 'C':
skew[i] -= 1
else:
skew[i] = 0
return np.insert(skew, 0, 0)
>> skew_array('gacaattagcaa'.upper())
array([ 0., 1., 0., -1., 0., 0., 0., 0., 0., 1., -1., 0., 0.])
I am not sure if it is the right way to do it (inserting at the end) or if there are a way just to keep the first position as zero when creating the array.
I appreciate any tip! Thank you by your time.
PS - I was using a list, but it is very bad for memory in bigger strings!