from Bio import SeqIO
fa_seq = SeqIO.read("bio and python练习/sequence01.fasta", "fasta")
print(fa_seq)
print('\n')
for fa in SeqIO.parse("bio and python练习/multi_sequence.fasta", "fasta"):
print (fa.seq)
print('\n')
seqs = [fa.seq for fa in SeqIO.parse("bio and python练习/multi_sequence.fasta", "fasta")]
print (seqs)
seqs = [str(fa.seq) for fa in SeqIO.parse("bio and python练习/multi_sequence.fasta", "fasta")]
print (seqs)
print('\n')
from Bio import SeqIO
fa_seq = SeqIO.read("bio and python练习/sequence01.fasta", "fasta")
print(fa_seq)
print('\n')
print ("id: ", fa_seq.id)
print ("name: ", fa_seq.name)
print ("description: ", fa_seq.description)
print ("seq: ", fa_seq.seq)
print ("dbxrefs: ", fa_seq.dbxrefs)
print ("annotations: ", fa_seq.annotations)
print ("letter_annotations: ", fa_seq.letter_annotations)
print ("features: ", fa_seq.features)
print('\n')
from Bio import SeqIO
gb_seq = SeqIO.read("bio and python练习/sequence01.gb", "genbank")
print (gb_seq)
print('\n')
print ("id: ", gb_seq.id)
print ("name: ", gb_seq.name)
print ("description: ", gb_seq.description)
print ("seq: ", gb_seq.seq)
print ("dbxrefs: ", gb_seq.dbxrefs)
print ("annotations: ", gb_seq.annotations)
print ("letter_annotations: ", gb_seq.letter_annotations)
print ("features: ", gb_seq.features)
print ("organism: ", gb_seq.annotations["organism"])
print ("comment: ", gb_seq.annotations["comment"])
print ("source: ", gb_seq.annotations["source"])
print ("taxonomy: ", gb_seq.annotations["taxonomy"])
print ("structured_comment: ", gb_seq.annotations["structured_comment"])
print ("keywords: ", gb_seq.annotations["keywords"])
print ("references: ", gb_seq.annotations["references"])
print ("accessions: ", gb_seq.annotations["accessions"])
print ("molecule_type: ", gb_seq.annotations["molecule_type"])
print ("data_file_division: ", gb_seq.annotations["data_file_division"])
print ("date: ", gb_seq.annotations["date"])
print ("sequence_version: ", gb_seq.annotations["sequence_version"])
print ("topology: ", gb_seq.annotations["topology"])
print('\n')
from Bio.Seq import Seq
from Bio.Alphabet import IUPAC
dna_seq = Seq("GGATGGTTGTCTATTAACTTGTTCAAAAAAGTATCAGGAGTTGTCAAGGCAGAGAAGAGAGTGTTTGCA", IUPAC.unambiguous_dna)
print(dna_seq)
mrna_seq = dna_seq.transcribe()
print(mrna_seq)
protein_seq = mrna_seq.translate()
print(protein_seq)
print('\n')
from Bio.Seq import Seq
from Bio.Alphabet import IUPAC
dna_seq2 = Seq("GAATGGTTGTCTATTAACTTGTTCAAAAAAGTATCAGGAGTTGTCAAGGCAGAGAAGAGAGTGTTTGCA", IUPAC.unambiguous_dna)
dna_seq_mutable = dna_seq2.tomutable()
dna_seq_mutable[0] = "T"
print(dna_seq_mutable)
print('\n')
from Bio.Seq import Seq
from Bio.Alphabet import IUPAC
dna_seq3 = Seq("TTTATGGTTGTCTATTAACTTGTTCAAAAAAGTATCAGGAGTTGTCAAGGCAGAGAAGAGAGTGTTTGCA", IUPAC.unambiguous_dna)
print ("Sequence: ", dna_seq3)
print("Length : ", len(dna_seq3))
print("G Counts: ", dna_seq3.count("G"))
print("reverse: ", dna_seq3[::-1])
print ("complement: ", dna_seq3.complement())
print ("Reverse complement: ", dna_seq3.reverse_complement())
print('\n')
from Bio.Seq import Seq
from Bio.Alphabet import IUPAC
dna_seq4= Seq("TATATGGTTGTCTATTAACTTGTTCAAAAAAGTATCAGGAGTTGTCAAGGCAGAGAAGAGAGTGTTTGCA", IUPAC.unambiguous_dna)
transcribe_seq1=dna_seq4.transcribe()
print ("rna1: ", transcribe_seq1)
transcribe_seq2 = dna_seq4.reverse_complement().transcribe()
print ("rna2: ", transcribe_seq2)
print('\n')
from Bio.Seq import Seq
from Bio.Alphabet import IUPAC
dna_seq4= Seq("TATATGGTTGTCTATTAACTTGTTCAAAAAAGTATCAGGAGTTGTCAAGGCAGAGAAGAGAGTGTTTGCA", IUPAC.unambiguous_dna)
transcribe_seq1=dna_seq4.transcribe()
print ("rna1: ", transcribe_seq1)
transcribe_seq2 = dna_seq4.reverse_complement().transcribe()
print ("rna2: ", transcribe_seq2)
print('\n')
print ("protein1: ", transcribe_seq1.translate())
print ("protein2: ", transcribe_seq1.translate(table="Vertebrate Mitochondrial"))
print ("protein3: ", transcribe_seq1.translate(table="Vertebrate Mitochondrial", to_stop=True))
print ("protein4: ", dna_seq4.translate())
print('\n')
bacterial_dna = Seq("GTGAAAAAGATGCAATCTATCGTACTCGCACTTTCCCTGGTTCTGGTCGCTCCCATGGCATAA")
print ("protein5: ", bacterial_dna.translate(table="Bacterial", to_stop=True))
print ("protein6: ", bacterial_dna.translate(table="Bacterial", cds=True))
print('\n')
from Bio.Seq import Seq
from Bio.Alphabet import IUPAC
dna_seq5= Seq("GTATATGGTTGTCTATTAACTTGTTCAAAAAAGTATCAGGAGTTGTCAAGGCAGAGAAGAGAGTGTTTGCA", IUPAC.unambiguous_dna)
print("TA Counts: ", dna_seq5.count("TA"))
print ("GC Content", format(100 * float(dna_seq5.count("G") + dna_seq5.count("C")) / len(dna_seq5),'.2f'))
def cg_content(seq):
total = len(seq)
gcCount = seq.count('G') + seq.count('C')
gcContent = format(float(gcCount / total * 100), '.6f')
return gcContent
seq=dna_seq5
cg_content_result=cg_content(seq)
print("GC Content:",cg_content_result)
print('\n')
print("Promoter seq: ",dna_seq5[:10])