# MSU FBB. Bioinformatics. Term 1. Block 2. Practice 7. Task 2. 
# From_fasta_to_fasta v2.3                                            
# Author: Lozinskiy.Y.N.                                              
# Last modification date: 26.10.2013 14:16
                             
class Protein:                                                        
    ID = ""                                                           
    description = ""                                                  
    sequence = ""                                                     
    def __init__(self,i,d,s):                                         
        self.ID = i                                                   
        self.description = d                                          
        self.sequence = s                                             
    def print_fasta (self,z):                                         
        new_line = ""                                                 
        a = 1                                                         
        for el in range(len(self.sequence)):                          
            if a < int(z):                                            
               new_line = new_line + self.sequence[el]                
               a += 1                                                 
            else:                                                     
               new_line = new_line + self.sequence[el]+"\n"           
               a = 1                                                  
        print ">" + self.ID + " " + self.description                  
        print new_line
                                                 
fasta = "NC_000854.faa"             #you should write here a name of your fasta file                                   
op_fasta = open(fasta)                                                
description = ""                                                      
protein_list = list()                                                 
save_ID = ""                                                          
save_description = ""                                                 
save_sequence = ""                                                    
protein = ""                                                          
number = raw_input (" Please enter a number of letters in a line: \n")
 
for line in op_fasta:                                                 
    new_line=line.strip("\n")                                         
    new_line=new_line.strip("\r")                                     
    if len(new_line.strip()) == 0:                                      
        continue                                                      
    if new_line[0] == ">":                                            
        if (save_ID != "") and (save_description != "") :             
            protein = Protein(save_ID, save_description, save_sequence)
            protein_list.append(protein)                                
            save_sequence = ""                                        
        new_line = new_line.split(None,1)                             
        save_ID = new_line[0].strip(">")                              
        if len(new_line[1]) > 0:                                      
            save_description = new_line[1].replace("  ","")           
        else:                                                         
            save_description = "None"                                                                                       
    else:                                                             
        new_line = new_line.replace(" ","")                           
        save_sequence = save_sequence + new_line                      
     
protein = Protein(save_ID, save_description, save_sequence)           
protein_list.append(protein)