Skip to content

Commit

Permalink
feat(cleanup): removing cache from test_repeats. They are creating to…
Browse files Browse the repository at this point in the history
…o big of a cache.
  • Loading branch information
andreasprlic committed Jul 1, 2024
1 parent a31cd26 commit 30addf2
Show file tree
Hide file tree
Showing 8 changed files with 72 additions and 73 deletions.
4 changes: 2 additions & 2 deletions src/hgvs/pretty/datacompiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ def data(
seq_end = display_end

if var_c_or_n is not None:
tx_ac = var_c_or_n.ac
tx_ac = var_c_or_n.ac
else:
tx_ac = "" # can't show transcript , since there is none.

Expand Down Expand Up @@ -228,7 +228,7 @@ def data(
var_p = None
reference_data = None

position_details:List[PositionDetail] = []
position_details: List[PositionDetail] = []
prev_mapped_pos = None
prev_c_pos = -1
prev_n_pos = -1
Expand Down
10 changes: 4 additions & 6 deletions src/hgvs/pretty/renderer/prot_mapping_renderer.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,20 @@ def display(self, data: VariantData) -> str:

var_str = ""

count = -1
count = -1
for pdata in data.position_details:
count += 1
if not pdata.mapped_pos:
var_str += " "
var_str += " "
continue

prot_data = pdata.protein_data

if not prot_data or prot_data.aa_pos < 0:
var_str +=" "
var_str += " "
continue


if len(var_str) > count:
if len(var_str) > count:
continue

aa_pos = prot_data.aa_pos
Expand All @@ -39,7 +38,6 @@ def display(self, data: VariantData) -> str:
var_str += "."
continue


var_str += " "

return var_str
7 changes: 3 additions & 4 deletions src/hgvs/pretty/renderer/prot_ruler_renderer.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,19 +28,18 @@ def display(self, data: VariantData) -> str:
prev_aa = -1
continue


if len(var_str) > count:
continue

aa_pos = prot_data.aa_pos

if aa_pos == prev_aa :
var_str += ' '
if aa_pos == prev_aa:
var_str += " "
continue

prev_aa = aa_pos

if (aa_pos + 1) % 10 == 0:
if (aa_pos + 1) % 10 == 0:
var_str += f"{aa_pos+1} "
continue

Expand Down
6 changes: 3 additions & 3 deletions src/hgvs/pretty/renderer/tx_alig_renderer.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,11 @@ def display(self, data: VariantData) -> str:

coding = True

if cig == "=":
if cig == "=":
if c_pos:
bg_col = math.ceil((c_pos+1) / 3) % 2
bg_col = math.ceil((c_pos + 1) / 3) % 2
elif n_pos:
bg_col = math.ceil((n_pos+1) / 3) % 2
bg_col = math.ceil((n_pos + 1) / 3) % 2
else:
var_str += " "
continue
Expand Down
35 changes: 23 additions & 12 deletions src/hgvs/pretty_print.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@
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.sequencevariant import SequenceVariant
from hgvs.repeats import RepeatAnalyser
from hgvs.sequencevariant import SequenceVariant

TGREEN = "\033[32m" # Green Text
TGREENBG = "\033[30;42m"
TRED = "\033[31m" # Red Text
Expand Down Expand Up @@ -131,9 +132,10 @@ def _colorize_hgvs(self, hgvs_str: str) -> str:

return var_str

def get_hgvs_names(
self, sv: SequenceVariant, tx_ac: str = None
) -> Tuple[SequenceVariant, SequenceVariant]:

def get_hgvs_names(self, sv: SequenceVariant, tx_ac:str =None)->Tuple[SequenceVariant, SequenceVariant]:

var_c_or_n = None
if sv.type == "g":
var_g = sv
Expand All @@ -146,7 +148,7 @@ def get_hgvs_names(self, sv: SequenceVariant, tx_ac:str =None)->Tuple[SequenceVa
# map back to genome
var_g = self._map_to_chrom(sv)
var_c_or_n = sv

return var_g, var_c_or_n

def display(
Expand All @@ -158,7 +160,7 @@ def display(
) -> str:
"""Takes a variant and prints the genomic context around it."""

var_g, var_c_or_n = self.get_hgvs_names(sv,tx_ac)
var_g, var_c_or_n = self.get_hgvs_names(sv, tx_ac)

self.data_compiler = DataCompiler(config=self.config)

Expand All @@ -180,7 +182,9 @@ def display(
if self.config.infer_hgvs_c:
var_c_or_n = self._infer_hgvs_c(var_g)

return self.create_repre(var_g, var_c_or_n, display_start, display_end, self.data_compiler)
return self.create_repre(
var_g, var_c_or_n, display_start, display_end, self.data_compiler
)

def create_repre(
self,
Expand All @@ -197,7 +201,7 @@ def create_repre(
fully_justified_var = data.fully_justified

if self.config.showLegend:
head = "hgvs_g : "
head = "hgvs_g : "
head_c = "hgvs_c : "
head_n = "hgvs_n : "
head_p = "hgvs_p : "
Expand All @@ -216,9 +220,9 @@ def create_repre(
var_c_print = self._colorize_hgvs(str(var_c_or_n))
else:
var_c_print = str(var_c_or_n)
if data.var_c_or_n.type == 'c':
var_str += head_c
elif data.var_c_or_n.type == 'n':
if data.var_c_or_n.type == "c":
var_str += head_c
elif data.var_c_or_n.type == "n":
var_str += head_n
var_str += var_c_print + "\n"

Expand Down Expand Up @@ -268,15 +272,22 @@ def create_repre(
)
fully_justified_str = fully_justified_renderer.display(data)

if self.config.showAllShuffleableRegions :
if self.config.showAllShuffleableRegions:
var_str += shuffled_seq_header + left_shuffled_str + "\n"
var_str += shuffled_seq_header + right_shuffled_str + "\n"
var_str += shuffled_seq_header + fully_justified_str + "\n"

else:
var_str += shuffled_seq_header + left_shuffled_str + "\n"

renderers_cls = [TxAligRenderer, TxMappingRenderer, TxRulerRenderer, ProtSeqRenderer, ProtMappingRenderer, ProtRulerRenderer ]
renderers_cls = [
TxAligRenderer,
TxMappingRenderer,
TxRulerRenderer,
ProtSeqRenderer,
ProtMappingRenderer,
ProtRulerRenderer,
]
for cls in renderers_cls:
renderer = cls(self.config, data.strand)

Expand Down
6 changes: 3 additions & 3 deletions src/hgvs/repeats.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,23 +12,23 @@ def count_pattern_occurence(pattern, string):
matches = re.findall(pattern, string)
return len(matches)


def count_repetitive_units(s):
length = len(s)

for i in range(1, length + 1):
unit = s[:i]
if length % i == 0:
if unit * (length // i) == s:
return length // i, unit

return 1, s


class RepeatAnalyser:

def __init__(self, fs: VariantCoords) -> None:


self.is_repeat = False
self.ref_count = 0
self.alt_count = 0
Expand Down
18 changes: 9 additions & 9 deletions tests/test_pretty_print.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ def test_insertion(self):
+ " : 1,643,270 1,643,280 1,643,290 1,643,300 1,643,310\n"
+ "chrom pos : . | . | . | . | . | \n"
+ "seq -> : TCACTGGGGTGTCATCCTCATCGTCATCTTCGTAATTGAGGGAGCAAA\n"
+ "region : |------| \n"
+ "region : |------| \n"
+ "tx seq <- : AGTGACCCCACAGTAGGAGTAGCAGTAGAAGCATTAACTCCCTCGTTT\n"
+ "tx pos : | . | . | . | . | .\n"
+ " : 950 940 930 920 910\n"
Expand All @@ -191,7 +191,7 @@ def test_insertion_size_1(self):
+ " : 36,561,650 36,561,670\n"
+ "chrom pos : . | . | . | . | \n"
+ "seq -> : ACCTCGTTGGGGTGGAATCCATCCACGGGCTCGATGAGCT\n"
+ "region : ^^ \n"
+ "region : ^^ \n"
+ "tx seq <- : GAGCAACCCCACCTTAGGTAGGTGCCCGAGCTACTCGA\n"
+ "tx pos : | . | . | . | \n"
+ " : 1500 1490 1480 1470\n"
Expand All @@ -217,7 +217,7 @@ def test_del_2bp(self):
+ " : 36,561,650 36,561,670\n"
+ "chrom pos : . | . | . | . | \n"
+ "seq -> : TACCTCGTTGGGGTGGAATCCATCCACGGGCTCGATGAGCTG\n"
+ "region : xx \n"
+ "region : xx \n"
+ "tx seq <- : GAGCAACCCCACCTTAGGTAGGTGCCCGAGCTACTCGAC\n"
+ "tx pos : | . | . | . | .\n"
+ " : 1500 1490 1480 1470\n"
Expand All @@ -243,7 +243,7 @@ def test_del_1bp_shuffleable(self):
+ " : 36,561,650 36,561,670\n"
+ "chrom pos : . | . | . | . | \n"
+ "seq -> : TTACCTCGTTGGGGTGGAATCCATCCACGGGCTCGATGAGCT\n"
+ "region : xx \n"
+ "region : xx \n"
+ "tx seq <- : GAGCAACCCCACCTTAGGTAGGTGCCCGAGCTACTCGA\n"
+ "tx pos : | . | . | . | \n"
+ " : 1500 1490 1480 1470\n"
Expand All @@ -264,7 +264,7 @@ def test_del_1bp(self):

result = result.split("\n")
expected_str = (
"hgvs_g : NC_000007.13:g.36561663del\n"
"hgvs_g : NC_000007.13:g.36561663del\n"
+ "hgvs_c : NM_001177507.2:c.1485del\n"
+ "hgvs_p : NP_001170978.1:p.(Asp495GlufsTer123)\n"
+ " : 36,561,650 36,561,670\n"
Expand Down Expand Up @@ -329,7 +329,7 @@ def test_dup_1bp(self):
+ " : 1500 1490 1480 1470\n"
+ "aa seq <- : GluAsnProHisPheGlyAspValProGluIleLeuGln\n"
+ "aa pos : ||| ... ||| \n"
+ " : 500 490 \n"
+ " : 500 490 \n"
+ "ref>alt : A>AA\n"
).split("\n")
for r, e in zip(result, expected_str):
Expand All @@ -351,7 +351,7 @@ def test_identity(self):
+ " : 36,561,650 36,561,670\n"
+ "chrom pos : . | . | . | . | \n"
+ "seq -> : ACCTCGTTGGGGTGGAATCCATCCACGGGCTCGATGAGCTG\n"
+ "region : = \n"
+ "region : = \n"
+ "tx seq <- : GAGCAACCCCACCTTAGGTAGGTGCCCGAGCTACTCGAC\n"
+ "tx pos : | . | . | . | .\n"
+ " : 1500 1490 1480 1470\n"
Expand Down Expand Up @@ -423,7 +423,7 @@ def test_hgvs_c(self):
+ " 33,049,650 33,049,670 33,049,690 33,049,710 33,049,730 33,049,750 33,049,770 33,049,790\n"
+ " . | . | . | . | . | . | . | . | . | . | . | . | . | . | . |\n"
+ "CTGGGGCGCCGGGGGCTGCCATGGGGCCGGTGGGGGCGACCGAGCTGCTCGCCTGCCTCTGGACTCGCGGGCGAAGCCGCCACGGAGCTGGGGGCGCTGGCGCGAGCCCCGCCCCGCTCGAGTCCGGCCCCGCCCCTGGCCCGCCCC\n"
+ " |-------------------------| \n"
+ " |-------------------------| \n"
+ "GACCCCGCGGCCCCCGACGGTAccccggccacccccgctggctcgacgagcggacggagacctgagcgcccgcttcggcggtgcctcgacccccgcgaccgcgctcggggcggggcgagctcaggccggggcgggga \n"
+ " | . | . | . | . | . | . | . | . | . | . | . | . | . | . \n"
+ " 20 10 1 -10 -20 -30 -40 -50 -60 -70 -80 -90 -100 -110\n"
Expand Down Expand Up @@ -591,7 +591,7 @@ def test_rna_coding(self):
+ "chrom pos : | . | . | . | . |\n"
+ "seq -> : TGCTGATCTTTGGATGTTCTGGTTAGTCTAAGAAGGAGAGT\n"
+ "seq <- : ACGACTAGAAACCTACAAGACCAATCAGATTCTTCCTCTCA\n"
+ "region : A \n"
+ "region : A \n"
+ "tx seq -> : GATGTTCTGGTTAGTCTAAGAAGGAGAGT\n"
+ "tx pos : . | . | . |\n"
+ " : 10 20 30\n"
Expand Down
Loading

0 comments on commit 30addf2

Please sign in to comment.