U
umdehoon
Hello everybody,
Say I have an array (Python array, not Numpy) that contains characters
representing a DNA sequence. Something like
Now I want to calculate the reverse complement of this sequence. I could
make a simple loop:
array('c', 'AGCAGCTAT')
But usually DNA sequences are very long, so the loop might take a long
time to finish. So I thought I would use the map function instead:
But then I am creating memory for s from scratch. So what I would really
like to do is to have a function similar to map, but have it modify the
array in place. Does such a function exist in Python?
Many thanks,
Michiel de Hoon
Human Genome Center, U Tokyo.
Say I have an array (Python array, not Numpy) that contains characters
representing a DNA sequence. Something like
Now I want to calculate the reverse complement of this sequence. I could
make a simple loop:
d = {'A': 'T', 'T': 'A', 'C': 'G', 'G': 'C'}
s.reverse()
s array('c', 'TCGTCGATA')
n = len(s)
for i in range(n): .... s = d[s]
s
array('c', 'AGCAGCTAT')
But usually DNA sequences are very long, so the loop might take a long
time to finish. So I thought I would use the map function instead:
s = map(lambda c: d[c], s)
s = array('c', s)
But then I am creating memory for s from scratch. So what I would really
like to do is to have a function similar to map, but have it modify the
array in place. Does such a function exist in Python?
Many thanks,
Michiel de Hoon
Human Genome Center, U Tokyo.