From 204c099a8417861bd72b4a6d252e460cb8f0fc39 Mon Sep 17 00:00:00 2001 From: "Furkan M. Torun" Date: Fri, 6 May 2022 00:47:30 +0300 Subject: [PATCH] ADD: Simple Bioinformatics Tool (#131) * ADD: Simple Bioinformatics Tool as an example * ADD: Favicon to Bioinformatics Example --- .../examples/simple_bioinformatics_tool.html | 128 ++++++++++++++++++ 1 file changed, 128 insertions(+) create mode 100644 pyscriptjs/examples/simple_bioinformatics_tool.html diff --git a/pyscriptjs/examples/simple_bioinformatics_tool.html b/pyscriptjs/examples/simple_bioinformatics_tool.html new file mode 100644 index 00000000..0f1f6f94 --- /dev/null +++ b/pyscriptjs/examples/simple_bioinformatics_tool.html @@ -0,0 +1,128 @@ + + + + + + PyScript — Simple Bioinformatics Example + + + + + + + + +
+
+

PyScript — Simple Bioinformatics Example v.1

+

+ Demonstrates the simple use of PyScript + in Bioinformatics/Computational Biology fields! +

+
+
+ + + +
+

🧬 DNA Sequence Tool

+ + +
+ +
+ +
+
+ + + +
+
+
+ +
+
+
+ + +
+
+ +
+ + + +
+
+ +

+ + + + +# Define HTML elements and inputs +dna_alphabet = "ATGC" +output = Element("output") +dna_seq_element = Element("dna_seq") +operation_element = Element("operation") +operation_name_output_element = Element("operation_name_output") + +# DNA Sequene Operations +def return_reverse(dna_seq): + return dna_seq[::-1] +def return_complement(dna_seq): + return dna_seq.translate(str.maketrans("ATCG", "TAGC")) +def return_reverse_complement(dna_seq): + return dna_seq.translate(str.maketrans("ATCG", "TAGC"))[::-1] + +# Check DNA seq is valid +def check_dna_seq(dna_seq): + return all(letter in dna_alphabet for letter in dna_seq.upper()) + +# Clear the form and output +def clear(*args, **kwargs): + dna_seq_element.clear() + output.clear() + +# Run +def run(*args, **kwargs): + dna_seq = dna_seq_element.value + is_dna_seq_valid = check_dna_seq(dna_seq) + if is_dna_seq_valid: + operation_name = operation_element.value + operation_name_output_element.write(operation_name) + + # Compute the desired outputs + if operation_name == "Reverse": + output_dna_seq = return_reverse(dna_seq) + elif operation_name == "Complement": + output_dna_seq = return_complement(dna_seq) + elif operation_name == "ReverseComplement": + output_dna_seq = return_reverse_complement(dna_seq) + + # Output the result + output.write(output_dna_seq) + elif (dna_seq.strip() == "") or (dna_seq is None): + output.write("No DNA sequence provided") + else: + output.write("Invalid DNA sequence entered") + + + +