FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

feat: Add new wizard mode for interactive plot generation by fxwiegand · Pull Request #327 · alignoth/alignoth · GitHub

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .lock  (1) .md  (1) .rs  (3) .toml  (1) All 4 file types selected
Only manifest files
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
178 changes: 177 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
This file contains hidden or 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
Expand Up @@ -23,6 +23,7 @@ csv = "1.3.1"
tera = "1.20.0"
reqwest = "0.12" # 0.12 seems to cause issues fetching vega libs from cdn
tokio = { version = "1", features = ["full"] }
inquire = "0.7.5"

[profile.release]
lto = "fat"
Expand Down
8 changes: 8 additions & 0 deletions README.md
This file contains hidden or 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
Expand Up @@ -10,8 +10,16 @@
A tool for creating alignment plots from bam files. The generated [vega-lite](https://vega.github.io/vega-lite/) plots are written to stdout per default.
An example of a generated plot can be seen [here](http://htmlpreview.github.io/?https://github.com/koesterlab/alignoth/blob/main/examples/plot.html)
The name alignoth is derived from the visualized **align**ments combined with the star **alioth** (usage of vega plots).

Alignoth supports an interactive mode that can be activated by simply executing it without any arguments (i.e. `alignoth`).
This launches a wizard that guides you through selecting input files, defining the region of interest, and choosing between an interactive HTML output or a Vega-Lite specification.

## Usage

```alignoth```

To activate the interactive mode guiding you through the process of creating an alignment plot.

```alignoth -b path/to/my.bam -r path/to/my/reference.fa -g chr1:200-300 > plot.vl.json```

To directly generate a plot in svg, png or pdf format we advice using the [vega-cli](https://vega.github.io/vega/usage/#cli) and [vega-lite-cli]( https://vega.github.io/vega-lite/usage/compile.html#cli) packages:
Expand Down
32 changes: 30 additions & 2 deletions src/main.rs
This file contains hidden or 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
@@ -1,9 +1,11 @@
mod cli;
mod plot;
mod utils;
mod wizard;

use crate::cli::{DataFormat, Interval, Preprocess};
use crate::plot::create_plot_data;
use crate::wizard::wizard_mode;
use anyhow::Result;
use csv::WriterBuilder;
use log::LevelFilter;
Expand All @@ -18,7 +20,12 @@ use tera::{Context, Tera};

#[tokio::main]
async fn main() -> Result<()> {
let mut opt = cli::Alignoth::from_args();
let wizard = std::env::args().len() == 1;
let mut opt = if wizard {
wizard_mode().await?
} else {
cli::Alignoth::from_args()
};
let _ = TermLogger::init(
LevelFilter::Warn,
Config::default(),
Expand Down Expand Up @@ -133,6 +140,16 @@ async fn main() -> Result<()> {
plot_specs["datasets"]["reference"] = json!(reference_data);
plot_specs["datasets"]["reads"] = json!(read_data);
plot_specs["datasets"]["highlight"] = json!(highlight);
let bam_name = opt
.bam_path
.unwrap()
.file_name()
.unwrap()
.to_str()
.unwrap()
.strip_suffix(".bam")
.unwrap()
.to_owned();
if opt.html {
let mut templates = Tera::default();
templates.add_raw_template("plot", include_str!("../resources/plot.html.tera"))?;
Expand Down Expand Up @@ -160,7 +177,18 @@ async fn main() -> Result<()> {
.await?,
);
let html = templates.render("plot", &context)?;
stdout().write_all(html.as_bytes())?;
if wizard {
std::fs::write(format!("{}.html", bam_name), html.as_bytes())?;
println!("Plot saved to {}.html 🪄", bam_name);
} else {
stdout().write_all(html.as_bytes())?;
}
} else if wizard {
std::fs::write(
format!("{}.vl.json", bam_name),
plot_specs.to_string().as_bytes(),
)?;
println!("Plot saved to {}.vl.json 🪄", bam_name);
} else {
stdout().write_all(plot_specs.to_string().as_bytes())?;
}
Expand Down
Loading

Back | FazBrowse Home | New Git URL