File: seqparse.py

package info (click to toggle)
python-screed 1.1.3-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 820 kB
  • sloc: python: 3,356; makefile: 169; sh: 32; javascript: 16
file content (63 lines) | stat: -rw-r--r-- 1,622 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# Copyright (c) 2008, Michigan State University.

"""
seqparse contains custom sequence parsers for extending screed's
functionality to arbitrary sequence formats. An example 'hava'
parser is included for API reference
"""

from __future__ import absolute_import

import os

from .createscreed import create_db
from .openscreed import ScreedDB
from . import openscreed
from . import fastq
from . import fasta
from . import hava

# [AN] these functions look strangely similar


def read_fastq_sequences(filename):
    """
    Function to parse text from the given FASTQ file into a screed database
    """
    # Will raise an exception if the file doesn't exist
    iterfunc = openscreed.Open(filename, parse_description=True)

    # Create the screed db
    create_db(filename, fastq.FieldTypes, iterfunc)

    return ScreedDB(filename)


def read_fasta_sequences(filename):
    """
    Function to parse text from the given FASTA file into a screed database
    """
    # Will raise an exception if the file doesn't exist
    iterfunc = openscreed.Open(filename, parse_description=True)

    # Create the screed db
    create_db(filename, fasta.FieldTypes, iterfunc)

    return ScreedDB(filename)


def read_hava_sequences(filename):
    """
    Function to parse text from the given HAVA file into a screed database
    """
    # Will raise an exception if the file doesn't exist
    theFile = open(filename, "rb")

    # Setup the iterator function
    iterfunc = hava.hava_iter(theFile)

    # Create the screed db
    create_db(filename, hava.FieldTypes, iterfunc)
    theFile.close()

    return ScreedDB(filename)