Skip to content

Commit

Permalink
v16 compressedX added along with check to never merge Bin0. graph-gen…
Browse files Browse the repository at this point in the history
  • Loading branch information
josiahseaman committed Jun 2, 2020
1 parent e8b27b5 commit a23d7c1
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 2 deletions.
3 changes: 3 additions & 0 deletions matrixcomponent/PangenomeSchematic.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,9 +188,12 @@ def write_index_file(self, folder, bin2file_mapping):
def prerender(self):
"""Calculates X coordinates and summary statistics for all Components"""
x = 0
compressedX = 0
for component in self.components:
component.x = x
component.compressedX = compressedX
# component.first_bin=0 does not take up rendering space, the next component is 0
x = component.next_x_coord(self.includes_connectors) if component.first_bin else 0
compressedX = component.next_compressedX(self.includes_connectors) if component.first_bin else 0
self.update_first_last_bin()

2 changes: 1 addition & 1 deletion matrixcomponent/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
JSON_VERSION = 15 # This version adds prerender x coordinates for all components
JSON_VERSION = 16 # This version adds prerender compressedX coordinates for all components
ODGI_VERSION = 12

import logging
Expand Down
12 changes: 11 additions & 1 deletion matrixcomponent/matrix.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ class Component:
first_bin: int
last_bin: int
x = 0
compressedX = 0
occupants: set # pure ids
matrix: List
arrivals: List[LinkColumn]
Expand All @@ -52,19 +53,28 @@ class Component:
def __init__(self, first_bin: int, last_bin: int):
self.first_bin = first_bin
self.last_bin = last_bin
if first_bin == 0:
# don't confuse the special case bin 0 with regular content
assert last_bin == 0
self.occupants = set()
self.matrix = []
self.arrivals = [] # reverse ordered Links
self.departures = [] # ordered Links

def width(self, includes_connectors):
def width(self, includes_connectors, compressed=False):
depart_n = len(self.departures)
if includes_connectors:
depart_n -= 1
matrix_width = (self.last_bin - self.first_bin + 1)
if compressed:
matrix_width = 3 # binScalingFactor
return len(self.arrivals) + depart_n + matrix_width
# (len(self.departures)-1) because last departure is adjacent connectors

def next_x_coord(self, includes_connectors):
# 1 column of padding
return self.x + self.width(includes_connectors) + (1 if includes_connectors else 0)

def next_compressedX(self, includes_connectors):
# 1 column of padding
return self.compressedX + self.width(includes_connectors, compressed=True) + (1 if includes_connectors else 0)

0 comments on commit a23d7c1

Please sign in to comment.