CmhaDSO Biopython

概要

from Bio import SeqIO

fasta_file = 'test/test.fna'
fasta = SeqIO.parse(fasta_file, 'fasta')

# SeqRecord object
r1 = next(fasta)
print(r1.id)
print(r1.description)
print(len(r1))

r1_seq = r1.seq
r1_seq[1806:2169].reverse_complement().translate()
from Bio import SeqIO

fasta_file = 'test/test.fna'
fasta = SeqIO.parse(fasta_file, 'fasta')

# 1> file全体の処理
for r in fasta:
from Bio import SeqIO

fasta_file = 'test/test.fna'

# 2> file全体の処理2
fasta = list(SeqIO.parse(fasta_file, 'fasta'))
from Bio import SeqIO

protein_fasta_file = 'test/test.faa'
output = 'tmp.faa'

fasta = SeqIO.parse(protein_fasta_file, 'fasta')
threshold = 1000

fasta = [ r for r in fasta if len(r) >= threshold]
fasta = sorted(fasta, key=len, reverse=True)

with open(output, 'w') as f:
SeqIO.write(fasta, f, 'fasta')
from Bio import SeqIO

fasta_file = 'test/test.fna'
fasta = SeqIO.parse(fasta_file, 'fasta')

f = {r.id: r for r in fasta}

print(f.keys())
print(f['NC_001140.6'])
from Bio import SeqIO
from pyfaidx import Fasta
fasta_file = 'test/test.fna'

fasta = Fasta(fasta_file)
# *.fai index fileが自動生成
# dict同様に使用可能

fasta.get_seq('NC_001140.6', 101, 200, rc=True)