def get_form(): """ @return: the body of a form """ # define the default tree string tree = NewickIO.parse(g_default_string, FelTree.NewickTree) formatted_tree_string = NewickIO.get_narrow_newick_string(tree, 60) # define the form objects form_objects = [ Form.MultiLine('tree', 'newick tree', formatted_tree_string), Form.RadioGroup('matrix', 'nodes used for the distance matrix', [ RadioItem('standard', 'tips only', True), RadioItem('augmented', 'all nodes'), RadioItem('named', 'all named nodes') ]), Form.CheckGroup('output_options', 'output options', [ CheckItem('show_split', 'exact criterion partition', True), CheckItem('show_value', 'exact criterion value', True), CheckItem('show_value_minus_trace', 'exact criterion value minus trace', True), CheckItem('show_fiedler_split', 'show the spectral sign partition', True), CheckItem('show_fiedler_eigenvector', 'show the eigenvector of interest', True), CheckItem('show_labels', 'ordered labels', True), CheckItem('show_distance_matrix', 'distance matrix', True), CheckItem('show_M_matrix', 'M matrix', True) ]) ] return form_objects
def get_form(): """ @return: the body of a form """ # define the default tree string and ordered tip labels tree_string = "(a:1, (b:2, d:5):1, c:4);" tree = NewickIO.parse(tree_string, FelTree.NewickTree) formatted_tree_string = NewickIO.get_narrow_newick_string(tree, 60) labels = list(sorted(tip.name for tip in tree.gen_tips())) # define the form objects form_objects = [ Form.MultiLine("tree", "newick tree", formatted_tree_string), Form.MultiLine("inlabels", "ordered labels", "\n".join(labels)), Form.Float("strength", "perturbation strength", 0.1, low_inclusive=0), Form.CheckGroup( "options", "output options", [ CheckItem("perturbed", "a perturbed distance matrix", True), CheckItem("distance", "the original distance matrix"), CheckItem("outlabels", "ordered labels"), ], ), ] return form_objects
def get_form(): """ @return: the body of a form """ # define the tree string tree_string = '(((a:0.05, b:0.05):0.15, c:0.2):0.8, x:1.0, (((m:0.05, n:0.05):0.15, p:0.2):0.8, y:1.0):1.0);' tree = NewickIO.parse(tree_string, FelTree.NewickTree) formatted_tree_string = NewickIO.get_narrow_newick_string(tree, 60) # define the object list form_objects = [ Form.MultiLine('tree', 'tree', formatted_tree_string), Form.Integer('sequence_length', 'use sequences that are this long', 100, low=1), Form.RadioGroup('assumption', 'distance matrix sampling model', [ RadioItem('infinite_alleles', 'infinite alleles', True), RadioItem('jukes_cantor', 'Jukes-Cantor model (4 alleles)')]), Form.RadioGroup('infinity', 'matrices with infinite distances', [ RadioItem('reject_infinity', 'reject these matrices', True), RadioItem('replace_infinity', 'use 20 instead')]), Form.RadioGroup('zero', 'matrices with zero distances', [ RadioItem('reject_zero', 'reject these matrices'), RadioItem('replace_zero', 'use .00001 instead'), RadioItem('remain_zero', 'use 0 unmodified', True)]), Form.RadioGroup('criterion', 'tree reconstruction criterion', [ RadioItem('sign', 'spectral sign approximation', True), RadioItem('nj', 'neighbor joining'), RadioItem('random', 'random bipartition')])] # return the object list return form_objects
def get_form(): """ @return: the body of a form """ # define the default tree string tree = NewickIO.parse(g_default_string, FelTree.NewickTree) formatted_tree_string = NewickIO.get_narrow_newick_string(tree, 60) # define the form objects form_objects = [ Form.MultiLine('tree', 'newick tree with branch lengths', formatted_tree_string), Form.SingleLine('lhs_a', 'the first taxon on one side of the split', 'a'), Form.SingleLine('lhs_b', 'the second taxon on one side of the split', 'b'), Form.SingleLine('rhs_a', 'the first taxon on the other side of the split', 'x'), Form.SingleLine('rhs_b', 'the second taxon on the other side of the split', 'y'), Form.CheckGroup('options', 'output options', [ Form.CheckItem('show_response', 'show the Laplacian response matrix'), Form.CheckItem('show_reduced_response', 'show the 2x2 submatrix'), Form.CheckItem('show_blen', 'show the branch length implied by the split') ]) ] return form_objects
def get_form(): """ @return: a list of form objects """ tree = NewickIO.parse(g_default_string, FelTree.NewickTree) formatted_tree_string = NewickIO.get_narrow_newick_string(tree, 60) return [Form.MultiLine('tree', 'tree', formatted_tree_string)]
def get_form(): """ @return: the body of a form """ # define the default tree string tree = NewickIO.parse(g_default_string, FelTree.NewickTree) formatted_tree_string = NewickIO.get_narrow_newick_string(tree, 60) # define the form objects form_objects = [ Form.MultiLine('tree', 'newick tree', formatted_tree_string), Form.Integer('length', 'use sequences that are this long', 100, low=1), Form.RadioGroup('assumption', 'distance matrix sampling model', [ Form.RadioItem('infinite_alleles', 'infinite alleles', True), Form.RadioItem('jukes_cantor', 'Jukes-Cantor model (4 alleles)')]), Form.RadioGroup('infinity', 'infinite distance estimates', [ Form.RadioItem('reject_infinity', 'reject these matrices'), Form.RadioItem('replace_infinity', 'replace inf with 20', True)]), Form.RadioGroup('zero', 'distance estimates of zero', [ Form.RadioItem('reject_zero', 'reject these matrices'), Form.RadioItem('replace_zero', 'use .00001 instead of zero'), Form.RadioItem('remain_zero', 'use 0 unmodified', True)])] return form_objects
def get_form(): """ @return: the body of a form """ # define the default tree string tree = get_default_original_tree() formatted_tree_string = NewickIO.get_narrow_newick_string(tree, 60) # define the form objects form_objects = [ Form.MultiLine('tree', 'original tree with branch lengths', formatted_tree_string), Form.Integer('iterations', 'reconstruct this many trees', 10, low=1), Form.Integer('length', 'use sequences that are this long', 100, low=2), Form.RadioGroup('criterion', 'bipartition function', [ RadioItem('exact', 'exact criterion'), RadioItem('sign', 'spectral sign approximation', True), RadioItem('threshold', 'spectral threshold approximation'), RadioItem('nj', 'neighbor joining criterion'), RadioItem('random', 'random bipartition')]), Form.RadioGroup('recourse', 'recourse for degenerate partitions', [ RadioItem('njrecourse', 'neighbor joining', True), RadioItem('halvingrecourse', 'leaf stem length halving')]), Form.CheckGroup('output_options', 'extra output option', [ CheckItem('showtrees', 'show reconstructed tree topologies')])] return form_objects
def get_form(): """ @return: the body of a form """ # define the default tree string tree = NewickIO.parse(g_default_string, FelTree.NewickTree) formatted_tree_string = NewickIO.get_narrow_newick_string(tree, 60) # define the form objects form_objects = [ Form.MultiLine('tree', 'newick tree', formatted_tree_string), Form.Integer('length', 'use sequences that are this long', 100, low=1), Form.RadioGroup('assumption', 'distance matrix sampling model', [ Form.RadioItem('infinite_alleles', 'infinite alleles', True), Form.RadioItem('jukes_cantor', 'Jukes-Cantor model (4 alleles)') ]), Form.RadioGroup('infinity', 'infinite distance estimates', [ Form.RadioItem('reject_infinity', 'reject these matrices'), Form.RadioItem('replace_infinity', 'replace inf with 20', True) ]), Form.RadioGroup('zero', 'distance estimates of zero', [ Form.RadioItem('reject_zero', 'reject these matrices'), Form.RadioItem('replace_zero', 'use .00001 instead of zero'), Form.RadioItem('remain_zero', 'use 0 unmodified', True) ]) ] return form_objects
def get_form(): """ @return: the body of a form """ # define the default tree string tree = get_default_original_tree() formatted_tree_string = NewickIO.get_narrow_newick_string(tree, 60) # define the form objects form_objects = [ Form.MultiLine('tree', 'original tree with branch lengths', formatted_tree_string), Form.Integer('iterations', 'reconstruct this many trees', 10, low=1), Form.Integer('length', 'use sequences that are this long', 100, low=2), Form.RadioGroup('criterion', 'bipartition function', [ RadioItem('exact', 'exact criterion'), RadioItem('sign', 'spectral sign approximation', True), RadioItem('threshold', 'spectral threshold approximation'), RadioItem('nj', 'neighbor joining criterion'), RadioItem('random', 'random bipartition') ]), Form.RadioGroup('recourse', 'recourse for degenerate partitions', [ RadioItem('njrecourse', 'neighbor joining', True), RadioItem('halvingrecourse', 'leaf stem length halving') ]), Form.CheckGroup( 'output_options', 'extra output option', [CheckItem('showtrees', 'show reconstructed tree topologies')]) ] return form_objects
def get_form(): """ @return: the body of a form """ # define the default tree string tree = NewickIO.parse(g_default_string, FelTree.NewickTree) formatted_tree_string = NewickIO.get_narrow_newick_string(tree, 60) # define the form objects form_objects = [ Form.MultiLine('tree', 'newick tree with branch lengths', formatted_tree_string), Form.SingleLine('lhs_a', 'the first taxon on one side of the split', 'a'), Form.SingleLine('lhs_b', 'the second taxon on one side of the split', 'b'), Form.SingleLine('rhs_a', 'the first taxon on the other side of the split', 'x'), Form.SingleLine('rhs_b', 'the second taxon on the other side of the split', 'y'), Form.CheckGroup('options', 'output options', [ Form.CheckItem('show_response', 'show the full Laplacian matrix'), Form.CheckItem('show_reduced_response', 'show the 2x2 submatrix'), Form.CheckItem('show_blen', 'show the branch length implied by the split')])] return form_objects
def get_form(): """ @return: the body of a form """ # define the default tree string tree = NewickIO.parse(g_default_string, FelTree.NewickTree) formatted_tree_string = NewickIO.get_narrow_newick_string(tree, 60) # define the form objects form_objects = [ Form.MultiLine("tree", "newick tree", formatted_tree_string), Form.RadioGroup( "matrix", "nodes used for the distance matrix", [ RadioItem("standard", "tips only", True), RadioItem("augmented", "all nodes"), RadioItem("named", "all named nodes"), ], ), Form.CheckGroup( "output_options", "output options", [ CheckItem("show_split", "exact criterion partition", True), CheckItem("show_value", "exact criterion value", True), CheckItem("show_value_minus_trace", "exact criterion value minus trace", True), CheckItem("show_fiedler_split", "show the spectral sign partition", True), CheckItem("show_fiedler_eigenvector", "show the eigenvector of interest", True), CheckItem("show_labels", "ordered labels", True), CheckItem("show_distance_matrix", "distance matrix", True), CheckItem("show_M_matrix", "M matrix", True), ], ), ] return form_objects
def get_form(): """ @return: a list of form objects """ # define the default tree string tree = NewickIO.parse(g_default_string, FelTree.NewickTree) formatted_tree_string = NewickIO.get_narrow_newick_string(tree, 60) # return the form objects form_objects = [Form.MultiLine("tree", "newick tree with branch lengths", formatted_tree_string)] return form_objects
def get_form(): """ @return: the body of a form """ # define the formatted tree string tree = NewickIO.parse(g_tree_data, Newick.NewickTree) formatted_tree_string = NewickIO.get_narrow_newick_string(tree, 60) # return the form objects form_objects = [ Form.MultiLine('tree', 'newick tree', formatted_tree_string)] return form_objects
def get_form(): """ @return: the body of a form """ default_tree = NewickIO.parse(g_tree_data, FelTree.NewickTree) default_tree_string = NewickIO.get_narrow_newick_string(default_tree, 60) # define the list of form objects form_objects = [ Form.MultiLine('tree', 'tree', default_tree_string), Form.MultiLine('annotation', 'SNP annotations', g_annotation_data) ] return form_objects
def get_form(): """ @return: a list of form objects """ # define the default tree string tree = NewickIO.parse(g_tree_string, FelTree.NewickTree) formatted_default_tree_string = NewickIO.get_narrow_newick_string(tree, 60) # define the list of form objects form_objects = [ Form.MultiLine('tree', 'tree', formatted_default_tree_string), Form.ImageFormat()] return form_objects
def get_form(): """ @return: a list of form objects """ # define the default tree string tree = NewickIO.parse(g_default_string, FelTree.NewickTree) formatted_tree_string = NewickIO.get_narrow_newick_string(tree, 60) # return the form objects return [ Form.MultiLine('tree', 'newick tree with branch lengths', formatted_tree_string), Form.Integer('precision', 'precision', 4, low=2, high=17)]
def get_form(): """ @return: the body of a form """ # define the formatted tree string tree = NewickIO.parse(g_tree_data, Newick.NewickTree) formatted_tree_string = NewickIO.get_narrow_newick_string(tree, 60) # return the form objects form_objects = [ Form.MultiLine('tree', 'newick tree', formatted_tree_string) ] return form_objects
def get_form(): """ @return: a list of form objects """ # define the default tree string tree = NewickIO.parse(g_default_string, FelTree.NewickTree) formatted_tree_string = NewickIO.get_narrow_newick_string(tree, 60) # return the form objects form_objects = [ Form.MultiLine('tree', 'newick tree with branch lengths', formatted_tree_string)] return form_objects
def get_form(): """ @return: a list of form objects """ # define the default tree string tree = NewickIO.parse(g_tree_string, FelTree.NewickTree) formatted_default_tree_string = NewickIO.get_narrow_newick_string(tree, 60) # define the list of form objects form_objects = [ Form.MultiLine('tree', 'tree', formatted_default_tree_string), Form.ImageFormat() ] return form_objects
def get_form(): """ @return: a list of form objects """ # define the default tree string # ordered_labels = ('a', 'b', 'c', 'x', 'm', 'n', 'p', 'y', 'ab', 'abc', 'mn', 'mnp', 'mnpy', 'abcxmnpy') tree = NewickIO.parse(g_default_string, FelTree.NewickTree) formatted_tree_string = NewickIO.get_narrow_newick_string(tree, 60) # return the form objects return [ Form.MultiLine("tree", "newick tree with branch lengths", formatted_tree_string), Form.Integer("precision", "precision", 4, low=2, high=17), ]
def get_form(): """ @return: a list of form objects """ # define the default tree string tree = NewickIO.parse(g_default_string, FelTree.NewickTree) formatted_tree_string = NewickIO.get_narrow_newick_string(tree, 60) # return the form objects return [ Form.MultiLine('tree', 'newick tree with branch lengths', formatted_tree_string), Form.Integer('precision', 'precision', 4, low=2, high=17) ]
def get_form(): """ @return: the body of a form """ default_tree = NewickIO.parse(g_tree_data, FelTree.NewickTree) default_tree_string = NewickIO.get_narrow_newick_string(default_tree, 60) # define the list of form objects form_objects = [ Form.MultiLine('tree', 'tree', default_tree_string), Form.MultiLine('annotation', 'SNP annotations', g_annotation_data)] return form_objects
def get_verbose_summary(self): """ @return: a multiline string """ # begin the response out = StringIO() # show the number of taxa in various domains print >> out, self._get_name_summary() print >> out # show the pruned full tree formatted_tree_string = NewickIO.get_narrow_newick_string(self.pruned_tree, 120) print >> out, 'this is the tree that represents all clades but for which redundant nodes have been pruned:' print >> out, formatted_tree_string print >> out # split the distance matrix D = np.array(self.pruned_tree.get_distance_matrix(self.pruned_names)) L = Euclid.edm_to_laplacian(D) v = BuildTreeTopology.laplacian_to_fiedler(L) eigensplit = BuildTreeTopology.eigenvector_to_split(v) # report the eigendecomposition print >> out, get_eigendecomposition_report(D) print >> out # report the clade intersections of sides of the split side_names = [set(self.pruned_names[i] for i in side) for side in eigensplit] print >> out, 'domains represented by each side of the primary split:' print >> out, 'the left side has:\t', ', '.join(self._get_domains(side_names[0])) print >> out, 'the right side has:\t', ', '.join(self._get_domains(side_names[1])) print >> out # prepare to do the secondary splits left_indices, right_indices = eigensplit full_label_sets = [set([i]) for i in range(len(self.pruned_names))] # do the secondary splits for index_selection, index_complement in ((left_indices, right_indices), (right_indices, left_indices)): L_secondary = SchurAlgebra.mmerge(L, index_complement) next_label_sets = SchurAlgebra.vmerge(full_label_sets, index_complement) v = BuildTreeTopology.laplacian_to_fiedler(L_secondary) left_subindices, right_subindices = BuildTreeTopology.eigenvector_to_split(v) left_sublabels = set() for i in left_subindices: left_sublabels.update(next_label_sets[i]) right_sublabels = set() for i in right_subindices: right_sublabels.update(next_label_sets[i]) left_subnames = set(self.pruned_names[i] for i in left_sublabels) right_subnames = set(self.pruned_names[i] for i in right_sublabels) print >> out, 'domains represented by a subsplit:' print >> out, 'the left side has:\t', ', '.join(self._get_domains(left_subnames)) print >> out, 'the right side has:\t', ', '.join(self._get_domains(right_subnames)) print >> out # return the multiline string return out.getvalue().strip()
def get_form(): """ @return: the body of a form """ # Define the default tree string with branch lengths # and named internal nodes. tree_string = '(a:2, (b:2, c:9)g:4, ((d:1, e:3)i:7, f:2)j:1)h;' tree = NewickIO.parse(tree_string, FelTree.NewickTree) formatted_tree_string = NewickIO.get_narrow_newick_string(tree, 60) # define the form objects form_objects = [ Form.MultiLine('tree', 'newick tree with branch lengths', formatted_tree_string)] return form_objects
def get_form(): """ @return: the body of a form """ # define the default tree default_tree = NewickIO.parse(g_default_string, FelTree.NewickTree) default_tree_string = NewickIO.get_narrow_newick_string(default_tree, 60) # define the list of form objects form_objects = [ Form.MultiLine('tree', 'newick tree', default_tree_string), Form.SingleLine('chromosome', 'chromosome', 'chr17'), Form.Integer('position', 'position', 70360012, low=0), Form.SingleLine('aminoacid', 'the amino acid of interest', 'P')] return form_objects
def get_form(): """ @return: the body of a form """ # define the default tree string tree_string = NewickIO.daylight_example_tree tree = NewickIO.parse(tree_string, FelTree.NewickTree) formatted_tree_string = NewickIO.get_narrow_newick_string(tree, 60) # define the form objects form_objects = [ Form.MultiLine('tree', 'newick tree', formatted_tree_string), Form.MultiLine('selection', 'selected taxa', '\n'.join('ABFG')), Form.ImageFormat()] return form_objects
def get_form(): """ @return: the body of a form """ # define the default tree default_tree = NewickIO.parse(g_default_string, FelTree.NewickTree) default_tree_string = NewickIO.get_narrow_newick_string(default_tree, 60) # Define the default lines # that tell the amino acids in the column of the alignment. default_alignment_lines = [ 'Hg18 F', 'bosTau3 V', 'canFam2 V', 'danRer5 L', 'galGal3 A', 'mm9 L', 'monDom4 H', 'panTro2 F', 'rheMac2 F', 'rn4 L'] default_alignment_string = '\n'.join(default_alignment_lines) # define the list of form objects form_objects = [ Form.MultiLine('tree', 'tree', default_tree_string), Form.MultiLine('column', 'amino acid of each taxon', default_alignment_string), Form.CheckGroup('options', 'show these intermediate values', [ Form.CheckItem('show_raw_pc_table', 'the raw physicochemical property table', True), Form.CheckItem('show_standardized_pc_table', 'the standardized physicochemical property table', True), Form.CheckItem('show_pc_correlation_matrix', 'the physicochemical property correlation matrix', True), Form.CheckItem('show_tree', 'the pruned phylogenetic tree', True), Form.CheckItem('show_weights', 'the taxon weights', True), Form.CheckItem('show_aa_distribution', 'the estimated amino acid distribution', True), Form.CheckItem('show_pc_distribution', 'the estimated physicochemical property distn', True), Form.CheckItem('show_deviations', 'the aa physicochemical property deviations', True), Form.CheckItem('show_impact_scores', 'the impact score for each amino acid', True), Form.CheckItem('show_p_values', 'the p-value for each amino acid', True)])] return form_objects
def get_form(): """ @return: the body of a form """ # define the default tree default_tree = NewickIO.parse(g_default_string, FelTree.NewickTree) default_tree_string = NewickIO.get_narrow_newick_string(default_tree, 60) # define the list of form objects form_objects = [ Form.MultiLine('tree', 'newick tree', default_tree_string), Form.SingleLine('chromosome', 'chromosome', 'chr17'), Form.Integer('position', 'position', 70360012, low=0), Form.SingleLine('aminoacid', 'the amino acid of interest', 'P') ] return form_objects
def get_form(): """ @return: the body of a form """ # define the default tree string tree_string = NewickIO.daylight_example_tree tree = NewickIO.parse(tree_string, FelTree.NewickTree) formatted_tree_string = NewickIO.get_narrow_newick_string(tree, 60) # define the form objects form_objects = [ Form.MultiLine('tree', 'newick tree', formatted_tree_string), Form.MultiLine('selection', 'selected taxa', '\n'.join('ABFG')), Form.ImageFormat() ] return form_objects
def get_form(): """ @return: a list of form objects """ tree = NewickIO.parse(g_default_string, FelTree.NewickTree) formatted_default_tree_string = NewickIO.get_narrow_newick_string(tree, 60) # define the list of form objects form_objects = [ Form.MultiLine('tree', 'tree', formatted_default_tree_string), Form.CheckGroup('processing_options', 'processing options', [ Form.CheckItem('internal', 'process internal nodes', True)]), Form.CheckGroup('visualization_options', 'visualization options', [ Form.CheckItem('axes', 'draw axes', True), Form.CheckItem('connections', 'draw connections', True)]), Form.ImageFormat()] return form_objects
def get_form(): """ @return: a list of form objects """ # this counterexample uses symmetric and long branch lengths unused_counterexample = '(a:2, b:5, (c:5, d:2):1);' # this counterexample uses asymmetric and shorter branch lengths counterexample = '(a:.5, b:2.5, (c:2.7, d:.6):.3);' default_tree_string = counterexample tree = NewickIO.parse(default_tree_string, FelTree.NewickTree) formatted_tree_string = NewickIO.get_narrow_newick_string(tree, 60) # return the form objects form_objects = [ Form.MultiLine('tree', 'newick tree with branch lengths', formatted_tree_string)] return form_objects
def get_form(): """ @return: a list of form objects """ # this counterexample uses symmetric and long branch lengths unused_counterexample = '(a:2, b:5, (c:5, d:2):1);' # this counterexample uses asymmetric and shorter branch lengths counterexample = '(a:.5, b:2.5, (c:2.7, d:.6):.3);' default_tree_string = counterexample tree = NewickIO.parse(default_tree_string, FelTree.NewickTree) formatted_tree_string = NewickIO.get_narrow_newick_string(tree, 60) # return the form objects form_objects = [ Form.MultiLine('tree', 'newick tree with branch lengths', formatted_tree_string) ] return form_objects
def get_form(): """ @return: the body of a form """ tree = NewickIO.parse(g_default_string, FelTree.NewickTree) formatted_tree_string = NewickIO.get_narrow_newick_string(tree, 60) # define the form objects form_objects = [ Form.MultiLine('tree', 'newick tree with branch lengths', formatted_tree_string), Form.CheckGroup('options', 'output options', [ Form.CheckItem('show_direct_d', 'show the directly calculated full distance matrix', True), Form.CheckItem('show_clever_d', 'show the cleverly calculated full distance matrix', True), Form.CheckItem('show_closeness', 'show whether or not distance matrices are close', True)])] return form_objects
def get_form(): """ @return: the body of a form """ # define the default tree default_tree = NewickIO.parse(g_default_string, FelTree.NewickTree) default_tree_string = NewickIO.get_narrow_newick_string(default_tree, 60) # Define the default lines # that tell the amino acids in the column of the alignment. default_alignment_lines = [ 'Hg18 F', 'bosTau3 V', 'canFam2 V', 'danRer5 L', 'galGal3 A', 'mm9 L', 'monDom4 H', 'panTro2 F', 'rheMac2 F', 'rn4 L' ] default_alignment_string = '\n'.join(default_alignment_lines) # define the list of form objects form_objects = [ Form.MultiLine('tree', 'tree', default_tree_string), Form.MultiLine('column', 'amino acid of each taxon', default_alignment_string), Form.CheckGroup('options', 'show these intermediate values', [ Form.CheckItem('show_raw_pc_table', 'the raw physicochemical property table', True), Form.CheckItem('show_standardized_pc_table', 'the standardized physicochemical property table', True), Form.CheckItem('show_pc_correlation_matrix', 'the physicochemical property correlation matrix', True), Form.CheckItem('show_tree', 'the pruned phylogenetic tree', True), Form.CheckItem('show_weights', 'the taxon weights', True), Form.CheckItem('show_aa_distribution', 'the estimated amino acid distribution', True), Form.CheckItem('show_pc_distribution', 'the estimated physicochemical property distn', True), Form.CheckItem('show_deviations', 'the aa physicochemical property deviations', True), Form.CheckItem('show_impact_scores', 'the impact score for each amino acid', True), Form.CheckItem('show_p_values', 'the p-value for each amino acid', True) ]) ] return form_objects
def get_form(): """ @return: the body of a form """ # Define the default tree string with branch lengths # and named internal nodes. tree_string = '(a:2, (b:2, c:9)g:4, ((d:1, e:3)i:7, f:2)j:1)h;' tree = NewickIO.parse(tree_string, FelTree.NewickTree) formatted_tree_string = NewickIO.get_narrow_newick_string(tree, 60) # define the form objects form_objects = [ Form.MultiLine('tree', 'newick tree with branch lengths', formatted_tree_string), Form.Float('scaling_factor', 'show Laplacian matrices scaled by this amount', 13320), Form.RadioGroup('matrix_format', 'matrix format', [ Form.RadioItem('plain_matrix', 'plain', True), Form.RadioItem('latex_matrix', 'LaTeX')])] return form_objects
def get_form(): """ @return: a list of form objects """ tree = NewickIO.parse(g_default_string, FelTree.NewickTree) formatted_default_tree_string = NewickIO.get_narrow_newick_string(tree, 60) # define the list of form objects form_objects = [ Form.MultiLine('tree', 'tree', formatted_default_tree_string), Form.CheckGroup( 'processing_options', 'processing options', [Form.CheckItem('internal', 'process internal nodes', True)]), Form.CheckGroup('visualization_options', 'visualization options', [ Form.CheckItem('axes', 'draw axes', True), Form.CheckItem('connections', 'draw connections', True) ]), Form.ImageFormat() ] return form_objects
def get_form(): """ @return: the body of a form """ # define the default tree string and ordered tip labels tree_string = '(a:1, (b:2, d:5):1, c:4);' tree = NewickIO.parse(tree_string, FelTree.NewickTree) formatted_tree_string = NewickIO.get_narrow_newick_string(tree, 60) labels = list(sorted(tip.name for tip in tree.gen_tips())) # define the form objects form_objects = [ Form.MultiLine('tree', 'newick tree', formatted_tree_string), Form.MultiLine('inlabels', 'ordered labels', '\n'.join(labels)), Form.Float('strength', 'perturbation strength', 0.1, low_inclusive=0), Form.CheckGroup('options', 'output options', [ CheckItem('perturbed', 'a perturbed distance matrix', True), CheckItem('distance', 'the original distance matrix'), CheckItem('outlabels', 'ordered labels') ]) ] return form_objects
def get_form(): """ @return: the body of a form """ # define the default tree string tree = NewickIO.parse(g_default_string, FelTree.NewickTree) formatted_tree_string = NewickIO.get_narrow_newick_string(tree, 60) # define the ordered labels ordered_labels = list('abcxmnpy') # define the form objects form_objects = [ Form.MultiLine('tree', 'rooted newick tree with branch lengths', formatted_tree_string), Form.MultiLine('labels', 'ordered labels', '\n'.join(ordered_labels)), Form.Float('epsilon', 'epsilon', '1e-10'), Form.RadioGroup('matrix_format', 'output matrix format', [ Form.RadioItem('plain_format', 'plain', True), Form.RadioItem('r_format', 'R'), Form.RadioItem('matlab_format', 'MATLAB')])] return form_objects
def get_form(): """ @return: the body of a form """ # define the default tree string tree = get_default_original_tree() formatted_tree_string = NewickIO.get_narrow_newick_string(tree, 60) # define the form objects form_objects = [ Form.MultiLine('tree', 'original tree with branch lengths', formatted_tree_string), Form.Integer('iterations', 'reconstruct this many trees', 10), Form.Integer('length', 'use sequences that are this long', 100), Form.RadioGroup('criterion', 'bipartition function', [ Form.RadioItem('exact', 'exact criterion'), Form.RadioItem('sign', 'spectral sign approximation', True), Form.RadioItem('nj', 'neighbor joining criterion'), Form.RadioItem('random', 'random bipartition') ]) ] return form_objects
def get_form(): """ @return: the body of a form """ # define the default tree string tree = NewickIO.parse(g_default_string, FelTree.NewickTree) formatted_tree_string = NewickIO.get_narrow_newick_string(tree, 60) # define the ordered labels ordered_labels = list('abcxmnpy') # define the form objects form_objects = [ Form.MultiLine('tree', 'newick tree with branch lengths', formatted_tree_string), Form.MultiLine('labels', 'ordered labels', '\n'.join(ordered_labels)), Form.Float('epsilon', 'epsilon', '1e-10'), Form.RadioGroup('matrix_format', 'output matrix format', [ Form.RadioItem('plain_format', 'plain', True), Form.RadioItem('r_format', 'R'), Form.RadioItem('matlab_format', 'MATLAB')])] return form_objects
def get_form(): """ @return: the body of a form """ # Define the default tree string with branch lengths # and named internal nodes. tree_string = '(a:2, (b:2, c:9)g:4, ((d:1, e:3)i:7, f:2)j:1)h;' tree = NewickIO.parse(tree_string, FelTree.NewickTree) formatted_tree_string = NewickIO.get_narrow_newick_string(tree, 60) # define the form objects form_objects = [ Form.MultiLine('tree', 'newick tree with branch lengths', formatted_tree_string), Form.Float('scaling_factor', 'show Laplacian matrices scaled by this amount', 13320), Form.RadioGroup('matrix_format', 'matrix format', [ Form.RadioItem('plain_matrix', 'plain', True), Form.RadioItem('latex_matrix', 'LaTeX') ]) ] return form_objects
def get_response_content(fs): # read the tree tree = NewickIO.parse(fs.tree, Newick.NewickTree) # begin the response out = StringIO() # remove the branch length associated with the root if tree.get_root().blen is not None: print >> out, 'the root originally had a branch length of', tree.get_root( ).blen tree.get_root().blen = None else: print >> out, 'the root did not originally have a branch length' # force a trifurcation at the root if tree.get_root().get_child_count() < 3: print >> out, 'the original root had', tree.get_root().get_child_count( ), 'children' max_children, best_child = max( (child.get_child_count(), child) for child in tree.get_root().gen_children()) old_root = tree.get_root() tree.reroot(best_child) tree.remove_node(old_root) print >> out, 'the new root has', tree.get_root().get_child_count( ), 'children' else: print >> out, 'the root has', tree.get_root().get_child_count( ), 'children' # remove names of internal nodes nremoved_names = 0 for node in tree.preorder(): if node.has_children() and node.name is not None: node.name = None nremoved_names += 1 print >> out, 'removed', nremoved_names, 'internal node names' # draw the new formatted newick string after a break print >> out formatted_tree_string = NewickIO.get_narrow_newick_string(tree, 120) print >> out, formatted_tree_string # return the response return out.getvalue()
def get_form(): """ @return: the body of a form """ # define the default distance matrix and the ordered labels # this is from figure two of a paper called why neighbor joining works D = np.array([[0, 2.7, 2.6, 2.6, 2.6, 4.4, 4.4, 4.4], [2.7, 0, 4.4, 4.4, 4.4, 2.6, 2.6, 2.6], [2.6, 4.4, 0, 0.1, 0.4, 2.7, 2.7, 2.7], [2.6, 4.4, 0.1, 0, 0.4, 2.7, 2.7, 2.7], [2.6, 4.4, 0.4, 0.4, 0, 2.7, 2.7, 2.7], [4.4, 2.6, 2.7, 2.7, 2.7, 0, 0.1, 0.4], [4.4, 2.6, 2.7, 2.7, 2.7, 0.1, 0, 0.4], [4.4, 2.6, 2.7, 2.7, 2.7, 0.4, 0.4, 0]]) labels = list('xyabcmnp') # define the default newick tree string tree_string = '(((a, b), c), x, (((m, n), p), y));' tree = NewickIO.parse(tree_string, FelTree.NewickTree) formatted_tree_string = NewickIO.get_narrow_newick_string(tree, 60) # define the form objects form_objects = [ Form.Matrix('matrix', 'perturbed distance matrix', D, MatrixUtil.assert_predistance), Form.MultiLine('labels', 'ordered labels', '\n'.join(labels)), Form.MultiLine('tree', 'original tree (branch lengths optional)', formatted_tree_string), Form.RadioGroup('criterion', 'bipartition function', [ RadioItem('exact', 'exact criterion', True), RadioItem('sign', 'spectral sign approximation'), RadioItem('threshold', 'spectral threshold approximation'), RadioItem('nj', 'neighbor joining criterion') ]), Form.RadioGroup('recourse', 'recourse for degenerate partitions', [ RadioItem('njrecourse', 'neighbor joining', True), RadioItem('halvingrecourse', 'leaf stem length halving') ]) ] return form_objects
def get_form(): """ @return: the body of a form """ # define the default distance matrix and the ordered labels # this is from figure two of a paper called why neighbor joining works D = np.array([ [ 0, 2.7, 2.6, 2.6, 2.6, 4.4, 4.4, 4.4], [2.7, 0, 4.4, 4.4, 4.4, 2.6, 2.6, 2.6], [2.6, 4.4, 0, 0.1, 0.4, 2.7, 2.7, 2.7], [2.6, 4.4, 0.1, 0, 0.4, 2.7, 2.7, 2.7], [2.6, 4.4, 0.4, 0.4, 0, 2.7, 2.7, 2.7], [4.4, 2.6, 2.7, 2.7, 2.7, 0, 0.1, 0.4], [4.4, 2.6, 2.7, 2.7, 2.7, 0.1, 0, 0.4], [4.4, 2.6, 2.7, 2.7, 2.7, 0.4, 0.4, 0]]) labels = list('xyabcmnp') # define the default newick tree string tree_string = '(((a, b), c), x, (((m, n), p), y));' tree = NewickIO.parse(tree_string, FelTree.NewickTree) formatted_tree_string = NewickIO.get_narrow_newick_string(tree, 60) # define the form objects form_objects = [ Form.Matrix('matrix', 'perturbed distance matrix', D, MatrixUtil.assert_predistance), Form.MultiLine('labels', 'ordered labels', '\n'.join(labels)), Form.MultiLine('tree', 'original tree (branch lengths optional)', formatted_tree_string), Form.RadioGroup('criterion', 'bipartition function', [ RadioItem('exact', 'exact criterion', True), RadioItem('sign', 'spectral sign approximation'), RadioItem('threshold', 'spectral threshold approximation'), RadioItem('nj', 'neighbor joining criterion')]), Form.RadioGroup('recourse', 'recourse for degenerate partitions', [ RadioItem('njrecourse', 'neighbor joining', True), RadioItem('halvingrecourse', 'leaf stem length halving')])] return form_objects
def get_form(): """ @return: the body of a form """ # define the default tree string tree = get_default_original_tree() formatted_tree_string = NewickIO.get_narrow_newick_string(tree, 60) # define the form objects form_objects = [ Form.MultiLine("tree", "original tree with branch lengths", formatted_tree_string), Form.Integer("iterations", "reconstruct this many trees", 10), Form.Integer("length", "use sequences that are this long", 100), Form.RadioGroup( "criterion", "bipartition function", [ Form.RadioItem("exact", "exact criterion"), Form.RadioItem("sign", "spectral sign approximation", True), Form.RadioItem("nj", "neighbor joining criterion"), Form.RadioItem("random", "random bipartition"), ], ), ] return form_objects
def get_form(): """ @return: the body of a form """ # define the tree string tree_string = '(((a:0.05, b:0.05):0.15, c:0.2):0.8, x:1.0, (((m:0.05, n:0.05):0.15, p:0.2):0.8, y:1.0):1.0);' tree = NewickIO.parse(tree_string, FelTree.NewickTree) formatted_tree_string = NewickIO.get_narrow_newick_string(tree, 60) # define the object list form_objects = [ Form.MultiLine('tree', 'tree', formatted_tree_string), Form.Integer('sequence_length', 'use sequences that are this long', 100, low=1), Form.RadioGroup('assumption', 'distance matrix sampling model', [ RadioItem('infinite_alleles', 'infinite alleles', True), RadioItem('jukes_cantor', 'Jukes-Cantor model (4 alleles)') ]), Form.RadioGroup('infinity', 'matrices with infinite distances', [ RadioItem('reject_infinity', 'reject these matrices', True), RadioItem('replace_infinity', 'use 20 instead') ]), Form.RadioGroup('zero', 'matrices with zero distances', [ RadioItem('reject_zero', 'reject these matrices'), RadioItem('replace_zero', 'use .00001 instead'), RadioItem('remain_zero', 'use 0 unmodified', True) ]), Form.RadioGroup('criterion', 'tree reconstruction criterion', [ RadioItem('sign', 'spectral sign approximation', True), RadioItem('nj', 'neighbor joining'), RadioItem('random', 'random bipartition') ]) ] # return the object list return form_objects
def get_standard_response(fs): """ @param fs: a FieldStorage object containing the cgi arguments @return: a (response_headers, response_text) pair """ # begin the response out = StringIO() # show a summary of the original data print >> out, 'data summary before removing branches with zero length:' print >> out, len(archaea_names), 'archaea names in the original tree' print >> out, len(bacteria_names), 'bacteria names in the original tree' print >> out, len(eukaryota_names), 'eukaryota names in the original tree' print >> out, len(all_names), 'total names in the original tree' print >> out # get the pruned full tree pruned_full_tree = get_pruned_tree(full_tree) ordered_names = list(node.get_name() for node in pruned_full_tree.gen_tips()) # show a summary of the processed data print >> out, 'data summary after removing branches with zero length:' print >> out, len(ordered_names), 'total names in the processed non-degenerate tree' print >> out # draw the pruned full tree print >> out, 'this is the tree that represents all clades but for which redundant nodes have been pruned:' formatted_tree_string = NewickIO.get_narrow_newick_string(pruned_full_tree, 120) print >> out, formatted_tree_string print >> out # split the distance matrix D = np.array(pruned_full_tree.get_distance_matrix(ordered_names)) L = Euclid.edm_to_laplacian(D) v = BuildTreeTopology.laplacian_to_fiedler(L) eigensplit = BuildTreeTopology.eigenvector_to_split(v) # report the eigendecomposition print >> out, get_eigendecomposition_report(D) # report the clade intersections of sides of the split side_names = [set(ordered_names[i] for i in side) for side in eigensplit] clade_name_pairs = ((archaea_names, 'archaea'), (bacteria_names, 'bacteria'), (eukaryota_names, 'eukaryota')) print >> out, 'clade intersections with each side of the split:' for side, side_name in zip(side_names, ('left', 'right')): for clade, clade_name in clade_name_pairs: if clade & side: print >> out, 'the', side_name, 'side intersects', clade_name print >> out # prepare to do the secondary splits left_indices, right_indices = eigensplit full_label_sets = [set([i]) for i in range(len(ordered_names))] # get a secondary split for index_selection, index_complement in ((left_indices, right_indices), (right_indices, left_indices)): L_s1 = SchurAlgebra.mmerge(L, index_complement) next_label_sets = SchurAlgebra.vmerge(full_label_sets, index_complement) v = BuildTreeTopology.laplacian_to_fiedler(L_s1) left_subindices, right_subindices = BuildTreeTopology.eigenvector_to_split(v) left_sublabels = set() for i in left_subindices: left_sublabels.update(next_label_sets[i]) right_sublabels = set() for i in right_subindices: right_sublabels.update(next_label_sets[i]) left_subnames = set(ordered_names[i] for i in left_sublabels) right_subnames = set(ordered_names[i] for i in right_sublabels) print >> out, 'clade intersections with a subsplit:' for clade, clade_name in clade_name_pairs: if clade & left_subnames: print >> out, 'the left side intersects', clade_name for clade, clade_name in clade_name_pairs: if clade & right_subnames: print >> out, 'the right side intersects', clade_name print >> out # show debug info print >> out, 'archaea names:' print >> out, '\n'.join(x for x in sorted(archaea_names)) print >> out print >> out, 'bacteria names:' print >> out, '\n'.join(x for x in sorted(bacteria_names)) print >> out print >> out, 'eukaryota names:' print >> out, '\n'.join(x for x in sorted(eukaryota_names)) print >> out # return the response response_text = out.getvalue().strip() return [('Content-Type', 'text/plain')], response_text
def get_verbose_summary(self): """ @return: a multiline string """ # begin the response out = StringIO() # show the number of taxa in various domains print >> out, self._get_name_summary() print >> out # show the pruned full tree formatted_tree_string = NewickIO.get_narrow_newick_string( self.pruned_tree, 120) print >> out, 'this is the tree that represents all clades but for which redundant nodes have been pruned:' print >> out, formatted_tree_string print >> out # split the distance matrix D = np.array(self.pruned_tree.get_distance_matrix(self.pruned_names)) L = Euclid.edm_to_laplacian(D) v = BuildTreeTopology.laplacian_to_fiedler(L) eigensplit = BuildTreeTopology.eigenvector_to_split(v) # report the eigendecomposition print >> out, get_eigendecomposition_report(D) print >> out # report the clade intersections of sides of the split side_names = [ set(self.pruned_names[i] for i in side) for side in eigensplit ] print >> out, 'domains represented by each side of the primary split:' print >> out, 'the left side has:\t', ', '.join( self._get_domains(side_names[0])) print >> out, 'the right side has:\t', ', '.join( self._get_domains(side_names[1])) print >> out # prepare to do the secondary splits left_indices, right_indices = eigensplit full_label_sets = [set([i]) for i in range(len(self.pruned_names))] # do the secondary splits for index_selection, index_complement in ((left_indices, right_indices), (right_indices, left_indices)): L_secondary = SchurAlgebra.mmerge(L, index_complement) next_label_sets = SchurAlgebra.vmerge(full_label_sets, index_complement) v = BuildTreeTopology.laplacian_to_fiedler(L_secondary) left_subindices, right_subindices = BuildTreeTopology.eigenvector_to_split( v) left_sublabels = set() for i in left_subindices: left_sublabels.update(next_label_sets[i]) right_sublabels = set() for i in right_subindices: right_sublabels.update(next_label_sets[i]) left_subnames = set(self.pruned_names[i] for i in left_sublabels) right_subnames = set(self.pruned_names[i] for i in right_sublabels) print >> out, 'domains represented by a subsplit:' print >> out, 'the left side has:\t', ', '.join( self._get_domains(left_subnames)) print >> out, 'the right side has:\t', ', '.join( self._get_domains(right_subnames)) print >> out # return the multiline string return out.getvalue().strip()
def get_standard_response(fs): """ @param fs: a FieldStorage object containing the cgi arguments @return: a (response_headers, response_text) pair """ # begin the response out = StringIO() # show a summary of the original data print >> out, 'data summary before removing branches with zero length:' print >> out, len(archaea_names), 'archaea names in the original tree' print >> out, len(bacteria_names), 'bacteria names in the original tree' print >> out, len(eukaryota_names), 'eukaryota names in the original tree' print >> out, len(all_names), 'total names in the original tree' print >> out # get the pruned full tree pruned_full_tree = get_pruned_tree(full_tree) ordered_names = list(node.get_name() for node in pruned_full_tree.gen_tips()) # show a summary of the processed data print >> out, 'data summary after removing branches with zero length:' print >> out, len( ordered_names), 'total names in the processed non-degenerate tree' print >> out # draw the pruned full tree print >> out, 'this is the tree that represents all clades but for which redundant nodes have been pruned:' formatted_tree_string = NewickIO.get_narrow_newick_string( pruned_full_tree, 120) print >> out, formatted_tree_string print >> out # split the distance matrix D = np.array(pruned_full_tree.get_distance_matrix(ordered_names)) L = Euclid.edm_to_laplacian(D) v = BuildTreeTopology.laplacian_to_fiedler(L) eigensplit = BuildTreeTopology.eigenvector_to_split(v) # report the eigendecomposition print >> out, get_eigendecomposition_report(D) # report the clade intersections of sides of the split side_names = [set(ordered_names[i] for i in side) for side in eigensplit] clade_name_pairs = ((archaea_names, 'archaea'), (bacteria_names, 'bacteria'), (eukaryota_names, 'eukaryota')) print >> out, 'clade intersections with each side of the split:' for side, side_name in zip(side_names, ('left', 'right')): for clade, clade_name in clade_name_pairs: if clade & side: print >> out, 'the', side_name, 'side intersects', clade_name print >> out # prepare to do the secondary splits left_indices, right_indices = eigensplit full_label_sets = [set([i]) for i in range(len(ordered_names))] # get a secondary split for index_selection, index_complement in ((left_indices, right_indices), (right_indices, left_indices)): L_s1 = SchurAlgebra.mmerge(L, index_complement) next_label_sets = SchurAlgebra.vmerge(full_label_sets, index_complement) v = BuildTreeTopology.laplacian_to_fiedler(L_s1) left_subindices, right_subindices = BuildTreeTopology.eigenvector_to_split( v) left_sublabels = set() for i in left_subindices: left_sublabels.update(next_label_sets[i]) right_sublabels = set() for i in right_subindices: right_sublabels.update(next_label_sets[i]) left_subnames = set(ordered_names[i] for i in left_sublabels) right_subnames = set(ordered_names[i] for i in right_sublabels) print >> out, 'clade intersections with a subsplit:' for clade, clade_name in clade_name_pairs: if clade & left_subnames: print >> out, 'the left side intersects', clade_name for clade, clade_name in clade_name_pairs: if clade & right_subnames: print >> out, 'the right side intersects', clade_name print >> out # show debug info print >> out, 'archaea names:' print >> out, '\n'.join(x for x in sorted(archaea_names)) print >> out print >> out, 'bacteria names:' print >> out, '\n'.join(x for x in sorted(bacteria_names)) print >> out print >> out, 'eukaryota names:' print >> out, '\n'.join(x for x in sorted(eukaryota_names)) print >> out # return the response response_text = out.getvalue().strip() return [('Content-Type', 'text/plain')], response_text
def get_response_content(fs): # start writing the html response out = StringIO() print >> out, '<html>' print >> out, '<body>' # get the tree and the column sent by the user pruned_tree, taxon_to_aa_letter = get_tree_and_column(fs) # get the weights of the taxa taxon_weight_pairs = LeafWeights.get_stone_weights(pruned_tree) # show the raw physicochemical property table if fs.show_raw_pc_table: print >> out, 'raw physicochemical property table:' print >> out, '<br/>' col_labels = MAPP.g_property_names row_labels = Codon.g_aa_letters table = MAPP.g_property_array print >> out, HtmlTable.get_labeled_table_string( col_labels, row_labels, table) print >> out, '<br/><br/>' # calculate the standardized physicochemical property table standardized_property_array = MAPP.get_standardized_property_array( MAPP.g_property_array) # show the standardized physicochemical property table if fs.show_standardized_pc_table: print >> out, 'standardized physicochemical property table:' print >> out, '<br/>' col_labels = MAPP.g_property_names row_labels = Codon.g_aa_letters table = standardized_property_array print >> out, HtmlTable.get_labeled_table_string( col_labels, row_labels, table) print >> out, '<br/><br/>' # calculate the physicochemical property correlation matrix correlation_matrix = MAPP.get_property_correlation_matrix( standardized_property_array) # show the physicochemical property correlation matrix if fs.show_pc_correlation_matrix: print >> out, 'physicochemical property correlation matrix:' print >> out, '<br/>' col_labels = MAPP.g_property_names row_labels = MAPP.g_property_names table = correlation_matrix print >> out, HtmlTable.get_labeled_table_string( col_labels, row_labels, table) print >> out, '<br/><br/>' # show the pruned tree if fs.show_tree: tree_string = NewickIO.get_narrow_newick_string(pruned_tree, 80) lines = StringIO(tree_string).readlines() lines = [line.rstrip() for line in lines] print >> out, 'pruned phylogenetic tree in newick format:' print >> out, '<pre>' for line in lines: print >> out, cgi.escape(line) print >> out, '</pre>' print >> out, '<br/>' # show the weights if fs.show_weights: taxa, weights = zip(*taxon_weight_pairs) table = [weights] row_labels = ['weight'] col_labels = taxa print >> out, 'taxon weights:' print >> out, '<br/>' print >> out, HtmlTable.get_labeled_table_string( col_labels, row_labels, table) print >> out, '<br/><br/>' # estimate the amino acid distribution for the column, # taking into account the tree and a uniform prior. weights = [] aa_indices = [] for taxon, weight in taxon_weight_pairs: weights.append(weight) aa_indices.append(aa_letter_to_aa_index(taxon_to_aa_letter[taxon])) aa_distribution = MAPP.estimate_aa_distribution(weights, aa_indices) # show the estimated amino acid distribution if fs.show_aa_distribution: table = [aa_distribution] row_labels = ['weight'] col_labels = Codon.g_aa_letters print >> out, 'estimated amino acid distribution:' print >> out, '<br/>' print >> out, HtmlTable.get_labeled_table_string( col_labels, row_labels, table) print >> out, '<br/><br/>' # estimate the mean and variance of each physicochemical property est_pc_means = MAPP.estimate_property_means( standardized_property_array, aa_distribution) est_pc_variances = MAPP.estimate_property_variances( standardized_property_array, aa_distribution) # show the estimated mean and variance of each physicochemical property if fs.show_pc_distribution: table = [est_pc_means, est_pc_variances] row_labels = ['mean', 'variance'] col_labels = MAPP.g_property_names print >> out, 'estimated physicochemical property moments:' print >> out, '<br/>' print >> out, HtmlTable.get_labeled_table_string( col_labels, row_labels, table) print >> out, '<br/><br/>' # calculate the deviation from each property mean # for each possible amino acid deviations = MAPP.get_deviations( est_pc_means, est_pc_variances, standardized_property_array) # show the deviation from each property mean for each possible amino acid if fs.show_deviations: print >> out, 'deviations of amino acids from the normal distribution' print >> out, 'estimated for each property:' print >> out, '<br/>' col_labels = MAPP.g_property_names row_labels = Codon.g_aa_letters table = deviations print >> out, HtmlTable.get_labeled_table_string( col_labels, row_labels, table) print >> out, '<br/><br/>' # calculate the impact scores impact_scores = MAPP.get_impact_scores(correlation_matrix, deviations) # show the impact scores if fs.show_impact_scores: table = [impact_scores] row_labels = ['impact'] col_labels = Codon.g_aa_letters print >> out, 'impact scores:' print >> out, '<br/>' print >> out, HtmlTable.get_labeled_table_string( col_labels, row_labels, table) print >> out, '<br/><br/>' # calculate the p-values p_values = [] for score in impact_scores: ntaxa = len(taxon_weight_pairs) p_values.append(MAPP.get_p_value(score, ntaxa)) # show the p-values if fs.show_p_values: table = [p_values] row_labels = ['p-value'] col_labels = Codon.g_aa_letters print >> out, 'p-values:' print >> out, '<br/>' print >> out, HtmlTable.get_labeled_table_string( col_labels, row_labels, table) print >> out, '<br/><br/>' # write the html footer print >> out, '</body>' print >> out, '</html>' # return the response return out.getvalue()
def get_response_content(fs): # start writing the html response out = StringIO() print >> out, '<html>' print >> out, '<body>' # get the tree and the column sent by the user pruned_tree, taxon_to_aa_letter = get_tree_and_column(fs) # get the weights of the taxa taxon_weight_pairs = LeafWeights.get_stone_weights(pruned_tree) # show the raw physicochemical property table if fs.show_raw_pc_table: print >> out, 'raw physicochemical property table:' print >> out, '<br/>' col_labels = MAPP.g_property_names row_labels = Codon.g_aa_letters table = MAPP.g_property_array print >> out, HtmlTable.get_labeled_table_string( col_labels, row_labels, table) print >> out, '<br/><br/>' # calculate the standardized physicochemical property table standardized_property_array = MAPP.get_standardized_property_array( MAPP.g_property_array) # show the standardized physicochemical property table if fs.show_standardized_pc_table: print >> out, 'standardized physicochemical property table:' print >> out, '<br/>' col_labels = MAPP.g_property_names row_labels = Codon.g_aa_letters table = standardized_property_array print >> out, HtmlTable.get_labeled_table_string( col_labels, row_labels, table) print >> out, '<br/><br/>' # calculate the physicochemical property correlation matrix correlation_matrix = MAPP.get_property_correlation_matrix( standardized_property_array) # show the physicochemical property correlation matrix if fs.show_pc_correlation_matrix: print >> out, 'physicochemical property correlation matrix:' print >> out, '<br/>' col_labels = MAPP.g_property_names row_labels = MAPP.g_property_names table = correlation_matrix print >> out, HtmlTable.get_labeled_table_string( col_labels, row_labels, table) print >> out, '<br/><br/>' # show the pruned tree if fs.show_tree: tree_string = NewickIO.get_narrow_newick_string(pruned_tree, 80) lines = StringIO(tree_string).readlines() lines = [line.rstrip() for line in lines] print >> out, 'pruned phylogenetic tree in newick format:' print >> out, '<pre>' for line in lines: print >> out, cgi.escape(line) print >> out, '</pre>' print >> out, '<br/>' # show the weights if fs.show_weights: taxa, weights = zip(*taxon_weight_pairs) table = [weights] row_labels = ['weight'] col_labels = taxa print >> out, 'taxon weights:' print >> out, '<br/>' print >> out, HtmlTable.get_labeled_table_string( col_labels, row_labels, table) print >> out, '<br/><br/>' # estimate the amino acid distribution for the column, # taking into account the tree and a uniform prior. weights = [] aa_indices = [] for taxon, weight in taxon_weight_pairs: weights.append(weight) aa_indices.append(aa_letter_to_aa_index(taxon_to_aa_letter[taxon])) aa_distribution = MAPP.estimate_aa_distribution(weights, aa_indices) # show the estimated amino acid distribution if fs.show_aa_distribution: table = [aa_distribution] row_labels = ['weight'] col_labels = Codon.g_aa_letters print >> out, 'estimated amino acid distribution:' print >> out, '<br/>' print >> out, HtmlTable.get_labeled_table_string( col_labels, row_labels, table) print >> out, '<br/><br/>' # estimate the mean and variance of each physicochemical property est_pc_means = MAPP.estimate_property_means(standardized_property_array, aa_distribution) est_pc_variances = MAPP.estimate_property_variances( standardized_property_array, aa_distribution) # show the estimated mean and variance of each physicochemical property if fs.show_pc_distribution: table = [est_pc_means, est_pc_variances] row_labels = ['mean', 'variance'] col_labels = MAPP.g_property_names print >> out, 'estimated physicochemical property moments:' print >> out, '<br/>' print >> out, HtmlTable.get_labeled_table_string( col_labels, row_labels, table) print >> out, '<br/><br/>' # calculate the deviation from each property mean # for each possible amino acid deviations = MAPP.get_deviations(est_pc_means, est_pc_variances, standardized_property_array) # show the deviation from each property mean for each possible amino acid if fs.show_deviations: print >> out, 'deviations of amino acids from the normal distribution' print >> out, 'estimated for each property:' print >> out, '<br/>' col_labels = MAPP.g_property_names row_labels = Codon.g_aa_letters table = deviations print >> out, HtmlTable.get_labeled_table_string( col_labels, row_labels, table) print >> out, '<br/><br/>' # calculate the impact scores impact_scores = MAPP.get_impact_scores(correlation_matrix, deviations) # show the impact scores if fs.show_impact_scores: table = [impact_scores] row_labels = ['impact'] col_labels = Codon.g_aa_letters print >> out, 'impact scores:' print >> out, '<br/>' print >> out, HtmlTable.get_labeled_table_string( col_labels, row_labels, table) print >> out, '<br/><br/>' # calculate the p-values p_values = [] for score in impact_scores: ntaxa = len(taxon_weight_pairs) p_values.append(MAPP.get_p_value(score, ntaxa)) # show the p-values if fs.show_p_values: table = [p_values] row_labels = ['p-value'] col_labels = Codon.g_aa_letters print >> out, 'p-values:' print >> out, '<br/>' print >> out, HtmlTable.get_labeled_table_string( col_labels, row_labels, table) print >> out, '<br/><br/>' # write the html footer print >> out, '</body>' print >> out, '</html>' # return the response return out.getvalue()
def get_response_content(fs): # read the tree tree = NewickIO.parse(fs.tree, Newick.NewickTree) # begin the response out = StringIO() # remove the branch length associated with the root if tree.get_root().blen is not None: print >> out, 'the root originally had a branch length of', tree.get_root().blen tree.get_root().blen = None else: print >> out, 'the root did not originally have a branch length' # force a trifurcation at the root if tree.get_root().get_child_count() < 3: print >> out, 'the original root had', tree.get_root().get_child_count(), 'children' max_children, best_child = max((child.get_child_count(), child) for child in tree.get_root().gen_children()) old_root = tree.get_root() tree.reroot(best_child) tree.remove_node(old_root) print >> out, 'the new root has', tree.get_root().get_child_count(), 'children' else: print >> out, 'the root has', tree.get_root().get_child_count(), 'children' # remove names of internal nodes nremoved_names = 0 for node in tree.preorder(): if node.has_children() and node.name is not None: node.name = None nremoved_names += 1 print >> out, 'removed', nremoved_names, 'internal node names' # draw the new formatted newick string after a break print >> out formatted_tree_string = NewickIO.get_narrow_newick_string(tree, 120) print >> out, formatted_tree_string # return the response return out.getvalue()