def test_get_logo_alt_input_type(self): """copes with positions with no values""" data = [ {"A": 0.1, "C": 0.3, "G": 0.5, "T": 0.1}, {"A": 0.05, "C": 0.8, "G": 0.05, "T": 0.1}, {"A": 0.0, "C": 0.0, "G": 0.0, "T": 0.0}, {"A": 0.7, "C": 0.1, "G": 0.1, "T": 0.1}, {"A": 0.6, "C": 0.15, "G": 0.05, "T": 0.2}, ] d = get_logo(data) data[-2] = {} d = get_logo(data)
def test_get_logo_missing(self): """copes with positions with no values""" data = [ [0.1, 0.3, 0.5, 0.1], [0.05, 0.8, 0.05, 0.1], [0, 0, 0, 0], [0.7, 0.1, 0.1, 0.1], [0.6, 0.15, 0.05, 0.2], ] data = DictArrayTemplate(5, "ACGT").wrap(data) d = get_logo(data)
def test_get_logo(self): """returns Drawable""" data = [ [0.1, 0.3, 0.5, 0.1], [0.25, 0.25, 0.25, 0.25], [0.05, 0.8, 0.05, 0.1], [0.7, 0.1, 0.1, 0.1], [0.6, 0.15, 0.05, 0.2], ] data = DictArrayTemplate(5, "ACGT").wrap(data) d = get_logo(data)
def logo(self, height=400, width=800, wrap=None, ylim=None, vspace=0.05, colours=None): """returns a sequence logo Drawable""" from cogent3.draw.drawable import get_domain from cogent3.draw.logo import get_logo, get_mi_char_heights assert 0 <= vspace <= 1, f"{vspace} not in range 0-1" if ylim is None: ylim = -numpy.log2(1 / self.shape[1]) * 1.1 if wrap is None: mit = get_mi_char_heights(self) logo = get_logo(mit, height=height, width=width, ylim=ylim, colours=colours) return logo wrap = min(wrap, self.shape[0]) rows, remainder = divmod(self.shape[0], wrap) num_rows = rows + 1 if remainder else rows axnum = 1 logo = None xlim_text = { "showarrow": False, "text": "Position", "x": None, "xanchor": "center", "xref": None, "y": 0, "yshift": 2, "yanchor": "bottom", "yref": None, } for i in range(0, self.shape[0], wrap): axis = "axis" if axnum == 1 else f"axis{axnum}" ydomain = get_domain(num_rows, axnum - 1, is_y=True, space=vspace) segment = self[i:i + wrap, :] mit = get_mi_char_heights(segment) sublogo = get_logo( mit, height=height, width=width, axnum=axnum, ydomain=ydomain, ylim=ylim, colours=colours, ) xtick_vals = [j for j in range(0, segment.shape[0], 20)] xtick_text = [f"{i + j}" for j in range(0, segment.shape[0], 20)] sublogo.layout[f"x{axis}"].showticklabels = False sublogo.layout[f"x{axis}"].domain = [0, segment.shape[0] / wrap] # place the row limit x-coord xtext = xlim_text.copy() xtext["text"] = f"{i + segment.shape[0]}" xtext["x"] = segment.shape[0] + 1 xtext["xref"] = f"x{'' if axnum == 1 else axnum}" xtext["yref"] = f"y{'' if axnum == 1 else axnum}" sublogo.layout.annotations = [xtext] if logo is None: logo = sublogo else: logo.layout.shapes.extend(sublogo.layout.shapes) logo.layout.annotations.extend(sublogo.layout.annotations) logo.layout[f"x{axis}"] = sublogo.layout[f"x{axis}"] logo.layout[f"y{axis}"] = sublogo.layout[f"y{axis}"] axnum += 1 return logo