~ubuntu-branches/ubuntu/natty/python-cogent/natty

« back to all changes in this revision

Viewing changes to tests/test_draw.py

  • Committer: Bazaar Package Importer
  • Author(s): Steffen Moeller
  • Date: 2010-12-04 22:30:35 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20101204223035-j11kinhcrrdgg2p2
Tags: 1.5-1
* Bumped standard to 3.9.1, no changes required.
* New upstream version.
  - major additions to Cookbook
  - added AlleleFreqs attribute to ensembl Variation objects.
  - added getGeneByStableId method to genome objects.
  - added Introns attribute to Transcript objects and an Intron class.
  - added Mann-Whitney test and a Monte-Carlo version
  - exploratory and confirmatory period estimation techniques (suitable for
    symbolic and continuous data)
  - Information theoretic measures (AIC and BIC) added
  - drawing of trees with collapsed nodes
  - progress display indicator support for terminal and GUI apps
  - added parser for illumina HiSeq2000 and GAiix sequence files as 
    cogent.parse.illumina_sequence.MinimalIlluminaSequenceParser.
  - added parser to FASTQ files, one of the output options for illumina's
    workflow, also added cookbook demo.
  - added functionality for parsing of SFF files without the Roche tools in
    cogent.parse.binary_sff
  - thousand fold performance improvement to nmds
  - >10-fold performance improvements to some Table operations

Show diffs side-by-side

added added

removed removed

Lines of Context:
12
12
__credits__ = ["Peter Maxwell", "Gavin Huttley", "Rob Knight",
13
13
                    "Matthew Wakefield"]
14
14
__license__ = "GPL"
15
 
__version__ = "1.4.1"
 
15
__version__ = "1.5.0"
16
16
__maintainer__ = "Gavin Huttley"
17
17
__email__ = "gavin.huttley@anu.edu.au"
18
18
__status__ = "Production"
23
23
    matplotlib.use('PDF') # or Agg
24
24
    file_ext = "pdf" # or png
25
25
 
26
 
def makeSampleSequence():
27
 
    seq = DNA.makeSequence('aaaccggttt' * 10)
 
26
def makeSampleSequence(mut=False):
 
27
    repeat = 'aaaccggtwt'
 
28
    if mut: repeat = repeat[:-1]
 
29
    seq = DNA.makeSequence(repeat * 10)
28
30
    v = seq.addAnnotation(annotation.Feature, 'exon', 'exon', [(20,35)])
29
31
    v = seq.addAnnotation(annotation.Feature, 'repeat_unit', 'repeat_unit', [(39,49)])
30
32
    v = seq.addAnnotation(annotation.Feature, 'repeat_unit', 'rep2', [(49,60)])
35
37
    from cogent.align.align import global_pairwise, make_dna_scoring_dict
36
38
    DNA = make_dna_scoring_dict(10, -8, -8)
37
39
    seq1 = makeSampleSequence()[:-2]
38
 
    seq2 = makeSampleSequence()[2:]
 
40
    seq2 = makeSampleSequence(mut=True)[2:]
39
41
    seq1.Name = 'FAKE01'
40
42
    seq2.Name = 'FAKE02'
41
43
    names = (seq1.getName(), seq2.getName())
58
60
        fname = 'draw_test_%s.%s' % (msg.replace(' ', '_'), file_ext)
59
61
        seq_display.makeFigure(**kw).savefig(fname)
60
62
 
 
63
def green_cg(seq):
 
64
    seq = str(seq)
 
65
    posn = 0
 
66
    result = []
 
67
    while True:
 
68
        last = posn
 
69
        posn = seq.find('CG', posn)
 
70
        if posn < 0: break
 
71
        result.append('k' * (posn-last)+'gg')
 
72
        posn += 2
 
73
    result.append('k' * (len(seq)-last))
 
74
    return list(''.join(result))
 
75
 
61
76
def test_seqs():
62
77
    seqd = Display(seq)
63
78
    fig('sequence wrapped at 50', 
65
80
    small = FontProperties(size=7, stretch='extra-condensed')
66
81
    fig('squashed sequence', 
67
82
        seqd.copy(seq_font=small, colour_sequences=True))
68
 
    fig('seq display slice from 10 to 50', 
69
 
        seqd[10:50])
70
 
    
 
83
    fig('seq display slice from 5 to 45 starts "GGT"', 
 
84
        seqd[5:45])
 
85
 
 
86
def test_alns():
71
87
    alignd = Display(align, colour_sequences=True, min_feature_height=10)
72
88
    fig('coloured text alignment', 
73
89
        alignd)
74
 
    fig('coloured dot alignment', 
 
90
    fig('coloured alignment no text', 
75
91
        alignd.copy(show_text=False))
76
 
    fig('alignment with lines only', 
 
92
    fig('no text and no colour', 
77
93
        alignd.copy(show_text=False, colour_sequences=False))
78
 
 
 
94
    fig('no shapes', 
 
95
        alignd.copy(show_text=False, draw_bases=False))            
 
96
    fig('no text or colour or shapes', 
 
97
        alignd.copy(show_text=False, colour_sequences=False, draw_bases=False))
 
98
    fig('green seqs', 
 
99
        alignd.copy(seq_color_callback=green_cg))
79
100
 
80
101
# LEGEND
81
102
def test_legend():
86
107
 
87
108
def test_dotplot():
88
109
    from cogent.draw.dotplot import Display2D
89
 
    fig('2d', Display2D(seq, seq[:40]))
 
110
    fig('2d', Display2D(seq, seq[:40], show_text=False, draw_bases=False))
90
111
 
91
112
#fig('reversed', Display(seq[50:10]), 500)
92
113
# no good because seqs slice like lists: ie len==0
106
127
            ShelvedDendrogram, 
107
128
    #        StraightDendrogram, 
108
129
    #        ContemporaneousStraightDendrogram
109
 
        ]:
110
 
        fig(klass.__name__, klass(t), shade_param="length", 
 
130
            ]:
 
131
        dendro = klass(t)
 
132
        dendro.getConnectingNode('Ccccccccccc', 'Eeeeeeeeeee').setCollapsed(
 
133
            color="green", label="C, D and E")
 
134
        fig(klass.__name__, dendro, shade_param="length", 
111
135
            show_params=["length"])
112
 
    
 
136
 
113
137
    def callback(edge):
114
138
        return ["blue", "red"][edge.Name.startswith("A")]
115
 
    
116
139
    fig("Highlight edge A", UnrootedDendrogram(t), edge_color_callback=callback)
117
140
    
118
141
if __name__ == '__main__':
119
142
    test_seqs()
 
143
    test_alns()
120
144
    test_legend()
121
145
    test_dotplot()
122
146
    test_trees()