Oct-15-2016, 11:34 PM
OK,
This should do the trick. It's not the most efficient code, but you can clean it up. It works, that's the important thing.
This should do the trick. It's not the most efficient code, but you can clean it up. It works, that's the important thing.
def read_fasta(filename=None): table_dict = {} update_dict = False if filename is not None: name = '' value = '' with open(filename, 'r') as f: for line in f.readlines(): line = line.strip() if line[0] == ">": if update_dict: table_dict[name] = value value = '' name = line[1:] else: update_dict = True if len(line): value += line if len(value): table_dict[name] = value print(table_dict) if __name__ == '__main__': read_fasta('Ecoli.prot.fasta')Larz60+