File: Record.py

package info (click to toggle)
python-biopython 1.42-2
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 17,584 kB
  • ctags: 12,272
  • sloc: python: 80,461; xml: 13,834; ansic: 7,902; cpp: 1,855; sql: 1,144; makefile: 203
file content (80 lines) | stat: -rw-r--r-- 1,870 bytes parent folder | download | duplicates (3)
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# Copyright 2001 by Katharine Lindner.  All rights reserved.
# This code is part of the Biopython distribution and governed by its
# license.  Please see the LICENSE file that should have been included
# as part of this package.

"""Martel based parser to read NBRF formatted files.

This is a huge regular regular expression for NBRF, built using
the 'regular expressiona on steroids' capabilities of Martel.

http://www-nbrf.georgetown.edu/pirwww/pirhome.shtml


Notes:
Just so I remember -- the new end of line syntax is:
  New regexp syntax - \R
     \R    means "\n|\r\n?"
     [\R]  means "[\n\r]"

This helps us have endlines be consistent across platforms.

"""
# standard library
import string


from Bio.Seq import Seq
from Bio.NBRF.ValSeq import valid_sequence_dict



"""Hold NBRF data in a straightforward format.

classes:
o Record - All of the information in an NBRF record.
"""

class Record:
    """Hold NBRF information in a format similar to the original record.

    The Record class is meant to make data easy to get to when you are
    just interested in looking at NBRF data.

    Attributes:
    sequence_type
    sequence_name
    comment
    sequence

    """
    def __init__(self):
        self.sequence_type = ''
        self.sequence_name = ''
        self.comment = ''
        self.sequence = Seq('')

    def __str__( self ):
        sequence_type = valid_sequence_dict[ self.sequence_type ]
        output =  'Sequence type %s\n' % sequence_type
        output =  output + 'Sequence name %s\n' % self.sequence_name
        output = output + '%s\n' % self.comment
        output = output + out_sequence( self.sequence.data )
        return output

def out_sequence( seq ):
    output = ''
    for j in range( 0, len( seq ), 80 ):
        output = output + '%s\n'  % seq[ j: j + 80 ]
    output = output + '\n'
    return output