""" Routines to convert files and objects from a format to another """
[docs]defconvert_gbk_to_faa(gbk_input_filename,faa_output_filename):""" A function to convert a .gbk file returned from the RAST annotation to a .faa that can be used with ModelSEEDpy """fromBioimportSeqIOinput_handle=open(gbk_input_filename,"r")output_handle=open(faa_output_filename,"w")forseq_recordinSeqIO.parse(input_handle,"genbank"):print("Dealing with GenBank record %s"%seq_record.id)forentryinseq_record.features:ifentry.type=="CDS":cds_dict=dict(entry.qualifiers)output_handle.write(">%s%s\n%s\n"%(cds_dict["db_xref"][0],cds_dict["product"][0],cds_dict["translation"][0],))output_handle.close()input_handle.close()return0