diff --git a/src/hgvs/easy.py b/src/hgvs/easy.py index f9bb8e15..66d82a90 100644 --- a/src/hgvs/easy.py +++ b/src/hgvs/easy.py @@ -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 diff --git a/src/hgvs/pretty/renderer/chrom_seq_renderer.py b/src/hgvs/pretty/console/chrom_seq_renderer.py similarity index 87% rename from src/hgvs/pretty/renderer/chrom_seq_renderer.py rename to src/hgvs/pretty/console/chrom_seq_renderer.py index 8204f518..0278a682 100644 --- a/src/hgvs/pretty/renderer/chrom_seq_renderer.py +++ b/src/hgvs/pretty/console/chrom_seq_renderer.py @@ -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): @@ -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: diff --git a/src/hgvs/pretty/renderer/chrom_seq_reverse_renderer.py b/src/hgvs/pretty/console/chrom_seq_reverse_renderer.py similarity index 88% rename from src/hgvs/pretty/renderer/chrom_seq_reverse_renderer.py rename to src/hgvs/pretty/console/chrom_seq_reverse_renderer.py index 9516a1c0..01effa76 100644 --- a/src/hgvs/pretty/renderer/chrom_seq_reverse_renderer.py +++ b/src/hgvs/pretty/console/chrom_seq_reverse_renderer.py @@ -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): @@ -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: diff --git a/src/hgvs/pretty/console/constants.py b/src/hgvs/pretty/console/constants.py new file mode 100644 index 00000000..7e93ec27 --- /dev/null +++ b/src/hgvs/pretty/console/constants.py @@ -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 \ No newline at end of file diff --git a/src/hgvs/pretty/renderer/pos_info.py b/src/hgvs/pretty/console/pos_info.py similarity index 92% rename from src/hgvs/pretty/renderer/pos_info.py rename to src/hgvs/pretty/console/pos_info.py index 3a0b8f51..a10f2a9f 100644 --- a/src/hgvs/pretty/renderer/pos_info.py +++ b/src/hgvs/pretty/console/pos_info.py @@ -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): diff --git a/src/hgvs/pretty/renderer/prot_mapping_renderer.py b/src/hgvs/pretty/console/prot_mapping_renderer.py similarity index 94% rename from src/hgvs/pretty/renderer/prot_mapping_renderer.py rename to src/hgvs/pretty/console/prot_mapping_renderer.py index decb0243..e4ccf512 100644 --- a/src/hgvs/pretty/renderer/prot_mapping_renderer.py +++ b/src/hgvs/pretty/console/prot_mapping_renderer.py @@ -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): diff --git a/src/hgvs/pretty/renderer/prot_ruler_renderer.py b/src/hgvs/pretty/console/prot_ruler_renderer.py similarity index 95% rename from src/hgvs/pretty/renderer/prot_ruler_renderer.py rename to src/hgvs/pretty/console/prot_ruler_renderer.py index 3bcc48a4..402f7502 100644 --- a/src/hgvs/pretty/renderer/prot_ruler_renderer.py +++ b/src/hgvs/pretty/console/prot_ruler_renderer.py @@ -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): diff --git a/src/hgvs/pretty/renderer/prot_seq_renderer.py b/src/hgvs/pretty/console/prot_seq_renderer.py similarity index 93% rename from src/hgvs/pretty/renderer/prot_seq_renderer.py rename to src/hgvs/pretty/console/prot_seq_renderer.py index 046e9fad..79be30a2 100644 --- a/src/hgvs/pretty/renderer/prot_seq_renderer.py +++ b/src/hgvs/pretty/console/prot_seq_renderer.py @@ -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): @@ -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: diff --git a/src/hgvs/pretty/console/renderer.py b/src/hgvs/pretty/console/renderer.py new file mode 100644 index 00000000..b247c961 --- /dev/null +++ b/src/hgvs/pretty/console/renderer.py @@ -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 diff --git a/src/hgvs/pretty/renderer/ruler.py b/src/hgvs/pretty/console/ruler.py similarity index 92% rename from src/hgvs/pretty/renderer/ruler.py rename to src/hgvs/pretty/console/ruler.py index 3317f605..69b0810e 100644 --- a/src/hgvs/pretty/renderer/ruler.py +++ b/src/hgvs/pretty/console/ruler.py @@ -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): diff --git a/src/hgvs/pretty/renderer/shuffled_variant.py b/src/hgvs/pretty/console/shuffled_variant.py similarity index 94% rename from src/hgvs/pretty/renderer/shuffled_variant.py rename to src/hgvs/pretty/console/shuffled_variant.py index cf652b39..5989ca9c 100644 --- a/src/hgvs/pretty/renderer/shuffled_variant.py +++ b/src/hgvs/pretty/console/shuffled_variant.py @@ -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 @@ -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 diff --git a/src/hgvs/pretty/renderer/tx_alig_renderer.py b/src/hgvs/pretty/console/tx_alig_renderer.py similarity index 95% rename from src/hgvs/pretty/renderer/tx_alig_renderer.py rename to src/hgvs/pretty/console/tx_alig_renderer.py index 90418742..5afb226f 100644 --- a/src/hgvs/pretty/renderer/tx_alig_renderer.py +++ b/src/hgvs/pretty/console/tx_alig_renderer.py @@ -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): @@ -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 = "" diff --git a/src/hgvs/pretty/renderer/tx_mapping_renderer.py b/src/hgvs/pretty/console/tx_mapping_renderer.py similarity index 97% rename from src/hgvs/pretty/renderer/tx_mapping_renderer.py rename to src/hgvs/pretty/console/tx_mapping_renderer.py index 6eb04721..8fd78778 100644 --- a/src/hgvs/pretty/renderer/tx_mapping_renderer.py +++ b/src/hgvs/pretty/console/tx_mapping_renderer.py @@ -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): diff --git a/src/hgvs/pretty/renderer/tx_pos.py b/src/hgvs/pretty/console/tx_pos.py similarity index 95% rename from src/hgvs/pretty/renderer/tx_pos.py rename to src/hgvs/pretty/console/tx_pos.py index a58f0d10..6f9f7097 100644 --- a/src/hgvs/pretty/renderer/tx_pos.py +++ b/src/hgvs/pretty/console/tx_pos.py @@ -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): diff --git a/src/hgvs/pretty/renderer/tx_ref_disagree_renderer.py b/src/hgvs/pretty/console/tx_ref_disagree_renderer.py similarity index 91% rename from src/hgvs/pretty/renderer/tx_ref_disagree_renderer.py rename to src/hgvs/pretty/console/tx_ref_disagree_renderer.py index a729bab6..1fe5177d 100644 --- a/src/hgvs/pretty/renderer/tx_ref_disagree_renderer.py +++ b/src/hgvs/pretty/console/tx_ref_disagree_renderer.py @@ -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): @@ -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 diff --git a/src/hgvs/pretty/datacompiler.py b/src/hgvs/pretty/datacompiler.py index 45e770d2..ae73fb4e 100644 --- a/src/hgvs/pretty/datacompiler.py +++ b/src/hgvs/pretty/datacompiler.py @@ -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 diff --git a/src/hgvs/pretty/models.py b/src/hgvs/pretty/models.py index d3a8cef5..4afaca68 100644 --- a/src/hgvs/pretty/models.py +++ b/src/hgvs/pretty/models.py @@ -94,7 +94,7 @@ class VariantData: @dataclass class PrettyConfig: - """acontainer for various configurations.""" + """A container for various configurations.""" hdp: Interface am37: AssemblyMapper diff --git a/src/hgvs/pretty_print.py b/src/hgvs/pretty/pretty_print.py similarity index 83% rename from src/hgvs/pretty_print.py rename to src/hgvs/pretty/pretty_print.py index adcb1e6d..49b22104 100644 --- a/src/hgvs/pretty_print.py +++ b/src/hgvs/pretty/pretty_print.py @@ -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: @@ -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 @@ -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": @@ -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" diff --git a/src/hgvs/pretty/renderer/renderer.py b/src/hgvs/pretty/renderer/renderer.py deleted file mode 100644 index eab9a816..00000000 --- a/src/hgvs/pretty/renderer/renderer.py +++ /dev/null @@ -1,15 +0,0 @@ -from abc import ABC, abstractmethod - - -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 diff --git a/tests/test_pretty_print.py b/tests/test_pretty_print.py index d94f8633..0cb76f41 100644 --- a/tests/test_pretty_print.py +++ b/tests/test_pretty_print.py @@ -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