Skip to content

Commit be04bc6

Browse files
committed
Added bam_color_by_tag option
1 parent ca28250 commit be04bc6

4 files changed

Lines changed: 50 additions & 1 deletion

File tree

src/sessionizer/create_igv_session.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ def generate_igv_session(
103103
genome_path: Path,
104104
bam_group_by: List[AllignmentGroupByOption],
105105
bam_color_by: List[AllignmentColorByOption],
106+
bam_color_by_tag: List[str],
106107
bam_display_mode: List[AllignmentDisplayModeOption],
107108
bam_hide_small_indels: List[bool],
108109
bam_small_indel_threshold: List[int],
@@ -138,6 +139,7 @@ def generate_igv_session(
138139
if alignment_files:
139140
bam_group_by = hanlde_attribute("bam_group_by", bam_group_by, alignment_files, "alignment files")
140141
bam_color_by = hanlde_attribute("bam_color_by", bam_color_by, alignment_files, "alignment files")
142+
bam_color_by_tag = hanlde_attribute("bam_color_by_tag", bam_color_by_tag, alignment_files, "alignment files")
141143
bam_display_mode = hanlde_attribute("bam_display_mode", bam_display_mode, alignment_files, "alignment files")
142144
bam_hide_small_indels = hanlde_attribute("bam_hide_small_indels", bam_hide_small_indels, alignment_files, "alignment files")
143145
bam_small_indel_threshold = hanlde_attribute("bam_small_indel_threshold", bam_small_indel_threshold, alignment_files, "alignment files")
@@ -170,6 +172,7 @@ def generate_igv_session(
170172
# Allignment files
171173
bam_group_by_cycle = cycle(bam_group_by)
172174
bam_color_by_cycle = cycle(bam_color_by)
175+
bam_color_by_tag_cycle = cycle(bam_color_by_tag)
173176
bam_display_mode_cycle = cycle(bam_display_mode)
174177
bam_hide_small_indels_cycle = cycle(bam_hide_small_indels)
175178
bam_small_indel_threshold_cycle = cycle(bam_small_indel_threshold)
@@ -202,6 +205,7 @@ def generate_igv_session(
202205
height=height,
203206
group_by=next(bam_group_by_cycle),
204207
color_by=next(bam_color_by_cycle),
208+
color_by_tag=next(bam_color_by_tag_cycle),
205209
hide_small_indels=next(bam_hide_small_indels_cycle),
206210
small_indel_threshold=next(bam_small_indel_threshold_cycle),
207211
display_mode=next(bam_display_mode_cycle),

src/sessionizer/main.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,13 @@ def run(
107107
rich_help_panel=ALIGNMENT_OPTIONS,
108108
),
109109
] = [AllignmentColorByOption.NONE],
110+
bam_color_by_tag: Annotated[
111+
List[str],
112+
typer.Option(
113+
help="Parameter to color bams by tag.",
114+
rich_help_panel=ALIGNMENT_OPTIONS,
115+
),
116+
] = [""],
110117
bam_display_mode: Annotated[
111118
List[AllignmentDisplayModeOption],
112119
typer.Option(
@@ -251,6 +258,7 @@ def run(
251258
genome_path=genome_path,
252259
bam_group_by=bam_group_by,
253260
bam_color_by=bam_color_by,
261+
bam_color_by_tag=bam_color_by_tag,
254262
bam_display_mode=bam_display_mode,
255263
bam_hide_small_indels=bam_hide_small_indels,
256264
bam_small_indel_threshold=bam_small_indel_threshold,

src/sessionizer/track_elements.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@ class AllignmentColorByOption(str, Enum):
5050
ZMW = "zmw"
5151
BISULFITE = "bisulfite"
5252
NOMESEQ = "nomeseq"
53-
TAG = "tag"
5453
UNEXPECTED_PAIR = "unexpected_pair"
5554
MAPPED_SIZE = "mapped_size"
5655
LINK_STRAND = "link_strand"
@@ -63,6 +62,7 @@ class AllignmentColorByOption(str, Enum):
6362
SMRT_CCS_FWD_PW = "smrt_ccs_fwd_pw"
6463
SMRT_CCS_REV_IPD = "smrt_ccs_rev_ipd"
6564
SMRT_CCS_REV_PW = "smrt_ccs_rev_pw"
65+
TAG = "tag" # Special case - needs to be acompained by tag value
6666

6767
def __str__(self):
6868
return self.value
@@ -122,6 +122,7 @@ def add_track(self, session_panel: ET.Element):
122122
class AllignmentTrack(DataTrack):
123123
group_by: AllignmentGroupByOption
124124
color_by: AllignmentColorByOption
125+
color_by_tag: str
125126
display_mode: AllignmentDisplayModeOption
126127

127128
hide_small_indels: bool
@@ -159,6 +160,8 @@ def add_track(self, session_panel: ET.Element):
159160
"RenderOptions",
160161
)
161162
render_options.set("colorOption", str(self.color_by.name))
163+
if self.color_by == AllignmentColorByOption.TAG:
164+
render_options.set("colorByTag", self.color_by_tag)
162165
render_options.set("groupByOption", str(self.group_by.name))
163166
render_options.set("hideSmallIndels", str(self.hide_small_indels).lower())
164167
render_options.set("smallIndelThreshold", str(self.small_indel_threshold))

tests/test_create_igv_session.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ def test_attribute_handling(self):
4646
genome=GENOME.HG38,
4747
genome_path="",
4848
bam_color_by=[AllignmentColorByOption.NONE],
49+
bam_color_by_tag=[""],
4950
bam_display_mode=[AllignmentDisplayModeOption.COLLAPSED],
5051
bam_hide_small_indels=[False],
5152
bam_small_indel_threshold=[0],
@@ -73,6 +74,35 @@ def test_attribute_handling(self):
7374
genome=GENOME.HG38,
7475
genome_path="",
7576
bam_color_by=[AllignmentColorByOption.NONE],
77+
bam_color_by_tag=[""],
78+
bam_display_mode=[AllignmentDisplayModeOption.COLLAPSED],
79+
bam_hide_small_indels=[False],
80+
bam_small_indel_threshold=[0],
81+
bam_show_coverage=[False],
82+
bam_show_junctions=[False],
83+
bw_ranges=[BigWigRangeOption(minimum=0.0, baseline=0.0, maximum=0.0)],
84+
bw_color=[RGBColorOption.NONE],
85+
bw_negative_color=[RGBColorOption.NONE],
86+
bw_plot_type=[BigWigPlotTypeOption.NONE],
87+
bw_auto_scale=[False],
88+
vcf_show_genotypes=[False],
89+
vcf_feature_visibility_window=[0],
90+
gtf_display_mode=[GtfDisplayModeOption.COLLAPSED],
91+
)
92+
93+
self.assertRaises(
94+
ValueError,
95+
generate_igv_session,
96+
# Relevant arguments
97+
files=[self.input_bam],
98+
bam_color_by=[AllignmentColorByOption.TAG],
99+
bam_color_by_tag=["PS"],
100+
# Other arguments
101+
names=[],
102+
heights=[],
103+
genome=GENOME.HG38,
104+
genome_path="",
105+
bam_group_by=[AllignmentGroupByOption.NONE],
76106
bam_display_mode=[AllignmentDisplayModeOption.COLLAPSED],
77107
bam_hide_small_indels=[False],
78108
bam_small_indel_threshold=[0],
@@ -101,6 +131,7 @@ def test_attribute_handling(self):
101131
genome=GENOME.HG38,
102132
genome_path="",
103133
bam_color_by=[AllignmentColorByOption.NONE],
134+
bam_color_by_tag=[""],
104135
bam_display_mode=[AllignmentDisplayModeOption.COLLAPSED],
105136
bam_group_by=[AllignmentGroupByOption.NONE],
106137
bam_hide_small_indels=[False],
@@ -128,6 +159,7 @@ def test_attribute_handling(self):
128159
genome=GENOME.HG38,
129160
genome_path="",
130161
bam_color_by=[AllignmentColorByOption.NONE],
162+
bam_color_by_tag=[""],
131163
bam_display_mode=[AllignmentDisplayModeOption.COLLAPSED],
132164
bam_group_by=[False],
133165
bam_hide_small_indels=[False],
@@ -154,6 +186,7 @@ def test_attribute_handling(self):
154186
genome=GENOME.HG38,
155187
genome_path="",
156188
bam_color_by=[AllignmentColorByOption.NONE],
189+
bam_color_by_tag=[""],
157190
bam_display_mode=[AllignmentDisplayModeOption.COLLAPSED],
158191
bam_group_by=[False],
159192
bam_hide_small_indels=[False],
@@ -181,6 +214,7 @@ def test_attribute_handling(self):
181214
genome=GENOME.HG38,
182215
genome_path="",
183216
bam_color_by=[AllignmentColorByOption.NONE],
217+
bam_color_by_tag=[""],
184218
bam_display_mode=[AllignmentDisplayModeOption.COLLAPSED],
185219
bam_group_by=[False],
186220
bam_hide_small_indels=[False],

0 commit comments

Comments
 (0)