Exemple #1
0
def fromgff3(filename, region=None):
    """
    Extract feature rows from a GFF3 file. 

    .. versionadded:: 0.2

    .. versionchanged:: 0.15

    A region query string of the form '[seqid]' or '[seqid]:[start]-[end]' may be given
    for the ``region`` argument. If given, requires the GFF3 file to be bgzipped and
    tabix indexed.

    """

    if region is None:

        # parse file as tab-delimited
        tbl = fromtsv(filename)

    else:

        # extract via tabix
        tbl = fromtabix(filename, region=region)

    return convertgff3(tbl)
Exemple #2
0
def fromgff3(filename):
    """
    Extract feature rows from a GFF3 file. 
    
    .. versionadded:: 0.2

    """
    
    # parse file as tab-delimited
    t0 = fromtsv(filename)
    
    # push header
    t1 = pushheader(t0, ('seqid', 'source', 'type', 'start', 'end', 'score', 'strand', 'phase', 'attributes'))

    # skip comments
    t2 = skipcomments(t1, '#')
    
    # ignore any row not 9 values long (e.g., trailing fasta)
    t3 = rowlenselect(t2, 9)
    
    # parse attributes into a dict
    t4 = convert(t3, 'attributes', gff3_parse_attributes)
    
    # parse coordinates
    t5 = convert(t4, ('start', 'end'), int)

    return HybridRowView(t5)
Exemple #3
0
def test_totsv():

    t = [('fruit', 'city', 'sales'), ('orange', 'London', '12'),
         ('banana', 'London', '42'), ('orange', 'Paris', '31'),
         ('banana', 'Amsterdam', '74'), ('kiwi', 'Berlin', '55')]

    f = NamedTemporaryFile(delete=False)
    p = totsv(f.name)
    p.push(t)

    ieq(t, fromtsv(f.name))
Exemple #4
0
def test_totsv():

    t = [('fruit', 'city', 'sales'),
         ('orange', 'London', '12'),
         ('banana', 'London', '42'),
         ('orange', 'Paris', '31'),
         ('banana', 'Amsterdam', '74'),
         ('kiwi', 'Berlin', '55')]

    f = NamedTemporaryFile(delete=False)
    p = totsv(f.name)
    p.push(t)

    iassertequal(t, fromtsv(f.name))
Exemple #5
0
def test_totsv():

    t = [
        ("fruit", "city", "sales"),
        ("orange", "London", "12"),
        ("banana", "London", "42"),
        ("orange", "Paris", "31"),
        ("banana", "Amsterdam", "74"),
        ("kiwi", "Berlin", "55"),
    ]

    f = NamedTemporaryFile(delete=False)
    p = totsv(f.name)
    p.push(t)

    ieq(t, fromtsv(f.name))