root/galaxy-central/lib/galaxy_utils/sequence/sequence.py

リビジョン 2, 2.2 KB (コミッタ: hatakeyama, 14 年 前)

import galaxy-central

行番号 
1#Dan Blankenberg
2import transform
3import string
4from copy import deepcopy
5
6class SequencingRead( object ):
7    color_space_converter = transform.ColorSpaceConverter()
8    valid_sequence_list = string.letters
9    def __init__( self ):
10        self.identifier = None
11        self.sequence = '' #holds raw sequence string: no whitespace
12        self.description = None
13        self.quality = '' #holds raw quality string: no whitespace, unless this contains decimal scores
14    def __len__( self ):
15        return len( self.sequence )
16    def __str__( self ):
17        return "%s\n%s\n%s\n%s\n" % ( self.identifier, self.sequence, self.description, self.quality )
18    def append_sequence( self, sequence ):
19        self.sequence += sequence.rstrip( '\n\r' )
20    def append_quality( self, quality ):
21        self.quality += quality.rstrip( '\n\r' )
22    def is_DNA( self ):
23        return 'u' not in self.sequence.lower()
24    def clone( self ):
25        return deepcopy( self )
26    def reverse( self, clone = True ):
27        if clone:
28            rval = self.clone()
29        else:
30            rval = self
31        rval.sequence = transform.reverse( self.sequence )
32        rval.quality = rval.quality[::-1]
33        return rval
34    def complement( self, clone = True ):
35        if clone:
36            rval = self.clone()
37        else:
38            rval = self
39        if rval.is_DNA():
40            rval.sequence = transform.DNA_complement( rval.sequence )
41        else:
42            rval.sequence = transform.RNA_complement( rval.sequence )
43        return rval
44    def reverse_complement( self, clone = True ):
45        #need to reverse first, then complement
46        rval = self.reverse( clone = clone )
47        return rval.complement( clone = False ) #already working with a clone if requested
48    def sequence_as_DNA( self, clone = True ):
49        if clone:
50            rval = self.clone()
51        else:
52            rval = self
53        rval.sequence = transform.to_DNA( rval.sequence )
54        return rval
55    def sequence_as_RNA( self, clone = True ):
56        if clone:
57            rval = self.clone()
58        else:
59            rval = self
60        rval.sequence = transform.to_RNA( rval.sequence )
61        return rval
Note: リポジトリブラウザについてのヘルプは TracBrowser を参照してください。