Skip to content

Commit

Permalink
#741 small refactoring to update directory structure, based on PR com…
Browse files Browse the repository at this point in the history
…ments
  • Loading branch information
andreasprlic committed Sep 2, 2024
1 parent bc483b5 commit cf22aae
Show file tree
Hide file tree
Showing 20 changed files with 84 additions and 79 deletions.
2 changes: 1 addition & 1 deletion src/hgvs/easy.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
from hgvs.dataproviders.uta import connect
from hgvs.normalizer import Normalizer
from hgvs.parser import Parser
from hgvs.pretty_print import PrettyPrint
from hgvs.pretty.pretty_print import PrettyPrint
from hgvs.validator import Validator
from hgvs.variantmapper import VariantMapper

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from hgvs.pretty.models import VariantData
from hgvs.pretty.renderer.renderer import BasicRenderer
from hgvs.pretty.console.renderer import BasicRenderer


class ChromSeqRendered(BasicRenderer):
Expand All @@ -9,7 +9,7 @@ def legend(self) -> str:

def display(self, data: VariantData) -> str:
"""colors the ref sequences with adenine (A, green), thymine (T, red), cytosine (C, yellow), and guanine (G, blue)"""
from hgvs.pretty_print import ENDC, TBLUE, TGREEN, TRED, TYELLOW
from hgvs.pretty.pretty_print import ENDC, TBLUE, TGREEN, TRED, TYELLOW

var_seq = ""
for p in data.position_details:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from bioutils.sequences import reverse_complement

from hgvs.pretty.models import VariantData
from hgvs.pretty.renderer.renderer import BasicRenderer
from hgvs.pretty.console.renderer import BasicRenderer


class ChromReverseSeqRendered(BasicRenderer):
Expand All @@ -11,7 +11,7 @@ def legend(self) -> str:

def display(self, data: VariantData) -> str:
"""colors the ref sequences with adenine (A, green), thymine (T, red), cytosine (C, yellow), and guanine (G, blue)"""
from hgvs.pretty_print import ENDC, TBLUE, TGREEN, TRED, TYELLOW
from hgvs.pretty.pretty_print import ENDC, TBLUE, TGREEN, TRED, TYELLOW

var_seq = ""
for p in data.position_details:
Expand Down
14 changes: 14 additions & 0 deletions src/hgvs/pretty/console/constants.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
### Color constants for rendering text on the console

TGREEN = "\033[32m" # Green Text
TGREENBG = "\033[30;42m"
TRED = "\033[31m" # Red Text
TREDBG = "\033[30;41m"
TBLUE = "\033[34m" # Blue Text
TBLUEBG = "\033[30;44m"
TPURPLE = "\033[35m" # Purple Text
TPURPLEBG = "\033[30;45m"
TYELLOW = "\033[33m" # Yellow Text
TYELLOWBG = "\033[30;43m"

ENDC = "\033[m" # reset to the defaults
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from hgvs.pretty.models import VariantData
from hgvs.pretty.renderer.renderer import BasicRenderer
from hgvs.pretty.console.renderer import BasicRenderer


class ChrPositionInfo(BasicRenderer):
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from hgvs.pretty.models import VariantData
from hgvs.pretty.renderer.renderer import BasicRenderer
from hgvs.pretty.console.renderer import BasicRenderer


class ProtMappingRenderer(BasicRenderer):
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from hgvs.pretty.models import VariantData
from hgvs.pretty.renderer.renderer import BasicRenderer
from hgvs.pretty.console.renderer import BasicRenderer


class ProtRulerRenderer(BasicRenderer):
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from hgvs.pretty.models import VariantData
from hgvs.pretty.renderer.renderer import BasicRenderer
from hgvs.pretty.console.renderer import BasicRenderer


class ProtSeqRenderer(BasicRenderer):
Expand All @@ -14,7 +14,7 @@ def display(self, data: VariantData) -> str:
if not data.var_c_or_n:
return ""

from hgvs.pretty_print import ENDC, TGREEN, TRED
from hgvs.pretty.pretty_print import ENDC, TGREEN, TRED

var_str = ""
for pdata in data.position_details:
Expand Down
32 changes: 32 additions & 0 deletions src/hgvs/pretty/console/renderer.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
from abc import ABC, abstractmethod

from hgvs.pretty.console.constants import ENDC, TPURPLE, TYELLOW


def colorize_hgvs(hgvs_str: str) -> str:
""" Takes a string representation of a hgvs Sequence Variant and renders it with console colors.
"""

spl = hgvs_str.split(":")
var_str = TPURPLE + spl[0] + ENDC
var_str += ":"

sec = spl[1].split(".")
var_str += TYELLOW + sec[0] + ENDC
var_str += "."
var_str += sec[1]

return var_str

class BasicRenderer(ABC):
def __init__(self, config, orientation: int):
self.config = config
self.orientation = orientation

@abstractmethod
def legend(self):
pass

@abstractmethod
def display(self):
pass
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from hgvs.pretty.models import VariantData
from hgvs.pretty.renderer.renderer import BasicRenderer
from hgvs.pretty.console.renderer import BasicRenderer


class ChrRuler(BasicRenderer):
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from hgvs.pretty.models import VariantCoords, VariantData
from hgvs.pretty.renderer.renderer import BasicRenderer
from hgvs.pretty.console.renderer import BasicRenderer
from hgvs.sequencevariant import SequenceVariant


Expand All @@ -17,7 +17,7 @@ def legend(self) -> str:

def display(self, data: VariantData) -> str:

from hgvs.pretty_print import ENDC, TBLUE, TGREEN, TRED, TYELLOW
from hgvs.pretty.pretty_print import ENDC, TBLUE, TGREEN, TRED, TYELLOW

seq_start = data.display_start
seq_end = data.display_end
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import math

from hgvs.pretty.models import VariantData
from hgvs.pretty.renderer.renderer import BasicRenderer
from hgvs.pretty.console.renderer import BasicRenderer


class TxAligRenderer(BasicRenderer):
Expand All @@ -17,7 +17,7 @@ def display(self, data: VariantData) -> str:
if not data.var_c_or_n:
return ""

from hgvs.pretty_print import ENDC, TPURPLE, TYELLOW
from hgvs.pretty.pretty_print import ENDC, TPURPLE, TYELLOW

var_str = ""

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from hgvs.pretty.models import VariantData
from hgvs.pretty.renderer.renderer import BasicRenderer
from hgvs.pretty.console.renderer import BasicRenderer


class TxMappingRenderer(BasicRenderer):
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from hgvs.pretty.models import VariantData
from hgvs.pretty.renderer.renderer import BasicRenderer
from hgvs.pretty.console.renderer import BasicRenderer


class TxRulerRenderer(BasicRenderer):
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from hgvs.pretty.models import VariantData
from hgvs.pretty.renderer.renderer import BasicRenderer
from hgvs.pretty.console.renderer import BasicRenderer


class TxRefDisagreeRenderer(BasicRenderer):
Expand All @@ -15,7 +15,7 @@ def display(self, data: VariantData) -> str:
if not data.var_c_or_n:
return ""

from hgvs.pretty_print import ENDC, TRED
from hgvs.pretty.pretty_print import ENDC, TRED

var_str = ""
counter = -1
Expand Down
2 changes: 1 addition & 1 deletion src/hgvs/pretty/datacompiler.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import List, Optional, Tuple
from typing import List, Tuple

from bioutils.normalize import normalize
from bioutils.sequences import aa1_to_aa3_lut
Expand Down
2 changes: 1 addition & 1 deletion src/hgvs/pretty/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ class VariantData:

@dataclass
class PrettyConfig:
"""acontainer for various configurations."""
"""A container for various configurations."""

hdp: Interface
am37: AssemblyMapper
Expand Down
56 changes: 16 additions & 40 deletions src/hgvs/pretty_print.py → src/hgvs/pretty/pretty_print.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,35 +2,25 @@

import hgvs
from hgvs.assemblymapper import AssemblyMapper
from hgvs.pretty.console.renderer import colorize_hgvs
from hgvs.pretty.datacompiler import DataCompiler
from hgvs.pretty.models import PrettyConfig
from hgvs.pretty.renderer.chrom_seq_renderer import ChromSeqRendered
from hgvs.pretty.renderer.chrom_seq_reverse_renderer import ChromReverseSeqRendered
from hgvs.pretty.renderer.pos_info import ChrPositionInfo
from hgvs.pretty.renderer.prot_mapping_renderer import ProtMappingRenderer
from hgvs.pretty.renderer.prot_ruler_renderer import ProtRulerRenderer
from hgvs.pretty.renderer.prot_seq_renderer import ProtSeqRenderer
from hgvs.pretty.renderer.ruler import ChrRuler
from hgvs.pretty.renderer.shuffled_variant import ShuffledVariant
from hgvs.pretty.renderer.tx_alig_renderer import TxAligRenderer
from hgvs.pretty.renderer.tx_mapping_renderer import TxMappingRenderer
from hgvs.pretty.renderer.tx_pos import TxRulerRenderer
from hgvs.pretty.renderer.tx_ref_disagree_renderer import TxRefDisagreeRenderer
from hgvs.pretty.console.chrom_seq_renderer import ChromSeqRendered
from hgvs.pretty.console.chrom_seq_reverse_renderer import ChromReverseSeqRendered
from hgvs.pretty.console.pos_info import ChrPositionInfo
from hgvs.pretty.console.prot_mapping_renderer import ProtMappingRenderer
from hgvs.pretty.console.prot_ruler_renderer import ProtRulerRenderer
from hgvs.pretty.console.prot_seq_renderer import ProtSeqRenderer
from hgvs.pretty.console.ruler import ChrRuler
from hgvs.pretty.console.shuffled_variant import ShuffledVariant
from hgvs.pretty.console.tx_alig_renderer import TxAligRenderer
from hgvs.pretty.console.tx_mapping_renderer import TxMappingRenderer
from hgvs.pretty.console.tx_pos import TxRulerRenderer
from hgvs.pretty.console.tx_ref_disagree_renderer import TxRefDisagreeRenderer
from hgvs.repeats import RepeatAnalyser
from hgvs.sequencevariant import SequenceVariant

TGREEN = "\033[32m" # Green Text
TGREENBG = "\033[30;42m"
TRED = "\033[31m" # Red Text
TREDBG = "\033[30;41m"
TBLUE = "\033[34m" # Blue Text
TBLUEBG = "\033[30;44m"
TPURPLE = "\033[35m" # Purple Text
TPURPLEBG = "\033[30;45m"
TYELLOW = "\033[33m" # Yellow Text
TYELLOWBG = "\033[30;43m"

ENDC = "\033[m" # reset to the defaults


class PrettyPrint:
Expand Down Expand Up @@ -117,20 +107,6 @@ def _map_to_chrom(self, sv: SequenceVariant) -> SequenceVariant:
elif sv.type == "t":
return am.t_to_g(sv)

def _colorize_hgvs(self, hgvs_str: str) -> str:
if not self.config.useColor:
return hgvs_str

spl = hgvs_str.split(":")
var_str = TPURPLE + spl[0] + ENDC
var_str += ":"

sec = spl[1].split(".")
var_str += TYELLOW + sec[0] + ENDC
var_str += "."
var_str += sec[1]

return var_str

def get_hgvs_names(
self, sv: SequenceVariant, tx_ac: str = None
Expand Down Expand Up @@ -210,14 +186,14 @@ def create_repre(
head = head_c = head_p = refa = ""

if self.config.useColor:
var_g_print = self._colorize_hgvs(str(var_g))
var_g_print = colorize_hgvs(str(var_g))
else:
var_g_print = str(var_g)

var_str = head + var_g_print + "\n"
if data.var_c_or_n:
if self.config.useColor:
var_c_print = self._colorize_hgvs(str(var_c_or_n))
var_c_print = colorize_hgvs(str(var_c_or_n))
else:
var_c_print = str(var_c_or_n)
if data.var_c_or_n.type == "c":
Expand All @@ -228,7 +204,7 @@ def create_repre(

if data.var_p:
if self.config.useColor:
var_p_print = self._colorize_hgvs(str(data.var_p))
var_p_print = colorize_hgvs(str(data.var_p))
else:
var_p_print = str(data.var_p)
var_str += head_p + var_p_print + "\n"
Expand Down
15 changes: 0 additions & 15 deletions src/hgvs/pretty/renderer/renderer.py

This file was deleted.

4 changes: 1 addition & 3 deletions tests/test_pretty_print.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
# -*- coding: utf-8 -*-
import os
import unittest

import pytest
from support import CACHE

import hgvs
from hgvs.pretty_print import PrettyPrint
from hgvs.pretty.pretty_print import PrettyPrint


@pytest.mark.quick
Expand Down

0 comments on commit cf22aae

Please sign in to comment.