コード例 #1
0
 def test_plot_from_seq_and_struct(self):
     """plot_from_seq_and_struct helper function should give correct result.
     """
     ps_plot = plot_from_seq_and_struct(self.standard_seq,\
         self.standard_struct, seqname=self.standard_name)
     observed_lines = ps_plot.split('\n')
     expected_lines = RNAPLOT_RES.split('\n')
     #First 8 lines depend on the runtime.  Check after.
     self.assertEqual(observed_lines[8:], expected_lines[8:])
コード例 #2
0
 def test_plot_from_seq_and_struct(self):
     """plot_from_seq_and_struct helper function should give correct result.
     """
     ps_plot = plot_from_seq_and_struct(self.standard_seq,\
         self.standard_struct, seqname=self.standard_name)
     observed_lines = ps_plot.split('\n')
     expected_lines = RNAPLOT_RES.split('\n')
     #First 8 lines depend on the runtime.  Check after.
     self.assertEqual(observed_lines[8:],expected_lines[8:])
コード例 #3
0
ファイル: rna_struct.py プロジェクト: pombredanne/pycogent-1
def get_rnaplot_postscript(sequence, struct):
    """Returns postscript string for seq and struct.
    """
    # Params for RNAplot
    params = {"-t": "0", "--pre": "%PreTextHere"}

    # Get the postscript list
    ps_list = plot_from_seq_and_struct(sequence, struct, params=params).split("\n")

    # parse it into prefix and suffix lists
    pre_finder = LabeledRecordFinder(is_label_line=lambda x: x.startswith("%PreTextHere"))
    prefix, suffix = list(pre_finder(ps_list))

    # Remove drawoutline and drawpairs commands form suffix
    new_suffix = []
    for s in suffix:
        if not (s.startswith("drawpairs") or s.startswith("drawoutline")):
            new_suffix.append(s)

    return "\n".join(prefix), "\n".join(new_suffix)
コード例 #4
0
def get_rnaplot_postscript(sequence, struct):
    """Returns postscript string for seq and struct.
    """
    #Params for RNAplot
    params = {'-t':'0',\
              '--pre':'%PreTextHere'}

    #Get the postscript list
    ps_list = plot_from_seq_and_struct(sequence,\
        struct,params=params).split('\n')
    
    #parse it into prefix and suffix lists
    pre_finder = LabeledRecordFinder(\
        is_label_line=lambda x: x.startswith('%PreTextHere'))
    prefix,suffix = list(pre_finder(ps_list))
    
    #Remove drawoutline and drawpairs commands form suffix
    new_suffix = []
    for s in suffix:
        if not (s.startswith('drawpairs') or s.startswith('drawoutline')):
            new_suffix.append(s)
    
    return '\n'.join(prefix), '\n'.join(new_suffix)
コード例 #5
0
ファイル: rna_struct.py プロジェクト: GavinHuttley/pycogent
def get_rnaplot_postscript(sequence, struct):
    """Returns postscript string for seq and struct.
    """
    #Params for RNAplot
    params = {'-t':'0',\
              '--pre':'%PreTextHere'}

    #Get the postscript list
    ps_list = plot_from_seq_and_struct(sequence,\
        struct,params=params).split('\n')
    
    #parse it into prefix and suffix lists
    pre_finder = LabeledRecordFinder(\
        is_label_line=lambda x: x.startswith('%PreTextHere'))
    prefix,suffix = list(pre_finder(ps_list))
    
    #Remove drawoutline and drawpairs commands form suffix
    new_suffix = []
    for s in suffix:
        if not (s.startswith('drawpairs') or s.startswith('drawoutline')):
            new_suffix.append(s)
    
    return '\n'.join(prefix), '\n'.join(new_suffix)
コード例 #6
0
ファイル: rna_struct.py プロジェクト: pombredanne/pycogent-1
def draw_structure(sequence, struct, indices=None, colors=None, circle_indices=None, square_indices=None, radial=True):
    """Returns a postscript string colored at indices.
        
        sequence: string of sequence characters.
        struct: string of ViennaStructure for sequence.  Must be valid structure
            same length as sequence.
        indices: list of indices in sequence that will be colored as a solid
            circle.
        colors: list of colors, same length as list of indices.
        circle_indices: list of indices in sequence to draw an empty circle 
            around.
        square_indices: list of indices in sequence to draw an empty square
            around.
        radial: draw structue in radial format (default=True).
    """
    seq_len_scale = int(len(sequence) / 50.0)

    if seq_len_scale < 1:
        circle_scale_size = 0.0
        square_scale_size = 0.0
    else:
        # Get circle radius.  Proportional to sequence length
        circle_scale_size = (0.02 / seq_len_scale) / 4.0
        # Get edge size.  Proportional to sequence length
        square_scale_size = (0.03 / seq_len_scale) / 4.0

    circle_radius = 0.02 - circle_scale_size
    square_edge_size = 0.03 - square_scale_size

    if indices is None:
        indices = []
    if colors is None:
        colors = []
    if circle_indices is None:
        circle_indices = []
    if square_indices is None:
        square_indices = []

    if len(indices) != len(colors):
        raise ValueError, "indices and colors must be equal sized lists"

    if radial:
        params = {"-t": "0"}
    else:
        params = {"-t": "1"}
    # Get the postscript list
    ps_list = plot_from_seq_and_struct(sequence, struct, params=params).split("\n")
    # Parse out seq, coords, and pairs
    seq, coords, pair_list = RnaPlotParser(ps_list)
    coords = scale_coords(coords)

    # get letters
    letters = make_letters(coords, list(seq))
    # get pairs
    pairs = make_pairs(coords, pair_list)
    # get outline
    outline = make_outline(coords)
    # get labels
    labels, label_coords = make_labels(coords)

    # get plain circle coords
    circle_coords = [coords[i] for i in circle_indices]
    circle_faces = ["white"] * len(circle_coords)
    circle_edges = ["black"] * len(circle_coords)
    plain_circles = make_circles(circle_coords, circle_faces, circle_edges, radius=circle_radius)

    # get motif circles
    motif_coords = [coords[i] for i in indices]
    motif_circles = make_circles(motif_coords, colors, colors, fill=True, radius=circle_radius)

    # Get square coords
    square_coords = [coords[i] for i in square_indices]
    plain_squares = make_boxes(square_coords, edge_size=square_edge_size)

    axis = gca()
    axis.set_axis_off()

    all_coords = coords + label_coords

    set_axis_limits(axis, all_coords)

    for l in [letters, pairs, outline, motif_circles, plain_circles, plain_squares, labels]:
        for shape in l:
            axis.add_artist(shape)

    fig = gcf()

    largest = max([fig.get_figheight(), fig.get_figwidth()])
    fig.set_figheight(largest)
    fig.set_figwidth(largest)
コード例 #7
0
def draw_structure(sequence,struct,indices=None,colors=None,\
    circle_indices=None, square_indices=None,radial=True):
    """Returns a postscript string colored at indices.
        
        sequence: string of sequence characters.
        struct: string of ViennaStructure for sequence.  Must be valid structure
            same length as sequence.
        indices: list of indices in sequence that will be colored as a solid
            circle.
        colors: list of colors, same length as list of indices.
        circle_indices: list of indices in sequence to draw an empty circle 
            around.
        square_indices: list of indices in sequence to draw an empty square
            around.
        radial: draw structue in radial format (default=True).
    """
    seq_len_scale = int(len(sequence)/50.)
    
    if seq_len_scale < 1:
        circle_scale_size = 0.
        square_scale_size = 0.
    else:
        #Get circle radius.  Proportional to sequence length
        circle_scale_size = (.02/seq_len_scale)/4.0
        #Get edge size.  Proportional to sequence length
        square_scale_size = (.03/seq_len_scale)/4.0
        
    circle_radius = .02 - circle_scale_size
    square_edge_size = .03 - square_scale_size
    
    if indices is None:
        indices = []
    if colors is None:
        colors = []
    if circle_indices is None:
        circle_indices = []
    if square_indices is None:
        square_indices = []
    
    if len(indices) != len(colors):
        raise ValueError, 'indices and colors must be equal sized lists'
    
    if radial:
        params = {'-t':'0'}
    else:
        params = {'-t':'1'}
    #Get the postscript list
    ps_list = plot_from_seq_and_struct(sequence,\
        struct,params=params).split('\n')
    #Parse out seq, coords, and pairs
    seq, coords, pair_list = RnaPlotParser(ps_list)
    coords = scale_coords(coords)
    
    #get letters
    letters = make_letters(coords, list(seq))
    #get pairs
    pairs = make_pairs(coords, pair_list)
    #get outline
    outline = make_outline(coords)
    #get labels
    labels,label_coords = make_labels(coords)


    #get plain circle coords
    circle_coords = [coords[i] for i in circle_indices]
    circle_faces = ['white']*len(circle_coords)
    circle_edges = ['black']*len(circle_coords)
    plain_circles = make_circles(circle_coords,circle_faces, circle_edges,\
        radius=circle_radius)
    
    #get motif circles
    motif_coords = [coords[i] for i in indices]
    motif_circles = make_circles(motif_coords,colors,colors,fill=True,\
        radius=circle_radius)
    
    #Get square coords
    square_coords = [coords[i] for i in square_indices]
    plain_squares = make_boxes(square_coords,edge_size=square_edge_size)
    
    axis = gca()
    axis.set_axis_off()
    
    all_coords = coords + label_coords
    
    set_axis_limits(axis, all_coords)
    
    for l in [letters, pairs, outline, motif_circles, plain_circles, \
        plain_squares,labels]:
        for shape in l:
            axis.add_artist(shape)
    
    fig = gcf()
    
    largest = max([fig.get_figheight(), fig.get_figwidth()])
    fig.set_figheight(largest)
    fig.set_figwidth(largest)