Sequence IO

Using Sequence IO object, we can analyze many sequences within this file
Using your text editor, write the following into a file seqio.py

import Bio
from Bio import SeqIO
import os
allSequences=[]
allSeqIDs=[]

os.getcwd()
'C:\\Users\\XXX\\Desktop\\BioPython'
pathToFile=os.path.join("C:\\Users\\XXX\\Desktop\\BioPython","test.fa")

for seq in SeqIO.parse(pathToFile,"fasta"):
        allSequences.append(seq)
        allSeqIDs.append(seq.id)
        print(seq.id)
        print(str(seq.seq))
        print(len(seq))  

If test.fa is saved under the current directory,
for seq in SeqIO.parse("test.fa","fasta"):
        allSequences.append(seq)
        allSeqIDs.append(seq.id)
        print(seq.id)
        print(str(seq.seq))
        print(len(seq))  

Then run seqio.py:
python seqio.py

NS500496_22_H2GV2BGXX:1:11101:7399:1076#TAAGGC/1
AGCCAGGCAATGGTGGTGCATGCCTTTAATCCCAGGTCTTGAGAGGAAGAGGCAGGCAGATATCTGTAAGTTTGATGCCAGCCTAGTCAATAGAGTTCCACCAAAACCAGAACTACACCAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
150
NS500496_22_H2GV2BGXX:1:11101:20246:1131#TAAGGC/1
ATGGGACCACAGTGCCAAATGGCAGGAGAAACCTGATAATCAGAGAGAGAGAGAGAGAGAGAGAGAGAGAGAGAGAGAGA
80
NS500496_22_H2GV2BGXX:1:11101:6476:1147#TAAGGC/1
ACTTTATGATATTCATCTTACATCAATAGAAAACCTTTCTGGTATTTTTTTATTTAATTAATTTTTTTAATAAAATTTTATTTAATAAATTTGGGGGGTGTGACATTAAAAATATCATGATTTAAATTAAACAAAAAAACTAACCAACAA
150
NS500496_22_H2GV2BGXX:1:11101:22871:1170#TAAGGC/1
ATGTAGTAAAACCCTGTTTGATTTATTTATTTTGAAACGAACTTGGCTGGTCTGGAACTCCTCCTGGCTCTGTCTCCTGAGAGGTGGGAATAAAGGTGTGTAGTGCCTGGCTAGAACAAAATTACAAAATTACAAAAAAAAACAAAAAAA
150
.
.
.
.

Last updated

Massachusetts Institute of Technology