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

All Samples(710)  |  Call(708)  |  Derive(0)  |  Import(2)
Turns a sequence file into an iterator returning SeqRecords.

 - handle   - handle to the file, or the filename as a string
              (note older versions of Biopython only took a handle).
 - format   - lower case string describing the file format.
 - alphabet - optional Alphabet object, useful when the sequence type
              cannot be automatically inferred from the file itself
              (e.g. format="fasta" or "tab")

Typical usage, opening a file to read in, and looping over the record(s):(more...)

        def parse(handle, format, alphabet=None):
    r"""Turns a sequence file into an iterator returning SeqRecords.

     - handle   - handle to the file, or the filename as a string
                  (note older versions of Biopython only took a handle).
     - format   - lower case string describing the file format.
     - alphabet - optional Alphabet object, useful when the sequence type
                  cannot be automatically inferred from the file itself
                  (e.g. format="fasta" or "tab")

    Typical usage, opening a file to read in, and looping over the record(s):

    >>> from Bio import SeqIO
    >>> filename = "Fasta/sweetpea.nu"
    >>> for record in SeqIO.parse(filename, "fasta"):
    ...    print("ID %s" % record.id)
    ...    print("Sequence length %i" % len(record))
    ...    print("Sequence alphabet %s" % record.seq.alphabet)
    ID gi|3176602|gb|U78617.1|LOU78617
    Sequence length 309
    Sequence alphabet SingleLetterAlphabet()

    For file formats like FASTA where the alphabet cannot be determined, it
    may be useful to specify the alphabet explicitly:

    >>> from Bio import SeqIO
    >>> from Bio.Alphabet import generic_dna
    >>> filename = "Fasta/sweetpea.nu"
    >>> for record in SeqIO.parse(filename, "fasta", generic_dna):
    ...    print("ID %s" % record.id)
    ...    print("Sequence length %i" % len(record))
    ...    print("Sequence alphabet %s" % record.seq.alphabet)
    ID gi|3176602|gb|U78617.1|LOU78617
    Sequence length 309
    Sequence alphabet DNAAlphabet()

    If you have a string 'data' containing the file contents, you must
    first turn this into a handle in order to parse it:

    >>> data = ">Alpha\nACCGGATGTA\n>Beta\nAGGCTCGGTTA\n"
    >>> from Bio import SeqIO
    >>> try:
    ...     from StringIO import StringIO # Python 2
    ... except ImportError:
    ...     from io import StringIO # Python 3
    ...
    >>> for record in SeqIO.parse(StringIO(data), "fasta"):
    ...     print("%s %s" % (record.id, record.seq))
    Alpha ACCGGATGTA
    Beta AGGCTCGGTTA

    Use the Bio.SeqIO.read(...) function when you expect a single record
    only.
    """
    #NOTE - The above docstring has some raw \n characters needed
    #for the StringIO example, hense the whole docstring is in raw
    #string mode (see the leading r before the opening quote).
    from Bio import AlignIO

    #Hack for SFF, will need to make this more general in future
    if format in _BinaryFormats:
        mode = 'rb'
    else:
        mode = 'rU'

    #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))

    with as_handle(handle, mode) 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)
            else:
                try:
                    i = iterator_generator(fp, alphabet=alphabet)
                except TypeError:
                    i = _force_alphabet(iterator_generator(fp), alphabet)
        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)
        else:
            raise ValueError("Unknown format '%s'" % format)
        #This imposes some overhead... wait until we drop Python 2.4 to fix it
        for r in i:
            yield r
        


src/b/i/biopython-1.63/Doc/examples/fasta_dictionary.py   biopython(Download)
    return gb_name[:-2]
 
rec_iterator = SeqIO.parse("ls_orchid.fasta", "fasta", generic_dna)
orchid_dict = SeqIO.to_dict(rec_iterator, get_accession_num)
 

src/b/i/biopython-HEAD/Doc/examples/fasta_dictionary.py   biopython(Download)
    return gb_name[:-2]
 
rec_iterator = SeqIO.parse("ls_orchid.fasta", "fasta", generic_dna)
orchid_dict = SeqIO.to_dict(rec_iterator, get_accession_num)
 

src/b/i/biopython-1.63/Doc/examples/www_blast.py   biopython(Download)
 
# first get the sequence we want to parse from a FASTA file
f_record = next(SeqIO.parse('m_cold.fasta', 'fasta'))
 
print('Doing the BLAST and retrieving the results...')

src/b/i/biopython-1.63/Doc/examples/fasta_iterator.py   biopython(Download)
def extract_organisms(file_to_parse, format):
    all_species = []
    for cur_record in SeqIO.parse(open(file_to_parse), format):
        # extract the info from the description
        new_species = cur_record.description.split()[1]

src/b/i/biopython-HEAD/Doc/examples/www_blast.py   biopython(Download)
 
# first get the sequence we want to parse from a FASTA file
f_record = next(SeqIO.parse('m_cold.fasta', 'fasta'))
 
print('Doing the BLAST and retrieving the results...')

src/b/i/biopython-HEAD/Doc/examples/fasta_iterator.py   biopython(Download)
def extract_organisms(file_to_parse, format):
    all_species = []
    for cur_record in SeqIO.parse(open(file_to_parse), format):
        # extract the info from the description
        new_species = cur_record.description.split()[1]

src/e/d/edge-HEAD/example/gb2gff.py   edge(Download)
def main(gb_file):
    out_file = "%s.gff" % os.path.splitext(gb_file)[0]
    with open(out_file, "w") as out_handle:
        GFF.write(SeqIO.parse(gb_file, "genbank"), out_handle, include_fasta=True)
 

src/s/e/seqmagick-0.5.0/seqmagick/subcommands/primer_trim.py   seqmagick(Download)
    # Load the alignment
    with arguments.source_file:
        sequences = SeqIO.parse(arguments.source_file, source_format,
                alphabet=Alphabet.Gapped(Alphabet.single_letter_alphabet))
 
        # Rewind the input file
        arguments.source_file.seek(0)
        sequences = SeqIO.parse(arguments.source_file,
                source_format,
                alphabet=Alphabet.Gapped(Alphabet.single_letter_alphabet))

src/s/e/seqmagick-HEAD/seqmagick/subcommands/primer_trim.py   seqmagick(Download)
    # Load the alignment
    with arguments.source_file:
        sequences = SeqIO.parse(arguments.source_file, source_format,
                alphabet=Alphabet.Gapped(Alphabet.single_letter_alphabet))
 
        # Rewind the input file
        arguments.source_file.seek(0)
        sequences = SeqIO.parse(arguments.source_file,
                source_format,
                alphabet=Alphabet.Gapped(Alphabet.single_letter_alphabet))

src/s/e/seqmagick-0.5.0/seqmagick/subcommands/convert.py   seqmagick(Download)
    else:
        # Unsorted iterator.
        records = SeqIO.parse(source_file, source_file_type,
                alphabet=ALPHABETS.get(arguments.alphabet))
 

  1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9  Next