Skip to content

Commit

Permalink
Support graphs comparing different samples
Browse files Browse the repository at this point in the history
  • Loading branch information
matthewfallan committed Jul 25, 2023
1 parent cc24d2d commit dd1628c
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 16 deletions.
10 changes: 6 additions & 4 deletions src/seismicrna/graph/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -336,10 +336,6 @@ def _get_common_attribute(self, name: str):
def out_dir(self):
return self._get_common_attribute("out_dir")

@property
def sample(self):
return self._get_common_attribute("sample")

@property
def ref(self):
return self._get_common_attribute("ref")
Expand All @@ -356,6 +352,12 @@ def sample1(self):
def sample2(self):
return self.table2.sample

@property
def sample(self):
if self.sample1 == self.sample2:
return self.sample1
return f"{self.sample1}__and__{self.sample2}"


class OneTableSeqGraph(OneTableGraph, OneSeqGraph, ABC):

Expand Down
10 changes: 7 additions & 3 deletions src/seismicrna/graph/delbar.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@

logger = getLogger(__name__)


COMMAND = __name__.split(os.path.extsep)[-1]


# Number of digits to which to round decimals.

params = [
Expand All @@ -35,7 +39,7 @@
]


@command(__name__.split(os.path.extsep)[-1], params=params)
@command(COMMAND, params=params)
def cli(*args, **kwargs):
""" Create bar graphs of differences between pairs of samples at
each position in a sequence. """
Expand Down Expand Up @@ -70,15 +74,15 @@ class SeqDeltaGraph(SeqPairGraph):

@classmethod
def graph_type(cls):
return "del-bar"
return COMMAND

@property
def x_title(self) -> str:
return POS_NAME

@property
def y_title(self):
return f"{self.quantity} 2 minus {self.quantity} 1"
return f"{self.quantity}-2 minus {self.quantity}-1"

@cached_property
def col_titles(self):
Expand Down
7 changes: 5 additions & 2 deletions src/seismicrna/graph/scatter.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,10 @@
]


@command(__name__.split(os.path.extsep)[-1], params=params)
COMMAND = __name__.split(os.path.extsep)[-1]


@command(COMMAND, params=params)
def cli(*args, **kwargs):
""" Create scatter plots between pairs of samples at each position
in a sequence. """
Expand Down Expand Up @@ -69,7 +72,7 @@ class SeqScatterGraph(SeqPairGraph):

@classmethod
def graph_type(cls):
return "scatter"
return COMMAND

@property
def x_title(self) -> str:
Expand Down
6 changes: 4 additions & 2 deletions src/seismicrna/graph/seqbar.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@

logger = getLogger(__name__)

COMMAND = __name__.split(os.path.extsep)[-1]

# Number of digits to which to round decimals.

params = [
Expand All @@ -43,7 +45,7 @@
]


@command(__name__.split(os.path.extsep)[-1], params=params)
@command(COMMAND, params=params)
def cli(*args, **kwargs):
""" Create bar graphs of positions in a sequence. """
return run(*args, **kwargs)
Expand Down Expand Up @@ -156,7 +158,7 @@ def predicate(self):

@property
def graph_filename(self):
return f"{self.subject}_{self.predicate}".lower()
return f"{self.subject}_{self.predicate}_{COMMAND}".lower()

def _figure_layout(self, fig: go.Figure):
super()._figure_layout(fig)
Expand Down
10 changes: 5 additions & 5 deletions src/seismicrna/graph/seqpair.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,20 +95,20 @@ def subject1(self):
if isinstance(self.table1, ClustPosTableLoader):
osym = 'x' if self._order1 is None else self._order1[0]
ksym = 'x' if self._cluster1 is None else self._cluster1[0]
return f"{self.sample1}_{self.source1}-{osym}-{ksym}"
return f"{self.sample1}_{self.source1}"
return f"{self.source1}-{osym}-{ksym}"
return self.source1

@property
def subject2(self):
if isinstance(self.table2, ClustPosTableLoader):
osym = 'x' if self._order2 is None else self._order2[0]
ksym = 'x' if self._cluster2 is None else self._cluster2[0]
return f"{self.sample2}_{self.source2}-{osym}-{ksym}"
return f"{self.sample2}_{self.source2}"
return f"{self.source2}-{osym}-{ksym}"
return self.source2

@property
def subject(self):
return f"{self.subject1}_vs_{self.subject2}"
return f"{self.subject1}__and__{self.subject2}"

@property
def quantity(self):
Expand Down

0 comments on commit dd1628c

Please sign in to comment.