Answers.Body: <p>Here's one way with pure Python:</p>
  
  <pre><code>#!/usr/bin/env python3
  import sys
  import re
  
  with open (sys.argv[1] , 'r') as fo:
      for line in fo:
          fields = line.split()
          if len(fields)==2:
              print(fields[1],len(fields[1].replace('-','')))
  </code></pre>
  
  <p>Running this on your file gives:</p>
  
  <pre><code>$ foo.py file.aln 
  ------------------------------------------------------------ 0
  ------------------------------------------------------------ 0
  ------------------------------------------------------------ 0
  ------------------------------------------------------------ 0
  ------------------------------------------------------------ 0
  MQWTGFRVSMTTLMMIMGVVAVLIALLPAKAQQPHDKSLRTTSTLTDTGASADEADMGSA 60
  ------------------------------------------------------------ 0
  ------------------------------------------------------------ 0
  ------------------------------------------------------------ 0
  ------------------------------------------------------------ 0
  ------------------------------------------------------------ 0
  HVELLDGDDDVGNGSDQMMVTLHLQSIFQCIRRPCEKVDRAIDPVTQRWRTANTRNDYQK 60
  ------------------MRLRVRLLKRTWPLEVPETEPTLGHLRSHLRQSLLCTWGYSS 42
  ------------------MRLRVRLLKRTWPLEVPETEPTLGHLRSRLRQSLLCTWGYSS 42
  ------------------MKLRVRLQKRTWPLDLPDAEPTLGQLRAHLSQALLPSWGFGS 42
  ------------------MKLRVRLQKRTQPLEVPESEPTLGQLRAHLSQVLLPTLGFSS 42
  ------------------MKLRVRVRKQTNRLELEAESPTLGDLRSKLSSVTLPALGYST 42
  INVCVVPAYDVSLSTGVRMKLRVKISGQKTRVDVGQDCHTLGTLRTLLAPVLGEQYGLGD 60
  NTRFTITLNYKDPLTGDEETLASYGIVSGDLICLILQDDIPA---------------PNI 45
  NTRFTITLNYKDPLTGDEETLASYGIVSGDLICLILQDDIPA---------------PNI 45
  DTRFAITLNNKDALTGDEETLASYGIVSGDLICLILEDAIPA---------------PNL 45
  DTRFAITLNNKDALTGDEETLASYGIVSGDLICLVLEDDMPA---------------PNL 45
  EANFTITLNGKDALTGDQNTLESAGIISGDLIVVVLPDSQLP---------------PPQ 45
  DMPFEISLNGRDALLGDDKPLSDLGIVSGDLIHILLASVDQPSTNHNTQQQGQHPSSPEH 60
  </code></pre>
  
  <hr>
  
  <p>Some other options:</p>
  
  <ol>
  <li><p><code>awk</code></p>
  
  <pre><code>$ awk 'NF==2{l=$2;gsub(/-/,"",$2); print l,length($2)}' file.aln 
  ------------------------------------------------------------ 0
  ------------------------------------------------------------ 0
  ------------------------------------------------------------ 0
  ------------------------------------------------------------ 0
  ------------------------------------------------------------ 0
  MQWTGFRVSMTTLMMIMGVVAVLIALLPAKAQQPHDKSLRTTSTLTDTGASADEADMGSA 60
  ------------------------------------------------------------ 0
  ------------------------------------------------------------ 0
  ------------------------------------------------------------ 0
  ------------------------------------------------------------ 0
  ------------------------------------------------------------ 0
  HVELLDGDDDVGNGSDQMMVTLHLQSIFQCIRRPCEKVDRAIDPVTQRWRTANTRNDYQK 60
  ------------------MRLRVRLLKRTWPLEVPETEPTLGHLRSHLRQSLLCTWGYSS 42
  ------------------MRLRVRLLKRTWPLEVPETEPTLGHLRSRLRQSLLCTWGYSS 42
  ------------------MKLRVRLQKRTWPLDLPDAEPTLGQLRAHLSQALLPSWGFGS 42
  ------------------MKLRVRLQKRTQPLEVPESEPTLGQLRAHLSQVLLPTLGFSS 42
  ------------------MKLRVRVRKQTNRLELEAESPTLGDLRSKLSSVTLPALGYST 42
  INVCVVPAYDVSLSTGVRMKLRVKISGQKTRVDVGQDCHTLGTLRTLLAPVLGEQYGLGD 60
  NTRFTITLNYKDPLTGDEETLASYGIVSGDLICLILQDDIPA---------------PNI 45
  NTRFTITLNYKDPLTGDEETLASYGIVSGDLICLILQDDIPA---------------PNI 45
  DTRFAITLNNKDALTGDEETLASYGIVSGDLICLILEDAIPA---------------PNL 45
  DTRFAITLNNKDALTGDEETLASYGIVSGDLICLVLEDDMPA---------------PNL 45
  EANFTITLNGKDALTGDQNTLESAGIISGDLIVVVLPDSQLP---------------PPQ 45
  DMPFEISLNGRDALLGDDKPLSDLGIVSGDLIHILLASVDQPSTNHNTQQQGQHPSSPEH 60
  </code></pre></li>
  <li><p>Perl</p>
  
  <pre><code>$ perl -lane '$l=$F[1];$l=~s/-//g; $#F==1 &amp;&amp; print "$F[1] ", length($l)' file.aln 
  ------------------------------------------------------------ 0
  ------------------------------------------------------------ 0
  ------------------------------------------------------------ 0
  ------------------------------------------------------------ 0
  ------------------------------------------------------------ 0
  MQWTGFRVSMTTLMMIMGVVAVLIALLPAKAQQPHDKSLRTTSTLTDTGASADEADMGSA 60
  ------------------------------------------------------------ 0
  ------------------------------------------------------------ 0
  ------------------------------------------------------------ 0
  ------------------------------------------------------------ 0
  ------------------------------------------------------------ 0
  HVELLDGDDDVGNGSDQMMVTLHLQSIFQCIRRPCEKVDRAIDPVTQRWRTANTRNDYQK 60
  ------------------MRLRVRLLKRTWPLEVPETEPTLGHLRSHLRQSLLCTWGYSS 42
  ------------------MRLRVRLLKRTWPLEVPETEPTLGHLRSRLRQSLLCTWGYSS 42
  ------------------MKLRVRLQKRTWPLDLPDAEPTLGQLRAHLSQALLPSWGFGS 42
  ------------------MKLRVRLQKRTQPLEVPESEPTLGQLRAHLSQVLLPTLGFSS 42
  ------------------MKLRVRVRKQTNRLELEAESPTLGDLRSKLSSVTLPALGYST 42
  INVCVVPAYDVSLSTGVRMKLRVKISGQKTRVDVGQDCHTLGTLRTLLAPVLGEQYGLGD 60
  NTRFTITLNYKDPLTGDEETLASYGIVSGDLICLILQDDIPA---------------PNI 45
  NTRFTITLNYKDPLTGDEETLASYGIVSGDLICLILQDDIPA---------------PNI 45
  DTRFAITLNNKDALTGDEETLASYGIVSGDLICLILEDAIPA---------------PNL 45
  DTRFAITLNNKDALTGDEETLASYGIVSGDLICLVLEDDMPA---------------PNL 45
  EANFTITLNGKDALTGDQNTLESAGIISGDLIVVVLPDSQLP---------------PPQ 45
  DMPFEISLNGRDALLGDDKPLSDLGIVSGDLIHILLASVDQPSTNHNTQQQGQHPSSPEH 60
  </code></pre></li>
  </ol>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-09-05T19:12:33.587Z
Answers.Text: Well ,Thankyou for this much help, it really solved my problem. Would this also work for a phylip file format?? which is ; [phylip format example] (http://scikit-bio.org/docs/0.2.3/generated/skbio.io.phylip.html)
Answers.UserDisplayName: Sidra Younas
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-09-05T19:15:15.443Z
Answers.Text: @SidraYounas I'm afraid not. This approach assumes that the lines of interest have two fields. Phylip has more. You might want to ask a new question about that.
Answers.UserDisplayName: terdon
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-09-05T19:27:11.887Z
Answers.Text: ,alright. But how come I write up these countings into the file and not just printing them out.?? As I'm working with windows and not linux system
Answers.UserDisplayName: Sidra Younas
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-09-06T05:26:57.683Z
Answers.Text: this code does not write the character numbers in my file. Do I need to use file handler to access writing permission to file??
Answers.UserDisplayName: Sidra Younas
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-09-06T09:56:41.697Z
Answers.Text: @SidraYounas yes, that's just normal python. Next time, please make sure to include all your requirements in your question so we don't need to do this sort of back and forth in the comments.
Answers.UserDisplayName: terdon
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-09-06T10:09:35.077Z
Answers.Text: I tried like this:`with open ("sample_clstl_seq.aln" , 'r') as fo:
      for line in fo:
          fields = line.split()
          if len(fields)==2:
              fo.write('{0}{1}'.format(fields[1],len(fields[1].replace('-',''))))` But errors out that it is not writeable.
Answers.UserDisplayName: Sidra Younas
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-09-06T10:10:23.087Z
Answers.Text: I understand, I will be more concerned about this matter.
Answers.UserDisplayName: Sidra Younas
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-09-07T09:40:24.537Z
Answers.Text: @SidraYounas I would not advise modifying the file directly, unless you have some good reason to. It is simpler and less risky to generate a new file and replace the original once you are sure that the result is correct.
Answers.UserDisplayName: bli
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-09-05T10:57:55.503Z
Answers.LastActivityDate: 2018-09-05T11:08:06.647Z
Answers.LastEditDate: 2018-09-05T11:08:06.647Z
Answers.UserDisplayName: terdon
Body: <p>I am using python 3 and biopython 1.72. I have been using a protein sequence file in clustal format.</p>
  
  <pre><code>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
                  :  * *:** :*.* **::.* . **:***** ::* .   .               *  
  </code></pre>
  
  <p>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:</p>
  
  <pre><code>file_var = input("File: ")
  count = 0
  with open (file_var , 'r') as fo:
      for i in fo:
          count += 1
          print (i)
      print (count)
  </code></pre>
  
  <p>But this results just counting the total number of rows in a file<code>(count variable)</code>. If I iterate over the file using biopython, it does'nt work also.</p>
  
  <pre><code>for seq_record in SeqIO.parse("sample.aln","clustal"):
      print (seq_record.id)
      print (repr(seq_record.seq))
  </code></pre>
  
  <p><strong>seq_record.id</strong> results the names of the sequences used in the file.
  <strong>repr(seq_record.seq)</strong> results the sequences of each specie alongwith description.</p>
  
  <p>While I need to</p>
  
  <ol>
  <li>get the rows only with amino acids (exclusing the symbols <code>'*,.,:'</code> line) and nothing else from the row and for each row I need to count the number of characters (exclusing <code>'-'</code> dashes)</li>
  <li>the number of characters of that row be placed at the end of each of the row.</li>
  </ol>
  
  <p>for example: for above example file, the counter should work like;</p>
  
  <pre><code>------------------------------------------------------------ 0
  MQWTGFRVSMTTLMMIMGVVAVLIALLPAKAQQPHDKSLRTTSTLTDTGASADEADMGSA 60
  ------------------MRLRVRLLKRTWPLEVPETEPTLGHLRSHLRQSLLCTWGYSS 42
  </code></pre>
  
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2018-09-05T10:37:29.843Z
Comments.Text: you can count for the character using 'length' function and before the counting character, use regular expression to remove the other character from the string.
Comments.UserDisplayName: Arijit Panda
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2018-09-05T18:16:02.940Z
Comments.Text: yes it does, but it won't do for each row separately. Thankyou for the response. :)
Comments.UserDisplayName: Sidra Younas
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2018-09-07T09:36:13.287Z
Comments.Text: I think biopython is not the right tool if you want the counts row-by-row: biopython treats the sequence of a taxon as one unit, regardless of the original layout in the alignment file.
Comments.UserDisplayName: bli
Tags: <python>
Title: Counting the characters in a row using python
ThreadText: # Counting the characters in a row using python
  
  (Asked by: username_0 on 2018-09-05)
  
  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
  
  1. 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)
  2. 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
  
  ```
  
  **Tags:** python
  
  > **Comments:**
  > **username_1**: you can count for the character using 'length' function and before the counting character, use regular expression to remove the other character from the string.  
  > **username_0**: yes it does, but it won't do for each row separately. Thankyou for the response. :)  
  > **username_2**: I think biopython is not the right tool if you want the counts row-by-row: biopython treats the sequence of a taxon as one unit, regardless of the original layout in the alignment file.  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_3 on 2018-09-05. Score: 5 | Accepted answer
  
  Here's one way with pure Python:
  
  ```
  #!/usr/bin/env python3
  import sys
  import re
  
  with open (sys.argv[1] , 'r') as fo:
      for line in fo:
          fields = line.split()
          if len(fields)==2:
              print(fields[1],len(fields[1].replace('-','')))
  
  ```
  
  Running this on your file gives:
  
  ```
  $ foo.py file.aln 
  ------------------------------------------------------------ 0
  ------------------------------------------------------------ 0
  ------------------------------------------------------------ 0
  ------------------------------------------------------------ 0
  ------------------------------------------------------------ 0
  MQWTGFRVSMTTLMMIMGVVAVLIALLPAKAQQPHDKSLRTTSTLTDTGASADEADMGSA 60
  ------------------------------------------------------------ 0
  ------------------------------------------------------------ 0
  ------------------------------------------------------------ 0
  ------------------------------------------------------------ 0
  ------------------------------------------------------------ 0
  HVELLDGDDDVGNGSDQMMVTLHLQSIFQCIRRPCEKVDRAIDPVTQRWRTANTRNDYQK 60
  ------------------MRLRVRLLKRTWPLEVPETEPTLGHLRSHLRQSLLCTWGYSS 42
  ------------------MRLRVRLLKRTWPLEVPETEPTLGHLRSRLRQSLLCTWGYSS 42
  ------------------MKLRVRLQKRTWPLDLPDAEPTLGQLRAHLSQALLPSWGFGS 42
  ------------------MKLRVRLQKRTQPLEVPESEPTLGQLRAHLSQVLLPTLGFSS 42
  ------------------MKLRVRVRKQTNRLELEAESPTLGDLRSKLSSVTLPALGYST 42
  INVCVVPAYDVSLSTGVRMKLRVKISGQKTRVDVGQDCHTLGTLRTLLAPVLGEQYGLGD 60
  NTRFTITLNYKDPLTGDEETLASYGIVSGDLICLILQDDIPA---------------PNI 45
  NTRFTITLNYKDPLTGDEETLASYGIVSGDLICLILQDDIPA---------------PNI 45
  DTRFAITLNNKDALTGDEETLASYGIVSGDLICLILEDAIPA---------------PNL 45
  DTRFAITLNNKDALTGDEETLASYGIVSGDLICLVLEDDMPA---------------PNL 45
  EANFTITLNGKDALTGDQNTLESAGIISGDLIVVVLPDSQLP---------------PPQ 45
  DMPFEISLNGRDALLGDDKPLSDLGIVSGDLIHILLASVDQPSTNHNTQQQGQHPSSPEH 60
  
  ```
  
  ---
  
  Some other options:
  
  1. `awk`
  
     ```
     $ awk 'NF==2{l=$2;gsub(/-/,"",$2); print l,length($2)}' file.aln 
     ------------------------------------------------------------ 0
     ------------------------------------------------------------ 0
     ------------------------------------------------------------ 0
     ------------------------------------------------------------ 0
     ------------------------------------------------------------ 0
     MQWTGFRVSMTTLMMIMGVVAVLIALLPAKAQQPHDKSLRTTSTLTDTGASADEADMGSA 60
     ------------------------------------------------------------ 0
     ------------------------------------------------------------ 0
     ------------------------------------------------------------ 0
     ------------------------------------------------------------ 0
     ------------------------------------------------------------ 0
     HVELLDGDDDVGNGSDQMMVTLHLQSIFQCIRRPCEKVDRAIDPVTQRWRTANTRNDYQK 60
     ------------------MRLRVRLLKRTWPLEVPETEPTLGHLRSHLRQSLLCTWGYSS 42
     ------------------MRLRVRLLKRTWPLEVPETEPTLGHLRSRLRQSLLCTWGYSS 42
     ------------------MKLRVRLQKRTWPLDLPDAEPTLGQLRAHLSQALLPSWGFGS 42
     ------------------MKLRVRLQKRTQPLEVPESEPTLGQLRAHLSQVLLPTLGFSS 42
     ------------------MKLRVRVRKQTNRLELEAESPTLGDLRSKLSSVTLPALGYST 42
     INVCVVPAYDVSLSTGVRMKLRVKISGQKTRVDVGQDCHTLGTLRTLLAPVLGEQYGLGD 60
     NTRFTITLNYKDPLTGDEETLASYGIVSGDLICLILQDDIPA---------------PNI 45
     NTRFTITLNYKDPLTGDEETLASYGIVSGDLICLILQDDIPA---------------PNI 45
     DTRFAITLNNKDALTGDEETLASYGIVSGDLICLILEDAIPA---------------PNL 45
     DTRFAITLNNKDALTGDEETLASYGIVSGDLICLVLEDDMPA---------------PNL 45
     EANFTITLNGKDALTGDQNTLESAGIISGDLIVVVLPDSQLP---------------PPQ 45
     DMPFEISLNGRDALLGDDKPLSDLGIVSGDLIHILLASVDQPSTNHNTQQQGQHPSSPEH 60
  
     ```
  2. Perl
  
     ```
     $ perl -lane '$l=$F[1];$l=~s/-//g; $#F==1 && print "$F[1] ", length($l)' file.aln 
     ------------------------------------------------------------ 0
     ------------------------------------------------------------ 0
     ------------------------------------------------------------ 0
     ------------------------------------------------------------ 0
     ------------------------------------------------------------ 0
     MQWTGFRVSMTTLMMIMGVVAVLIALLPAKAQQPHDKSLRTTSTLTDTGASADEADMGSA 60
     ------------------------------------------------------------ 0
     ------------------------------------------------------------ 0
     ------------------------------------------------------------ 0
     ------------------------------------------------------------ 0
     ------------------------------------------------------------ 0
     HVELLDGDDDVGNGSDQMMVTLHLQSIFQCIRRPCEKVDRAIDPVTQRWRTANTRNDYQK 60
     ------------------MRLRVRLLKRTWPLEVPETEPTLGHLRSHLRQSLLCTWGYSS 42
     ------------------MRLRVRLLKRTWPLEVPETEPTLGHLRSRLRQSLLCTWGYSS 42
     ------------------MKLRVRLQKRTWPLDLPDAEPTLGQLRAHLSQALLPSWGFGS 42
     ------------------MKLRVRLQKRTQPLEVPESEPTLGQLRAHLSQVLLPTLGFSS 42
     ------------------MKLRVRVRKQTNRLELEAESPTLGDLRSKLSSVTLPALGYST 42
     INVCVVPAYDVSLSTGVRMKLRVKISGQKTRVDVGQDCHTLGTLRTLLAPVLGEQYGLGD 60
     NTRFTITLNYKDPLTGDEETLASYGIVSGDLICLILQDDIPA---------------PNI 45
     NTRFTITLNYKDPLTGDEETLASYGIVSGDLICLILQDDIPA---------------PNI 45
     DTRFAITLNNKDALTGDEETLASYGIVSGDLICLILEDAIPA---------------PNL 45
     DTRFAITLNNKDALTGDEETLASYGIVSGDLICLVLEDDMPA---------------PNL 45
     EANFTITLNGKDALTGDQNTLESAGIISGDLIVVVLPDSQLP---------------PPQ 45
     DMPFEISLNGRDALLGDDKPLSDLGIVSGDLIHILLASVDQPSTNHNTQQQGQHPSSPEH 60
  
     ```
  
  > **Comments:**
  > **username_0**: Well ,Thankyou for this much help, it really solved my problem. Would this also work for a phylip file format?? which is ; [phylip format example] (http://scikit-bio.org/docs/0.2.3/generated/skbio.io.phylip.html)  
  > **username_3**: @username_0 I'm afraid not. This approach assumes that the lines of interest have two fields. Phylip has more. You might want to ask a new question about that.  
  > **username_0**: ,alright. But how come I write up these countings into the file and not just printing them out.?? As I'm working with windows and not linux system  
  > **username_0**: this code does not write the character numbers in my file. Do I need to use file handler to access writing permission to file??  
  > **username_3**: @username_0 yes, that's just normal python. Next time, please make sure to include all your requirements in your question so we don't need to do this sort of back and forth in the comments.  
  > **username_0**: I tried like this:`with open ("sample_clstl_seq.aln" , 'r') as fo:     for line in fo:         fields = line.split()         if len(fields)==2:             fo.write('{0}{1}'.format(fields[1],len(fields[1].replace('-',''))))` But errors out that it is not writeable.  
  > **username_0**: I understand, I will be more concerned about this matter.  
  > **username_2**: @username_0 I would not advise modifying the file directly, unless you have some good reason to. It is simpler and less risky to generate a new file and replace the original once you are sure that the result is correct.  
  
  ---
  
  