Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

adding a DNA example #23

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added examples/dna/assets/dna.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
89 changes: 89 additions & 0 deletions examples/dna/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
<!--
contributor: https://github.com/meg-1
tags: example-tag, dna, genetic-algorithms, combinatorics
-->

<!DOCTYPE html>
<html lang="en" xmlns="http://www.w3.org/1999/xhtml">

<head>
<meta name="viewport" content="width=device-width,initial-scale=1"/>
<meta charset="utf-8" />
<title>dna</title>
<link rel="stylesheet" href="https://pyscript.net/alpha/pyscript.css" />
<link rel="stylesheet" href="styles/styles.css" />
</head>

<body>

<header>
<h1 id="header_h1">Welcome to the "Complementary DNA converter"!</h1>
</header>

<main style="">

<div class="flexelement" id="first_div">
<p id="first_p">
Welcome to the "Complementary DNA converter"
<br />
<strong>"how does it work?"</strong>
The "Complementary DNA converter", given one side of a DNA strand returns the other,
complementary side of said strand.
To learn more, please visit:
<i>
<a href="https://en.wikipedia.org/wiki/DNA#Transcription_and_translation"
style="color: #0095E8;" target="_blank">
about DNA transcription and translation
<img src="assets/dna.png" style="height: 275px; margin-top: 2%;" />

</a>
</i>
</p>


</div>


<div class="flexelement">

<div id="form">

<div style="margin-top: 20%;">

<label>Initial DNA strand:</label><br>
<input id="initial_dna" type="text"/> <br />

<button pys-onClick="dna" id="calc">Get Result</button>

<div style="margin-top: 2%;">
<span id="dna_result"></span>
</div>

</div>

</div>

</div>

<py-script>
def dna(*args, **kwargs):
output = Element("dna_result")
p = str(Element("initial_dna").value)
res = p.translate(p.maketrans("ATCGatcg","TAGCTAGC"))
output.write("complementary side: " + str(res))
</py-script>

<script defer src="https://pyscript.net/alpha/pyscript.js"></script>

</main>

<footer>
<p id="footer_p">
Thank you for using the "Complementary DNA converter",
powered by PyScript!
</p>
</footer>

</body>

</html>
167 changes: 167 additions & 0 deletions examples/dna/styles/styles.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,167 @@
body {
background-color: #F3F6F8;
min-height: 100vh;
display: flex;
flex-direction: column;
}

main {
display: flex;
flex-direction: row;
}

#first_div {
align-content: center;
margin: 1%;
flex: 1.25;
}

#first_p {
margin: 3.5%;
margin-left: 15%;
font-family: Tahoma, sans-serif;
}

.flexelement {
flex: 1;
padding: 2%;
}



#form {
margin-top: 7%;
height: 100%;
display: flex;
align-content: center;
justify-content: center;
}

#form input[type=number] {
border: 1px solid white;
border-radius: 0.3em;
height: 12%;
width: 100%;
margin-bottom: 5px;
}


#form button {
width: 100%;
height: 12%;
margin-bottom: 5px;
}

header {
height: 100px;
}

footer {
margin-top: auto;
height: 57px;
}

header, footer {
background-color: #1A1A27;
}

#header_h1 {
padding-top: 2.2%;
margin-left: 40%;
font-weight: bold;
color: white;
}

input[type=number] {
padding: 1%;
}

#principal, #interest_rate, #time {
width: 25%;
}

#calc {
min-height: 47px;
width: 25%;
padding: 1%;
font-weight: bold;
margin-top: 2%;
color: white;
background-color: #0095E8;
}

#initial_dna {
margin-bottom: 2%;
margin-top: 2%;
color: black;
min-height: 47px;
}

#simple_interest, #compound_interest {
color: black;
font-weight: bold;
}

input[type=radio] {
display: none;
}

label {
cursor: pointer;
}

input[type=radio] ~ img {
animation: close 1.5;
display: none;
height: 0;
max-height: 500px;
overflow: hidden;
}

input[type=radio]:checked ~ img {
animation: open 1.5s;
display: block;
height: auto;
max-height: 500px;
}

@keyframes open {
from {
max-height: 0;
}

to {
max-height: auto;
}
}

@keyframes close {
from {
display: block;
max-height: auto;
}

to {
display: none;
height: 0;
}
}

.expander_label {
border: 1px solid #0095E8;
border-radius: 0.1em;
padding: 1%;
font-weight: 500;
color: white;
background-color: #0095E8;
background-color: #0095E8;
}

#footer_p {
font-weight: bold;
font-size: 13px;
text-align: center;
color: white;
vertical-align: central;
padding: 1.2%;
}
8 changes: 7 additions & 1 deletion tests/test_examples.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@
]

EXAMPLES = [
"hello_world"
"hello_world",
"dna",
]

TEST_PARAMS = {
Expand All @@ -42,6 +43,11 @@
"pattern": "\\d+:\\d+:\\d+",
"title": "PyScript Hello World",
},
"dna":{
"file":"/dna/index.html",
"pattern":"Get Result",
"title": "dna",
}
}


Expand Down