Bio.SeqIO.FastaIO模块
Bio.SeqIO支持“fasta”(又名FastA或Pearson)文件格式。
您需要通过Bio.SeqIO功能使用此模块。
- Bio.SeqIO.FastaIO.SimpleFastaParser(handle)
将Fasta记录作为字符串二元组进行迭代。
- 论点:
手柄-以文本模式打开的输入流
对于每个记录,返回一个由两个字符串组成的元组,FASTA标题行(没有前导“>”字符)和序列(删除了任何空格)。标题行不分为标识符(第一个单词)和注释或描述。
>>> with open("Fasta/dups.fasta") as handle: ... for values in SimpleFastaParser(handle): ... print(values) ... ('alpha', 'ACGTA') ('beta', 'CGTC') ('gamma', 'CCGCC') ('alpha (again - this is a duplicate entry to test the indexing code)', 'ACGTA') ('delta', 'CGCGC')
- Bio.SeqIO.FastaIO.FastaTwoLineParser(handle)
将无包装Fasta记录作为字符串元组进行迭代。
- 论点:
手柄-以文本模式打开的输入流
功能与SimpleFastaParser相同,但对FASTA格式进行了严格的解释,即每条记录恰好有两行,具有描述的比符号更短的标识符,以及没有行绕转的序列。
任何换行都将引发异常,多余的空行也会引发异常(零长度序列作为记录的第二行的特殊情况除外)。
示例
此文件每个FASTA记录使用两行:
>>> with open("Fasta/aster_no_wrap.pro") as handle: ... for title, seq in FastaTwoLineParser(handle): ... print("%s = %s..." % (title, seq[:3])) ... gi|3298468|dbj|BAA31520.1| SAMIPF = GGH...
这个等效文件使用行包装:
>>> with open("Fasta/aster.pro") as handle: ... for title, seq in FastaTwoLineParser(handle): ... print("%s = %s..." % (title, seq[:3])) ... Traceback (most recent call last): ... ValueError: Expected FASTA record starting with '>' character. Perhaps this file is using FASTA line wrapping? Got: 'MTFGLVYTVYATAIDPKKGSLGTIAPIAIGFIVGANI'
- class Bio.SeqIO.FastaIO.FastaIterator(source: IO[str] | PathLike | str | bytes, alphabet: None = None)
-
没有注释的纯Fasta文件的解析器。
- modes = 't'
- __init__(source: IO[str] | PathLike | str | bytes, alphabet: None = None) None
将Fasta记录作为SeqRecord对象进行迭代。
- 论点:
源-以文本模式打开的输入流,或文件的路径
字母表-可选字母表,未使用。离开为无。
此解析器需要没有注释或标题行的纯Fasta格式。
默认情况下,这将类似于调用Bio.SeqIO.parse(handle,“fasta”),而不对标题行进行自定义处理:
>>> with open("Fasta/dups.fasta") as handle: ... for record in FastaIterator(handle): ... print(record.id) ... alpha beta gamma alpha delta
如果您想在写入前修改记录,例如更改每条记录的ID,您可以使用如下生成器函数:
>>> def modify_records(records): ... for record in records: ... record.id = record.id.upper() ... yield record ... >>> with open('Fasta/dups.fasta') as handle: ... for record in modify_records(FastaIterator(handle)): ... print(record.id) ... ALPHA BETA GAMMA ALPHA DELTA
- __next__()
返回下一个SeqRecord。
此方法必须由子类实现。
- __abstractmethods__ = frozenset({})
- __annotations__ = {}
- __firstlineno__ = 143
- __parameters__ = ()
- __static_attributes__ = ('_line',)
- class Bio.SeqIO.FastaIO.FastaTwoLineIterator(source)
-
Fasta文件的解析器每条记录正好有两行。
- modes = 't'
- __init__(source)
迭代两行Fasta记录(作为SeqRecord对象)。
- 论点:
源-以文本模式打开的输入流,或文件的路径
这使用了对FASTA的严格解释,即每个记录只需要两行(没有行包裹)。
仅提供宽松FASTA解析器提供的ID/名称/描述解析的默认标题。
- __next__()
返回下一个SeqRecord。
此方法必须由子类实现。
- __abstractmethods__ = frozenset({})
- __annotations__ = {}
- __firstlineno__ = 268
- __parameters__ = ()
- __static_attributes__ = ('_data',)
- class Bio.SeqIO.FastaIO.FastaBlastIterator(source: IO[str] | PathLike | str | bytes, alphabet: None = None)
-
Fasta文件的解析器,允许像在BLAST中那样的注释。
- modes = 't'
- __init__(source: IO[str] | PathLike | str | bytes, alphabet: None = None) None
将Fasta记录作为SeqRecord对象进行迭代。
- 论点:
源-以文本模式打开的输入流,或文件的路径
字母表-可选字母表,未使用。离开为无。
这个解析器希望数据是FASTA格式的。就像在BLAST中一样,以#开头的行,!"或“;”被解释为注释并被忽略。
此迭代器的作用就像调用Bio.SeqIO.parse(handle,“fasta-blast”),而不对标题行进行自定义处理:
>>> with open("Fasta/dups.fasta") as handle: ... for record in FastaIterator(handle): ... print(record.id) ... alpha beta gamma alpha delta
如果您想在写入前修改记录,例如更改每条记录的ID,您可以使用如下生成器函数:
>>> def modify_records(records): ... for record in records: ... record.id = record.id.upper() ... yield record ... >>> with open('Fasta/dups.fasta') as handle: ... for record in modify_records(FastaIterator(handle)): ... print(record.id) ... ALPHA BETA GAMMA ALPHA DELTA
- __next__()
返回下一个SeqRecord。
此方法必须由子类实现。
- __abstractmethods__ = frozenset({})
- __annotations__ = {}
- __firstlineno__ = 304
- __parameters__ = ()
- __static_attributes__ = ('_line',)
- class Bio.SeqIO.FastaIO.FastaPearsonIterator(source: IO[str] | PathLike | str | bytes, alphabet: None = None)
-
Fasta文件的解析器,允许像FASTA对齐器中那样进行评论。
- modes = 't'
- __init__(source: IO[str] | PathLike | str | bytes, alphabet: None = None) None
将Fasta记录作为SeqRecord对象进行迭代。
- 论点:
源-以文本模式打开的输入流,或文件的路径
字母表-可选字母表,未使用。离开为无。
该解析器期望Fasta格式,允许标题(在第一个序列记录之前)和注释(以“”开头的行),就像William Pearson的FASTA对齐器软件中一样。
此迭代器相当于调用Bio.SeqIO.parse(handle,“fasta-pearson”),不对标题行进行自定义处理:
>>> with open("Fasta/dups.fasta") as handle: ... for record in FastaIterator(handle): ... print(record.id) ... alpha beta gamma alpha delta
如果您想在写入前修改记录,例如更改每条记录的ID,您可以使用如下生成器函数:
>>> def modify_records(records): ... for record in records: ... record.id = record.id.upper() ... yield record ... >>> with open('Fasta/dups.fasta') as handle: ... for record in modify_records(FastaIterator(handle)): ... print(record.id) ... ALPHA BETA GAMMA ALPHA DELTA
- __next__()
返回下一个SeqRecord。
此方法必须由子类实现。
- __abstractmethods__ = frozenset({})
- __annotations__ = {}
- __firstlineno__ = 403
- __parameters__ = ()
- __static_attributes__ = ('_line',)
- class Bio.SeqIO.FastaIO.FastaWriter(target, wrap=60, record2title=None)
-
编写Fasta格式文件(ObSOSYS)的类。
请使用
as_fasta
功能相反,或顶级Bio.SeqIO.write()
函数改为使用format="fasta"
.- modes = 't'
- __init__(target, wrap=60, record2title=None)
创建一名Fasta作家(ObSOSYS)。
- 论点:
target -以文本模式打开的输出流,或文件的路径。
包裹- 用于包裹序列行的可选行长度。将序列包装为60个字符使用零(或无)表示不包装,为序列提供一条长行。
record 2 title-可选函数,用于返回用于每条记录标题行的文本。 默认情况下,使用record.id和record. advantage的组合。 如果record. advantage以record.id开头,则仅使用record. advantage。
您可以用途::
handle = open(filename, "w") writer = FastaWriter(handle) writer.write_file(myRecords) handle.close()
或者,遵循顺序文件写入器系统,例如:
handle = open(filename, "w") writer = FastaWriter(handle) ... Multiple writer.write_record() and/or writer.write_records() calls ... handle.close()
- write_record(record)
将单个Fasta记录写入文件。
- __abstractmethods__ = frozenset({})
- __annotations__ = {}
- __firstlineno__ = 495
- __parameters__ = ()
- __static_attributes__ = ('record2title', 'wrap')
- class Bio.SeqIO.FastaIO.FastaTwoLineWriter(handle, record2title=None)
基类:
FastaWriter
类来编写每条记录2行的Fasta格式文件(OBSOSTO)。
这意味着我们在不进行行绕转的情况下编写序列信息,并且始终为空序列写入一行。
请使用
as_fasta_2line
功能相反,或顶级Bio.SeqIO.write()
函数改为使用format="fasta"
.- __init__(handle, record2title=None)
创建一个每条记录2行的Fasta writer(ObSOSYS)。
- 论点:
handle -输出文件的Handle,例如,打开返回的(文件名,“w”)
record 2 title-可选函数,用于返回用于每条记录标题行的文本。 默认情况下,使用record.id和record. advantage的组合。 如果record. advantage以record.id开头,则仅使用record. advantage。
您可以用途::
handle = open(filename, "w") writer = FastaWriter(handle) writer.write_file(myRecords) handle.close()
或者,遵循顺序文件写入器系统,例如:
handle = open(filename, "w") writer = FastaWriter(handle) ... Multiple writer.write_record() and/or writer.write_records() calls ... handle.close()
- __abstractmethods__ = frozenset({})
- __annotations__ = {}
- __firstlineno__ = 574
- __parameters__ = ()
- __static_attributes__ = ()
- Bio.SeqIO.FastaIO.as_fasta(record)
将SeqRecord转换为FASTA格式的字符串。
SeqRecord的. form(“fasta”)方法和SeqIO. writer(.,...,“fasta”)功能。
- Bio.SeqIO.FastaIO.as_fasta_2line(record)
将SeqRecord转换为两行FASTA格式的字符串。
SeqRecord的. form(“fasta-2line”)方法和SeqIO. writer(.,...,“fasta-2line”)功能。