-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add summarize-alignment visualizer (#2)
- Loading branch information
1 parent
e54d743
commit 1e802ea
Showing
3 changed files
with
86 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
# ---------------------------------------------------------------------------- | ||
# Copyright (c) 2024, Greg Caporaso. | ||
# | ||
# Distributed under the terms of the Modified BSD License. | ||
# | ||
# The full license is in the file LICENSE, distributed with this software. | ||
# ---------------------------------------------------------------------------- | ||
|
||
import os.path | ||
|
||
from skbio.alignment import TabularMSA | ||
|
||
|
||
def summarize_alignment(output_dir: str, msa: TabularMSA) -> None: | ||
with open(os.path.join(output_dir, "index.html"), "w") as fh: | ||
fh.write(_html_template % repr(msa)) | ||
|
||
|
||
_html_template = """ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
<title>Alignment summary</title> | ||
<style> | ||
body { | ||
padding: 20px; | ||
} | ||
p.alignment { | ||
font-family: 'Courier New', Courier, monospace; | ||
} | ||
</style> | ||
</head> | ||
<body> | ||
<pre> | ||
%s | ||
</pre> | ||
</body> | ||
</html> | ||
""" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
# ---------------------------------------------------------------------------- | ||
# Copyright (c) 2024, Greg Caporaso. | ||
# | ||
# Distributed under the terms of the Modified BSD License. | ||
# | ||
# The full license is in the file LICENSE, distributed with this software. | ||
# ---------------------------------------------------------------------------- | ||
|
||
import os.path | ||
|
||
from skbio.alignment import TabularMSA | ||
from skbio.sequence import DNA | ||
|
||
from qiime2.plugin.testing import TestPluginBase | ||
|
||
from q2_dwq2._visualizers import summarize_alignment | ||
|
||
|
||
class SummarizeAlignmentTests(TestPluginBase): | ||
package = 'q2_dwq2.tests' | ||
|
||
def test_simple1(self): | ||
aligned_sequence1 = DNA('AAAAAAAAGGTGGCCTTTTTTTT') | ||
aligned_sequence2 = DNA('AAAAAAAAGG-GGCCTTTTTTTT') | ||
msa = TabularMSA([aligned_sequence1, aligned_sequence2]) | ||
|
||
with self.temp_dir as output_dir: | ||
summarize_alignment(output_dir, msa) | ||
|
||
with open(os.path.join(output_dir, 'index.html'), 'r') as fh: | ||
observed = fh.read() | ||
|
||
self.assertIn('AAAAAAAAGGTGGCCTTTTTTTT', observed) | ||
self.assertIn('AAAAAAAAGG-GGCCTTTTTTTT', observed) |