I am using python 3 and biopython 1.72. I have been using a protein sequence file in clustal format.
CLUSTAL 2.1 multiple sequence alignment
Human ------------------------------------------------------------
Chimpanzee ------------------------------------------------------------
Dog ------------------------------------------------------------
Mouse ------------------------------------------------------------
Xenopus ------------------------------------------------------------
Amphioxus MQWTGFRVSMTTLMMIMGVVAVLIALLPAKAQQPHDKSLRTTSTLTDTGASADEADMGSA
Human ------------------------------------------------------------
Chimpanzee ------------------------------------------------------------
Dog ------------------------------------------------------------
Mouse ------------------------------------------------------------
Xenopus ------------------------------------------------------------
Amphioxus HVELLDGDDDVGNGSDQMMVTLHLQSIFQCIRRPCEKVDRAIDPVTQRWRTANTRNDYQK
Human ------------------MRLRVRLLKRTWPLEVPETEPTLGHLRSHLRQSLLCTWGYSS
Chimpanzee ------------------MRLRVRLLKRTWPLEVPETEPTLGHLRSRLRQSLLCTWGYSS
Dog ------------------MKLRVRLQKRTWPLDLPDAEPTLGQLRAHLSQALLPSWGFGS
Mouse ------------------MKLRVRLQKRTQPLEVPESEPTLGQLRAHLSQVLLPTLGFSS
Xenopus ------------------MKLRVRVRKQTNRLELEAESPTLGDLRSKLSSVTLPALGYST
Amphioxus INVCVVPAYDVSLSTGVRMKLRVKISGQKTRVDVGQDCHTLGTLRTLLAPVLGEQYGLGD
*:***:: :. ::: *** **: * * .
Human NTRFTITLNYKDPLTGDEETLASYGIVSGDLICLILQDDIPA---------------PNI
Chimpanzee NTRFTITLNYKDPLTGDEETLASYGIVSGDLICLILQDDIPA---------------PNI
Dog DTRFAITLNNKDALTGDEETLASYGIVSGDLICLILEDAIPA---------------PNL
Mouse DTRFAITLNNKDALTGDEETLASYGIVSGDLICLVLEDDMPA---------------PNL
Xenopus EANFTITLNGKDALTGDQNTLESAGIISGDLIVVVLPDSQLP---------------PPQ
Amphioxus DMPFEISLNGRDALLGDDKPLSDLGIVSGDLIHILLASVDQPSTNHNTQQQGQHPSSPEH
: * *:** :*.* **::.* . **:***** ::* . . *
I need to iterate over the rows of my file so that I could count the occurrence of characters in each row. I tried using the code:
file_var = input("File: ")
count = 0
with open (file_var , 'r') as fo:
for i in fo:
count += 1
print (i)
print (count)
But this results just counting the total number of rows in a file(count variable)
. If I iterate over the file using biopython, it does'nt work also.
for seq_record in SeqIO.parse("sample.aln","clustal"):
print (seq_record.id)
print (repr(seq_record.seq))
seq_record.id results the names of the sequences used in the file. repr(seq_record.seq) results the sequences of each specie alongwith description.
While I need to
- get the rows only with amino acids (exclusing the symbols
'*,.,:'
line) and nothing else from the row and for each row I need to count the number of characters (exclusing'-'
dashes) - the number of characters of that row be placed at the end of each of the row.
for example: for above example file, the counter should work like;
------------------------------------------------------------ 0
MQWTGFRVSMTTLMMIMGVVAVLIALLPAKAQQPHDKSLRTTSTLTDTGASADEADMGSA 60
------------------MRLRVRLLKRTWPLEVPETEPTLGHLRSHLRQSLLCTWGYSS 42