Count letters in text
<p>I have text file as follows...</p>

<p>s1</p>

<blockquote>
  <p>MPPRRSIVEVKVLDVQKRRVPNKHYVYIIRVTWSSGATEAIYRRYSKFFDLQMQMLDKFP
  MEGGQKDPKQRIIPFLPGKILFRRSHIRDVAVKRLIPIDEYCKALIQLPPYISQCDEVLQ
  FFETRPEDLNPPKEEHIGKKKSGNDPTSVDPMVLEQYVVVADYQKQESSEISLSVGQVVD</p>
</blockquote>

<p>s2</p>

<blockquote>
  <p>MAEVRKFTKRLSKPGTAAELRQSVSEAVRGSVVLEKAKLVEPLDYENVITQRKTQIYSDP
  LRDLLMFPMEDISISVIGRQRRTVQSTVPEDAEKRAQSLFVKECIKTYSTDWHVVNYKYE
  DFSGDFRMLPCKSLRPEKIPNHVFEIDEDCEKDEDSSSLCSQKGGVIKQGWLHKANVNST</p>
</blockquote>

<p>.
.
.</p>

<p>I wanted to count letter 'P' in each sequences output should be </p>

<p>>
s1:10</p>

<p>>
s2:20</p>

<p>To acheive this python script as follows</p>

<pre><code>infile=open("file1.txt",'r')

out=open("file2.csv",'w')

for line in infile:

     line = line.strip("\n")

   if line.startswith('&gt;'):

        name=line

   else:

        pattern = line.count('P') 

        print '%s:%s' %(name,pattern)

        out.write('%s:%s\n' %(name,pattern))
</code></pre>

<p>it read line and gives result as follows</p>

<p>>
s1:2</p>

<p>>
s1:3</p>

<p>>
s1:5</p>

<p>>
s2:10</p>

<p>>
s2:10</p>

<p>But i except out put as follows</p>

<p>>
s1:10</p>

<p>>
s2:20
.
.
.</p>

<p>Can any body help how to do this...</p>

<p>Thanks in Advance
Ni</p>
