def write_fasta_file_from_dict(indict, outname, outdir=None, outext='.faa', force_rerun=False):
"""Write a FASTA file for a dictionary of IDs and their sequence strings.
Args:
indict: Input dictionary with keys as IDs and values as sequence strings
outname: Name of the output file which will have outext appended to it
outdir: Path to directory to output sequences to
outext: Extension of FASTA file, default ".faa"
force_rerun: If file should be overwritten if it exists
Returns:
str: Path to output FASTA file.
"""
if not outdir:
outdir = ''
outfile = ssbio.utils.outfile_maker(inname='', outname=outname, outdir=outdir, outext=outext)
if ssbio.utils.force_rerun(flag=force_rerun, outfile=outfile):
seqs = []
for i, s in indict.items():
seq = ssbio.protein.sequence.utils.cast_to_seq_record(s, id=i)
seqs.append(seq)
SeqIO.write(seqs, outfile, "fasta")
return outfile
评论列表
文章目录