next up previous contents index
Next: alignment.check_structure_structure() check Up: The alignment class: comparison Previous: alignment.clear() delete   Contents   Index

alignment.read_one() -- read sequences one by one from a file

read_one(file, remove_gaps=False, alignment_format='PIR', io=None, allow_alternates=False)
Output:
True only if a sequence was read

This reads a single sequence from an open alignment file into the current alignment. This is useful, for example, when dealing with a very large database of sequences, which you do not want to read into memory in its entirety. The sequences can then be processed individually.

On exit, True is returned if a sequence was read. The read sequence is the only sequence in the final alignment (anything in the alignment before calling this method is erased). If the end of the file was reached without reading a sequence, False is returned.

Arguments are as for alignment.append(). Note that only 'PIR' or 'FASTA' format files can be read with this command. file should be an open file handle (see modfile.File()). Since only a single sequence is read, if remove_gaps is True, all gaps in the sequence are removed, regardless of whether they are aligned with other sequences in the alignment file.

This command can raise a FileFormatError if the alignment file format is invalid, or a SequenceMismatchError if a 'PIR' sequence does not match that read from PDB (when an empty range is given).
Example: examples/commands/alignment_read_one.py


# Example for: alignment.read_one()

from modeller import *
env = environ()

# Create an empty alignment
aln = alignment(env)

# Open the input alignment file, and get a handle to it:
input = modfile.File('toxin.ali', 'r')
# Same for the output file:
output = modfile.File('toxin-filter.ali', 'w')

# Read sequences one by one from the file handle in PIR format:
while aln.read_one(input, alignment_format='PIR'):
    print "Read code %s" % aln[0].code
    # Write only X-ray structures to the output file:
    if aln[0].prottyp == 'structureX':
        aln.write(output, alignment_format='FASTA')

# Explicitly close the files (not strictly necessary in this simple
# example, because they'll be closed at the end of the script anyway):
input.close()
output.close()


next up previous contents index
Next: alignment.check_structure_structure() check Up: The alignment class: comparison Previous: alignment.clear() delete   Contents   Index
Automatic builds 2011-03-29