Browse Source

Redirect to homepage if error occurs

pull/1/head
Ravi Shah 5 years ago
parent
commit
4846f0c44f
  1. 9
      src/lib.rs
  2. 2
      www/app.html
  3. 7
      www/app.js
  4. 2
      www/webpack.config.js

9
src/lib.rs

@ -16,7 +16,6 @@ extern {
fn alert(s: &str);
}
//#[wasm_bindgen]
pub fn transcription(dna: String) -> String {
let char_vec: Vec<char> = dna.chars().collect();
let mut transcribed_vec: Vec<char> = Vec::new();
@ -28,7 +27,6 @@ pub fn transcription(dna: String) -> String {
'C' => transcribed_vec.push('G'),
'G' => transcribed_vec.push('C'),
_ => {
// println!("Incorrect char");
break;
}
}
@ -38,7 +36,6 @@ pub fn transcription(dna: String) -> String {
return transcribed_string;
}
//#[wasm_bindgen]
pub fn find_start(messenger_rna: String) -> String {
let start_codon = "AUG";
let start_index = messenger_rna.find(start_codon).unwrap();
@ -46,7 +43,6 @@ pub fn find_start(messenger_rna: String) -> String {
return inter_rna;
}
//#[wasm_bindgen]
pub fn break_into_codons(inter_rna: String) -> Vec<String> {
let sub_len = 3;
let subs = inter_rna.as_bytes()
@ -63,7 +59,6 @@ pub fn break_into_codons(inter_rna: String) -> Vec<String> {
return string_vec;
}
//#[wasm_bindgen]
pub fn find_stop(inter_codons: &[String]) -> usize {
let mut stop_index_1: usize = usize::MAX;
let mut stop_index_2: usize = usize::MAX;
@ -84,7 +79,6 @@ pub fn find_stop(inter_codons: &[String]) -> usize {
return stop_index;
}
//#[wasm_bindgen]
pub fn find_first(stop_index_1: usize, stop_index_2: usize, stop_index_3: usize) -> usize {
let mut stop_index: usize = 1;
@ -114,7 +108,6 @@ pub fn find_first(stop_index_1: usize, stop_index_2: usize, stop_index_3: usize)
return stop_index;
}
//#[wasm_bindgen]
pub fn translation(inter_codons: Vec<String>) -> Vec<String> {
let mut amino_acids_list: Vec<String> = Vec::new();
@ -143,7 +136,6 @@ pub fn translation(inter_codons: Vec<String>) -> Vec<String> {
"AAU" | "AAC" => amino_acids_list.push("Asparginine".to_string()),
"AAA" | "AAG" => amino_acids_list.push("Lysine".to_string()),
_ => {
// println!("Incorrect char");
break;
}
}
@ -156,7 +148,6 @@ pub fn translation(inter_codons: Vec<String>) -> Vec<String> {
pub fn main(mut strand: String) {
println!("Enter the DNA strand to be transcribed and translated: ");
//let mut strand: String = "TACATGCCATACGAGACGAGCGCGCCTAAGCGGCGCAGACTCATGGTCATT".to_string();
strand = strand.to_string().to_uppercase();
let messenger_rna = transcription(strand);

2
www/app.html

@ -7,6 +7,6 @@
<body>
<noscript>This page contains webassembly and javascript content, please enable javascript in your browser.</noscript>
<script src="./bootstrap.js"></script>
<h1>Hello</h1>
<h1>DNA Transcription &amp; Translation</h1>
</body>
</html>

7
www/app.js

@ -3,6 +3,9 @@ import * as wasm from "wasm-dna-transcription-translation";
const urlParams = new URLSearchParams(window.location.search);
const strand = urlParams.get('strand');
console.log(strand)
try {
wasm.main(strand);
} catch(err) {
alert('Oh no! Something went wrong. Please check that your DNA strand only uses valid characters, and has a stop & start codon. You will now be redirected to the homepage.')
window.location.href = '/';
}

2
www/webpack.config.js

@ -2,6 +2,7 @@ const CopyWebpackPlugin = require("copy-webpack-plugin");
const path = require('path');
module.exports = {
devtool: 'eval-source-map',
entry: "./bootstrap.js",
output: {
path: path.resolve(__dirname, "dist"),
@ -10,5 +11,6 @@ module.exports = {
mode: "development",
plugins: [
new CopyWebpackPlugin(['index.html'])
new CopyWebpackPlugin(['app.html'])
],
};
Loading…
Cancel
Save