Did I find the right examples for you? yes no      Crawl my project      Python Jobs

All Samples(52)  |  Call(52)  |  Derive(0)  |  Import(0)
Iterate over an alignment file as MultipleSeqAlignment objects.

Arguments:
 - handle    - handle to the file, or the filename as a string
               (note older versions of Biopython only took a handle).
 - format    - string describing the file format.
 - alphabet  - optional Alphabet object, useful when the sequence type
               cannot be automatically inferred from the file itself
               (e.g. fasta, phylip, clustal)
 - seq_count - Optional integer, number of sequences expected in each(more...)

        def parse(handle, format, seq_count=None, alphabet=None):
    """Iterate over an alignment file as MultipleSeqAlignment objects.

    Arguments:
     - handle    - handle to the file, or the filename as a string
                   (note older versions of Biopython only took a handle).
     - format    - string describing the file format.
     - alphabet  - optional Alphabet object, useful when the sequence type
                   cannot be automatically inferred from the file itself
                   (e.g. fasta, phylip, clustal)
     - seq_count - Optional integer, number of sequences expected in each
                   alignment.  Recommended for fasta format files.

    If you have the file name in a string 'filename', use:

    >>> from Bio import AlignIO
    >>> filename = "Emboss/needle.txt"
    >>> format = "emboss"
    >>> for alignment in AlignIO.parse(filename, format):
    ...     print("Alignment of length %i" % alignment.get_alignment_length())
    Alignment of length 124
    Alignment of length 119
    Alignment of length 120
    Alignment of length 118
    Alignment of length 125

    If you have a string 'data' containing the file contents, use:

    from Bio import AlignIO
    from StringIO import StringIO
    my_iterator = AlignIO.parse(StringIO(data), format)

    Use the Bio.AlignIO.read() function when you expect a single record only.
    """
    from Bio import SeqIO

    #Try and give helpful error messages:
    if not isinstance(format, basestring):
        raise TypeError("Need a string for the file format (lower case)")
    if not format:
        raise ValueError("Format required (lower case string)")
    if format != format.lower():
        raise ValueError("Format string '%s' should be lower case" % format)
    if alphabet is not None and not (isinstance(alphabet, Alphabet) or
                                     isinstance(alphabet, AlphabetEncoder)):
        raise ValueError("Invalid alphabet, %s" % repr(alphabet))
    if seq_count is not None and not isinstance(seq_count, int):
        raise TypeError("Need integer for seq_count (sequences per alignment)")

    with as_handle(handle, 'rU') as fp:
        #Map the file format to a sequence iterator:
        if format in _FormatToIterator:
            iterator_generator = _FormatToIterator[format]
            if alphabet is None:
                i = iterator_generator(fp, seq_count)
            else:
                try:
                    #Initially assume the optional alphabet argument is supported
                    i = iterator_generator(fp, seq_count, alphabet=alphabet)
                except TypeError:
                    #It isn't supported.
                    i = _force_alphabet(iterator_generator(fp, seq_count),
                                        alphabet)

        elif format in SeqIO._FormatToIterator:
            #Exploit the existing SeqIO parser to the dirty work!
            i = _SeqIO_to_alignment_iterator(fp, format,
                                                alphabet=alphabet,
                                                seq_count=seq_count)
        else:
            raise ValueError("Unknown format '%s'" % format)

        #This imposes some overhead... wait until we drop Python 2.4 to fix it
        for a in i:
            yield a
        


src/b/i/biopython-1.63/Bio/SeqIO/__init__.py   biopython(Download)
        elif format in AlignIO._FormatToIterator:
            #Use Bio.AlignIO to read in the alignments
            i = (r for alignment in AlignIO.parse(fp, format,
                                                  alphabet=alphabet)
                 for r in alignment)

src/b/i/biopython-HEAD/Bio/SeqIO/__init__.py   biopython(Download)
        elif format in AlignIO._FormatToIterator:
            #Use Bio.AlignIO to read in the alignments
            i = (r for alignment in AlignIO.parse(fp, format,
                                                  alphabet=alphabet)
                 for r in alignment)

src/m/a/Mapp-0.1.0/mapp/utils/alignconverter.py   Mapp(Download)
 
    input_handler = open(args.input, "rU")
    alignments = list(AlignIO.parse(input_handler, args.informat, alphabet=Gapped(IUPAC.protein)))
    input_handler.close()
 

src/b/i/bioscripts.convert-0.4/bioscripts/convert/convalign.py   bioscripts.convert(Download)
		# open & read infile
		in_hndl = open (in_path, 'rb')
		in_alns = [x for x in AlignIO.parse (in_hndl, in_fmt)]
		in_hndl.close()
		assert (in_alns), \

src/b/i/biocma-0.2.1/biocma/biocma.py   biocma(Download)
def convert(in_file, in_fmt, out_file, out_fmt):
    records = list(parse(in_file)
            if in_fmt == 'cma'
            else AlignIO.parse(in_file, in_fmt))
    if out_fmt == 'cma':

src/b/i/biopython-1.63/Tests/test_AlignIO.py   biopython(Download)
            handle.seek(0)
            try:
                alignments2 = list(AlignIO.parse(handle=handle, format=format,
                                                 seq_count=records_per_alignment))
            except ValueError as e:
            handle.seek(0)
            try:
                alignments2 = list(AlignIO.parse(handle=handle, format=format))
            except ValueError as e:
                #This is BAD.  We can't read our own output.
for t_format in AlignIO._FormatToIterator:
    handle = StringIO()
    alignments = list(AlignIO.parse(handle, t_format))
    assert len(alignments) == 0
 
 
    #Try as an iterator using handle
    alignments = list(AlignIO.parse(handle=open(t_filename, "r"), format=t_format))
    assert len(alignments) == t_count, \
         "Found %i alignments but expected %i" % (len(alignments), t_count)
    #Try using the iterator with a for loop and a filename not handle
    alignments2 = []
    for record in AlignIO.parse(t_filename, format=t_format):
        alignments2.append(record)
    assert len(alignments2) == t_count

src/b/i/biopython-HEAD/Tests/test_AlignIO.py   biopython(Download)
            handle.seek(0)
            try:
                alignments2 = list(AlignIO.parse(handle=handle, format=format,
                                                 seq_count=records_per_alignment))
            except ValueError as e:
            handle.seek(0)
            try:
                alignments2 = list(AlignIO.parse(handle=handle, format=format))
            except ValueError as e:
                #This is BAD.  We can't read our own output.
for t_format in AlignIO._FormatToIterator:
    handle = StringIO()
    alignments = list(AlignIO.parse(handle, t_format))
    assert len(alignments) == 0
 
    #Try as an iterator using handle
    with open(t_filename, "r") as handle:
        alignments = list(AlignIO.parse(handle, format=t_format))
    assert len(alignments) == t_count, \
         "Found %i alignments but expected %i" % (len(alignments), t_count)
    #Try using the iterator with a for loop and a filename not handle
    alignments2 = []
    for record in AlignIO.parse(t_filename, format=t_format):
        alignments2.append(record)
    assert len(alignments2) == t_count

src/b/i/bio-MOSAIC-1.0/mosaic.py   bio-MOSAIC(Download)
 
    if status == 0:
        result = AlignIO.parse(outfile, 'fasta')
        alignmentobj = result.next()
        outfile.close()

src/b/i/biopython-1.63/Tests/test_AlignIO_FastaIO.py   biopython(Download)
 
    #Try as an iterator using handle
    alignments = list(AlignIO.parse(handle=open(t_filename, "r"), format=t_format))
    assert len(alignments) == t_count, \
         "Found %i alignments but expected %i" % (len(alignments), t_count)

src/b/i/biopython-1.63/Tests/test_AlignIO_convert.py   biopython(Download)
def check_convert(in_filename, in_format, out_format, alphabet=None):
    #Write it out using parse/write
    handle = StringIO()
    aligns = list(AlignIO.parse(open(in_filename), in_format, None, alphabet))
    try:

  1 | 2  Next