def test_get_domain_multi(self): """produces reversed coordinates for y""" # plotly coords are cartesian, index coords are array, so they need to # be converted y = get_domain(2, 0, is_y=True, space=0) assert_allclose(y, [0.5, 1]) y = get_domain(2, 1, is_y=True, space=0) assert_allclose(y, [0, 0.5]) # x-coords unaffected x = get_domain(2, 0, is_y=False, space=0) assert_allclose(x, [0, 0.5]) x = get_domain(2, 1, is_y=False, space=0) assert_allclose(x, [0.5, 1])
def test_get_domain_sep(self): """space argument shifts boundaries""" sep = 0.1 x = get_domain(2, 0, is_y=False, space=sep) assert_allclose(x, [0 + sep / 2, 0.5 - sep / 2]) x = get_domain(2, 1, is_y=False, space=sep) assert_allclose(x, [0.5 + sep / 2, 1 - sep / 2]) # if space too big relative to the span of each domain, it's reduced # to 1/10th the domain span sep = 0.6 x = get_domain(2, 0, is_y=False, space=sep) exp_sep = 0.5 / 10 assert_allclose(x, [0 + exp_sep, 0.5 - exp_sep])
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
def test_domain_element_size(self): """domain element value must not exceed num domains - 1""" with self.assertRaises(ValueError): x = get_domain(2, 2, is_y=False)
def test_get_domain_1(self): """handles single domain""" x = get_domain(1, 0, is_y=False) y = get_domain(1, 0, is_y=True) assert_allclose(x, [0, 1]) assert_allclose(y, [0, 1])