Exemplo n.º 1
0
 def test_default(self):
     """Default FieldWrapper should wrap fields and labels"""
     fields = list('abcde')
     f = FieldWrapper(fields)
     self.assertEqual(f(''), {})
     self.assertEqual(f('xy za '), {'a': 'xy', 'b': 'za'})
     self.assertEqual(f('1   2\t\t 3  \n4 5 6'), \
         {'a':'1','b':'2','c':'3','d':'4','e':'5'})
Exemplo n.º 2
0
 def test_splitter(self):
     """FieldWrapper with splitter should use that splitter"""
     fields = ['label', 'count']
     splitter = DelimitedSplitter(':', -1)
     f = FieldWrapper(fields, splitter)
     self.assertEqual(f(''), {})
     self.assertEqual(f('nknasd:'), {'label': 'nknasd', 'count': ''})
     self.assertEqual(f('n:k:n:a:sd  '), {
         'label': 'n:k:n:a',
         'count': 'sd'
     })
Exemplo n.º 3
0
__maintainer__ = "Rob Knight"
__email__ = "*****@*****.**"
__status__ = "Production"

all_chars = maketrans('', '')
dna_lc = 'utacgrywsmkbdhvn'
dna_lc_cmp = 'aatgcyrwskmvhdbn'
dna_trans = maketrans(dna_lc + dna_lc.upper(), dna_lc_cmp + dna_lc_cmp.upper())
rna_lc = 'utacgrywsmkbdhvn'
rna_lc_cmp = 'aaugcyrwskmvhdbn'
rna_trans = maketrans(rna_lc + rna_lc.upper(), rna_lc_cmp + rna_lc_cmp.upper())

locus_fields = [
    None, 'locus', 'length', None, 'mol_type', 'topology', 'db', 'date'
]
_locus_parser = FieldWrapper(locus_fields)

#need to turn off line stripping, because whitespace is significant
GbFinder = DelimitedRecordFinder('//', constructor=rstrip)


class PartialRecordError(Exception):
    pass


def parse_locus(line):
    """Parses a locus line, including conversion of Length to an int.
    
    WARNING: Gives incorrect results on legacy records that omit the topology. 
    All records spot-checked on 8/30/05 had been updated to include the topology
    even when prior versions omitted it.
Exemplo n.º 4
0
__version__ = "1.5.3"
__maintainer__ = "Rob Knight"
__email__ = "*****@*****.**"
__status__ = "Development"

def ll_start(line):
    """Returns True if line looks like the start of a LocusLink record."""
    return line.startswith('>>')
LLFinder = LabeledRecordFinder(ll_start)

pipes = DelimitedSplitter('|', None)
first_pipe = DelimitedSplitter('|')
commas = DelimitedSplitter(',', None)
first_colon = DelimitedSplitter(':', 1)

accession_wrapper = FieldWrapper(['Accession', 'Gi', 'Strain'], pipes)
def _read_accession(line):
    """Reads accession lines: format is Accession | Gi | Strain."""
    return MappedRecord(accession_wrapper(line))

rell_wrapper = FieldWrapper(['Description', 'Id', 'IdType', 'Printable'], pipes)
def _read_rell(line):
    """Reads RELL lines: format is Description|Id|IdType|Printable"""
    return MappedRecord(rell_wrapper(line))

accnum_wrapper = FieldWrapper(['Accession','Gi','Strain','Start','End'], pipes)
def _read_accnum(line):
    """Reads ACCNUM lines: format is Accession|Gi|Strain|Start|End."""
    return MappedRecord(accnum_wrapper(line))

map_wrapper = FieldWrapper(['Location','Source','Type'], pipes)
Exemplo n.º 5
0
 def test_constructor(self):
     """FieldWrapper with constructor should use that constructor"""
     fields = list('abc')
     f = FieldWrapper(fields, constructor=fake_dict)
     self.assertEqual(f('x y'), {'a': 'x', 'b': 'y'})
     assert isinstance(f('x y'), fake_dict)