Python: indexing letters of string in a list
<p>I would like to ask if there is a way how to get exact letters of some string stored in a list? I'm working with DNA strings, get them from FASTA file using BioPython SeqIO and store them as strings in a list. In next step I will convert it to numerical sequence (called genomic signals). But as novice in Python I don't know how to obtain it from the list correctly. Should I use different data type?</p>

<p>In Maltab I used: </p>

<pre><code>a=1+1i;c=-1-1i;g=-1+1i;t=1-1i; %base values definition
for i=1:number of sequences
    length_of_sequence(i)=length(sequence{1,i});
    temp=zeros(1,length_of_sequence(i),'double');
    temp(sequence{i}=='A')=angle(a);
    temp(sequence{i}=='C')=angle(c);
    temp(sequence{i}=='G')=angle(g);
    temp(sequence{i}=='T')=angle(t);    
    KontigNumS{i,1}=cumsum(temp); %cumulated phase of whole vector
end
</code></pre>

<p>what creates a vector and replace zeros with according values. 
I wasn't able to find a similar question. Thanks for replies. </p>

<p>My python code:</p>

<pre><code>#Dependencies
from Bio import SeqIO #fasta loading
import cmath #complex numbers
import numpy as np 

#Open FASTA file new variable
lengths=list()
sequences=list()
handle=open("F:\GC_Assembler_Python\xx.fasta","r")
for record in SeqIO.parse(handle, "fasta"):
    print(record.id)
    print(len(record.seq))
    lengths.append(len(record.seq))
    sequences.append(str(record.seq))

#Convert to genomic signals
a=complex(1,1)
c=complex(-1,-1)
g=complex(-1,1)
t=complex(1,-1)
I stopped here. 
</code></pre>

<p>I don't know how MATLAB does it. In Python you can access any position in a string without converting to a list:</p>

<pre><code>DNA = "ACGTACGTACGT"
print(DNA[2])
# outputs "G", the third base
</code></pre>

<p>If you want to store "strings in a list" you can do this:</p>

<pre><code>DNA_list = ["AAAAAA", "CCCCC", "GGGGG", "TTTTT"]
print(DNA_list[0][0])
# outputs "A", the first "A" of the first sequence
print(DNA_list[1][0])
# outputs "C", the first "C" of the second sequence
</code></pre>

python biopython