Back to index

python-biopython  1.60
Classes | Functions | Variables
Bio.SeqIO.TabIO Namespace Reference

Classes

class  TabWriter

Functions

def TabIterator

Variables

tuple handle = StringIO("Alpha\tAAAAAAA\nBeta\tCCCCCCC\n\n")
tuple records = list(TabIterator(handle))

Function Documentation

def Bio.SeqIO.TabIO.TabIterator (   handle,
  alphabet = single_letter_alphabet 
)
Iterates over tab separated lines (as SeqRecord objects).

Each line of the file should contain one tab only, dividing the line
into an identifier and the full sequence.

handle - input file
alphabet - optional alphabet

The first field is taken as the record's .id and .name (regardless of
any spaces within the text) and the second field is the sequence.

Any blank lines are ignored.

Definition at line 40 of file TabIO.py.

00040 
00041 def TabIterator(handle, alphabet = single_letter_alphabet):
00042     """Iterates over tab separated lines (as SeqRecord objects).
00043 
00044     Each line of the file should contain one tab only, dividing the line
00045     into an identifier and the full sequence.
00046 
00047     handle - input file
00048     alphabet - optional alphabet
00049 
00050     The first field is taken as the record's .id and .name (regardless of
00051     any spaces within the text) and the second field is the sequence.
00052 
00053     Any blank lines are ignored.
00054     """
00055     for line in handle:
00056         try:
00057             title, seq = line.split("\t") #will fail if more than one tab!
00058         except:
00059             if line.strip() == "":
00060                 #It's a blank line, ignore it
00061                 continue
00062             raise ValueError("Each line should have one tab separating the" + \
00063                              " title and sequence, this line has %i tabs: %s" \
00064                              % (line.count("\t"), repr(line)))
00065         title = title.strip()
00066         seq = seq.strip() #removes the trailing new line
00067         yield SeqRecord(Seq(seq, alphabet),
00068                         id=title, name=title,
00069                         description="")


Variable Documentation

tuple Bio.SeqIO.TabIO.handle = StringIO("Alpha\tAAAAAAA\nBeta\tCCCCCCC\n\n")

Definition at line 99 of file TabIO.py.

Definition at line 100 of file TabIO.py.