Skip to content

Commit

Permalink
Add ability to make a seq from AB1. On saving files, save the tabs open
Browse files Browse the repository at this point in the history
  • Loading branch information
David-OConnor committed Dec 14, 2024
1 parent 1f2dee0 commit 75a44d4
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 10 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

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

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "plascad"
version = "0.7.6"
version = "0.7.7"
edition = "2021"
authors = ["David O'Connor <the_alchemist@fastmail.com>"]
#description = "Tools for plasmid and primer design, PCR, and related."
Expand Down
54 changes: 52 additions & 2 deletions src/gui/ab1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,12 @@ use na_seq::{seq_to_str_lower, Nucleotide};

use crate::{
ab1::SeqRecordAb1,
feature_db_load::find_features,
file_io::GenericData,
gui::{BACKGROUND_COLOR, COL_SPACING, ROW_SPACING},
misc_types::Metadata,
state::State,
util::merge_feature_sets,
};

const NT_COLOR: Color32 = Color32::from_rgb(180, 220, 220);
Expand Down Expand Up @@ -165,16 +170,59 @@ fn plot(data: &SeqRecordAb1, to_screen: &RectTransform, ui: &mut Ui) -> Vec<Shap
result
}

pub fn ab1_page(data: &SeqRecordAb1, ui: &mut Ui) {
pub fn ab1_page(state: &mut State, ui: &mut Ui) {
ui.horizontal(|ui| {
let data = &state.ab1_data[state.active];

ui.heading("AB1 sequencing view");

ui.add_space(COL_SPACING * 2.);

if ui.button(RichText::new("🗐 Copy sequence")).clicked() {
if ui.button(RichText::new("🗐 Copy sequence")).on_hover_text("Copy this sequence to the clipboard.").clicked() {
let mut ctx = ClipboardContext::new().unwrap();
ctx.set_contents(seq_to_str_lower(&data.sequence)).unwrap();
}

ui.add_space(COL_SPACING);

if ui
.button("➕ Create data (e.g. Genbank, PCAD etc) as a new tab.")
.on_hover_text("Create a new non-AB1 data set\
that may include features, primers, etc. May be edited, and saved to Genbank, PCAD, or SnapGene formats.")
.clicked()
{
// Note: This segment is almost a duplicate of `State::add_tab` and the similar section in `cloning`.
let plasmid_name = match &state.tabs_open[state.active].path {
Some(p) => p.file_name().unwrap().to_str().unwrap_or_default(),
None => "Plasmid from AB1", // This shouldn't happen, I believe.
}.to_owned().replace(".ab1", "");

let generic = GenericData {
seq: data.sequence.clone(),
metadata: Metadata {
plasmid_name,
..Default::default()
},
..Default::default()
};


state.generic.push(generic);

state.portions.push(Default::default());
state.volatile.push(Default::default());
state.tabs_open.push(Default::default());
state.ab1_data.push(Default::default());

state.active = state.generic.len() - 1;

// state.sync_seq_related(None);

// Annotate. Don't add duplicates.
let features = find_features(&state.get_seq());
merge_feature_sets(&mut state.generic[state.active].features, &features)

}
});
ui.add_space(ROW_SPACING / 2.);

Expand All @@ -183,6 +231,8 @@ pub fn ab1_page(data: &SeqRecordAb1, ui: &mut Ui) {
Frame::canvas(ui.style())
.fill(BACKGROUND_COLOR)
.show(ui, |ui| {
let data = &state.ab1_data[state.active];

let (response, _painter) = {
let desired_size = vec2(ui.available_width(), ui.available_height());
ui.allocate_painter(desired_size, Sense::click())
Expand Down
7 changes: 1 addition & 6 deletions src/gui/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -411,12 +411,7 @@ pub fn draw(state: &mut State, ctx: &Context) {
metadata::metadata_page(&mut state.generic[state.active].metadata, ui)
}
Page::Portions => portions::portions_page(&mut state.portions[state.active], ui),
Page::Ab1 => {
if state.ab1_data.len() > 0 {
// todo: Fix index, and this hack in general.
ab1::ab1_page(&state.ab1_data[0], ui)
}
}
Page::Ab1 => ab1::ab1_page(state, ui),
}
});
}
Expand Down
4 changes: 4 additions & 0 deletions src/gui/save.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ pub fn save_section(state: &mut State, ui: &mut Ui) {
ab1: false,
};
set_window_title(&state.tabs_open[state.active], ui);
state.save_prefs(); // Save opened tabs.
}
Err(e) => eprintln!("Error saving in PlasCAD format: {:?}", e),
};
Expand All @@ -146,6 +147,7 @@ pub fn save_section(state: &mut State, ui: &mut Ui) {
ab1: false,
};
set_window_title(&state.tabs_open[state.active], ui);
state.save_prefs(); // Save opened tabs.
}
Err(e) => eprintln!("Error exporting to FASTA: {:?}", e),
}
Expand All @@ -164,6 +166,7 @@ pub fn save_section(state: &mut State, ui: &mut Ui) {
ab1: false,
};
set_window_title(&state.tabs_open[state.active], ui);
state.save_prefs(); // Save opened tabs.
}
Err(e) => eprintln!("Error exporting to GenBank: {:?}", e),
}
Expand All @@ -175,6 +178,7 @@ pub fn save_section(state: &mut State, ui: &mut Ui) {
ab1: false,
};
set_window_title(&state.tabs_open[state.active], ui);
state.save_prefs(); // Save opened tabs.
}
Err(e) => eprintln!("Error exporting to SnapGene: {:?}", e),
};
Expand Down

0 comments on commit 75a44d4

Please # to comment.