Compare commits
No commits in common. "beta-release" and "callback-refactor" have entirely different histories.
beta-relea
...
callback-r
|
@ -1,24 +0,0 @@
|
|||
name: Beta Deploy
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- beta-release
|
||||
|
||||
jobs:
|
||||
Compile-Plate-Tool:
|
||||
runs-on: linux_arm
|
||||
steps:
|
||||
- name: Check out repo code
|
||||
uses: https://github.com/actions/checkout@v4
|
||||
with:
|
||||
ref: "beta-release"
|
||||
- name: Compile plate-tool
|
||||
run: |
|
||||
. "$HOME/.cargo/env"
|
||||
trunk build --release --public-url "cool-stuff/plate-tool-beta/"
|
||||
- name: Transfer files to host server
|
||||
run: |
|
||||
sftp oracle <<< "put -r dist"
|
||||
- name: Deploy plate-tool-beta on host server
|
||||
run: |
|
||||
ssh oracle "sudo rm -rf /usr/share/nginx/html/plate-tool-beta/ && sudo mv dist /usr/share/nginx/html/plate-tool-beta"
|
File diff suppressed because it is too large
Load Diff
32
Cargo.toml
32
Cargo.toml
|
@ -1,3 +1,29 @@
|
|||
[workspace]
|
||||
members = ["plate-tool-web", "plate-tool-lib"]
|
||||
resolver = "2"
|
||||
[package]
|
||||
name = "plate-tool"
|
||||
version = "0.2.0"
|
||||
edition = "2021"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
yew = { version = "0.20.0", features = ["csr"] }
|
||||
yewdux = "0.9"
|
||||
wasm-bindgen = "0.2"
|
||||
web-sys = { version = "0.3", features = ["FormData", "HtmlFormElement",
|
||||
"HtmlDialogElement", "Blob", "Url", "Window",
|
||||
"HtmlAnchorElement", "ReadableStream", "HtmlSelectElement", "HtmlOptionElement", "HtmlButtonElement",
|
||||
"FileReader"] }
|
||||
js-sys = "0.3"
|
||||
log = "0.4"
|
||||
wasm-logger = "0.2"
|
||||
regex = "1"
|
||||
lazy_static = "1.4"
|
||||
uuid = { version = "1.6", features = ["v7", "fast-rng", "macro-diagnostics", "js", "serde"] }
|
||||
serde = { version = "1.0", features = ["derive"] }
|
||||
serde_json = "1.0"
|
||||
csv = "1.2"
|
||||
getrandom = { version = "0.2", features = ["js"] }
|
||||
rand = { version = "0.8", features = ["small_rng"] }
|
||||
|
||||
[dev-dependencies]
|
||||
wasm-bindgen-test = "0.3.0"
|
||||
|
|
|
@ -1,43 +1,34 @@
|
|||
pipeline {
|
||||
agent any
|
||||
environment {
|
||||
OUTPUT_DIR = "${env.BRANCH_NAME == "main" ? "plate-tool" : "plate-tool-beta"}"
|
||||
}
|
||||
|
||||
stages {
|
||||
stage('Parent') {
|
||||
when { anyOf { branch 'main'; branch 'beta-release' } }
|
||||
stages {
|
||||
stage('Build') {
|
||||
steps {
|
||||
sh '''
|
||||
. "$HOME/.cargo/env"
|
||||
cd plate-tool-web
|
||||
trunk build --release --public-url "./"
|
||||
trunk build --release --public-url "cool-stuff/plate-tool-beta/"
|
||||
'''
|
||||
}
|
||||
}
|
||||
stage('Archive') {
|
||||
steps {
|
||||
zip zipFile: "dist.zip", archive: true, dir: "plate-tool-web/dist/"
|
||||
zip zipFile: "dist.zip", archive: true, dir: "dist/"
|
||||
archiveArtifacts artifacts: "dist.zip", fingerprint: true
|
||||
}
|
||||
}
|
||||
stage('Transfer') {
|
||||
steps {
|
||||
sh 'echo "put -r plate-tool-web/dist/" | sftp oracle'
|
||||
sh 'echo "put -r dist/" | sftp oracle'
|
||||
}
|
||||
}
|
||||
stage('Deploy') {
|
||||
steps {
|
||||
sh '''
|
||||
ssh oracle "sudo rm -rf /usr/share/nginx/html/$OUTPUT_DIR/ && sudo mv dist /usr/share/nginx/html/$OUTPUT_DIR"
|
||||
ssh oracle "sudo rm -rf /usr/share/nginx/html/plate-tool-beta/ && sudo mv dist /usr/share/nginx/html/plate-tool-beta"
|
||||
'''
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
post {
|
||||
always {
|
||||
cleanWs(notFailBuild: true,
|
||||
|
|
674
LICENSE
674
LICENSE
|
@ -1,674 +0,0 @@
|
|||
GNU GENERAL PUBLIC LICENSE
|
||||
Version 3, 29 June 2007
|
||||
|
||||
Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/>
|
||||
Everyone is permitted to copy and distribute verbatim copies
|
||||
of this license document, but changing it is not allowed.
|
||||
|
||||
Preamble
|
||||
|
||||
The GNU General Public License is a free, copyleft license for
|
||||
software and other kinds of works.
|
||||
|
||||
The licenses for most software and other practical works are designed
|
||||
to take away your freedom to share and change the works. By contrast,
|
||||
the GNU General Public License is intended to guarantee your freedom to
|
||||
share and change all versions of a program--to make sure it remains free
|
||||
software for all its users. We, the Free Software Foundation, use the
|
||||
GNU General Public License for most of our software; it applies also to
|
||||
any other work released this way by its authors. You can apply it to
|
||||
your programs, too.
|
||||
|
||||
When we speak of free software, we are referring to freedom, not
|
||||
price. Our General Public Licenses are designed to make sure that you
|
||||
have the freedom to distribute copies of free software (and charge for
|
||||
them if you wish), that you receive source code or can get it if you
|
||||
want it, that you can change the software or use pieces of it in new
|
||||
free programs, and that you know you can do these things.
|
||||
|
||||
To protect your rights, we need to prevent others from denying you
|
||||
these rights or asking you to surrender the rights. Therefore, you have
|
||||
certain responsibilities if you distribute copies of the software, or if
|
||||
you modify it: responsibilities to respect the freedom of others.
|
||||
|
||||
For example, if you distribute copies of such a program, whether
|
||||
gratis or for a fee, you must pass on to the recipients the same
|
||||
freedoms that you received. You must make sure that they, too, receive
|
||||
or can get the source code. And you must show them these terms so they
|
||||
know their rights.
|
||||
|
||||
Developers that use the GNU GPL protect your rights with two steps:
|
||||
(1) assert copyright on the software, and (2) offer you this License
|
||||
giving you legal permission to copy, distribute and/or modify it.
|
||||
|
||||
For the developers' and authors' protection, the GPL clearly explains
|
||||
that there is no warranty for this free software. For both users' and
|
||||
authors' sake, the GPL requires that modified versions be marked as
|
||||
changed, so that their problems will not be attributed erroneously to
|
||||
authors of previous versions.
|
||||
|
||||
Some devices are designed to deny users access to install or run
|
||||
modified versions of the software inside them, although the manufacturer
|
||||
can do so. This is fundamentally incompatible with the aim of
|
||||
protecting users' freedom to change the software. The systematic
|
||||
pattern of such abuse occurs in the area of products for individuals to
|
||||
use, which is precisely where it is most unacceptable. Therefore, we
|
||||
have designed this version of the GPL to prohibit the practice for those
|
||||
products. If such problems arise substantially in other domains, we
|
||||
stand ready to extend this provision to those domains in future versions
|
||||
of the GPL, as needed to protect the freedom of users.
|
||||
|
||||
Finally, every program is threatened constantly by software patents.
|
||||
States should not allow patents to restrict development and use of
|
||||
software on general-purpose computers, but in those that do, we wish to
|
||||
avoid the special danger that patents applied to a free program could
|
||||
make it effectively proprietary. To prevent this, the GPL assures that
|
||||
patents cannot be used to render the program non-free.
|
||||
|
||||
The precise terms and conditions for copying, distribution and
|
||||
modification follow.
|
||||
|
||||
TERMS AND CONDITIONS
|
||||
|
||||
0. Definitions.
|
||||
|
||||
"This License" refers to version 3 of the GNU General Public License.
|
||||
|
||||
"Copyright" also means copyright-like laws that apply to other kinds of
|
||||
works, such as semiconductor masks.
|
||||
|
||||
"The Program" refers to any copyrightable work licensed under this
|
||||
License. Each licensee is addressed as "you". "Licensees" and
|
||||
"recipients" may be individuals or organizations.
|
||||
|
||||
To "modify" a work means to copy from or adapt all or part of the work
|
||||
in a fashion requiring copyright permission, other than the making of an
|
||||
exact copy. The resulting work is called a "modified version" of the
|
||||
earlier work or a work "based on" the earlier work.
|
||||
|
||||
A "covered work" means either the unmodified Program or a work based
|
||||
on the Program.
|
||||
|
||||
To "propagate" a work means to do anything with it that, without
|
||||
permission, would make you directly or secondarily liable for
|
||||
infringement under applicable copyright law, except executing it on a
|
||||
computer or modifying a private copy. Propagation includes copying,
|
||||
distribution (with or without modification), making available to the
|
||||
public, and in some countries other activities as well.
|
||||
|
||||
To "convey" a work means any kind of propagation that enables other
|
||||
parties to make or receive copies. Mere interaction with a user through
|
||||
a computer network, with no transfer of a copy, is not conveying.
|
||||
|
||||
An interactive user interface displays "Appropriate Legal Notices"
|
||||
to the extent that it includes a convenient and prominently visible
|
||||
feature that (1) displays an appropriate copyright notice, and (2)
|
||||
tells the user that there is no warranty for the work (except to the
|
||||
extent that warranties are provided), that licensees may convey the
|
||||
work under this License, and how to view a copy of this License. If
|
||||
the interface presents a list of user commands or options, such as a
|
||||
menu, a prominent item in the list meets this criterion.
|
||||
|
||||
1. Source Code.
|
||||
|
||||
The "source code" for a work means the preferred form of the work
|
||||
for making modifications to it. "Object code" means any non-source
|
||||
form of a work.
|
||||
|
||||
A "Standard Interface" means an interface that either is an official
|
||||
standard defined by a recognized standards body, or, in the case of
|
||||
interfaces specified for a particular programming language, one that
|
||||
is widely used among developers working in that language.
|
||||
|
||||
The "System Libraries" of an executable work include anything, other
|
||||
than the work as a whole, that (a) is included in the normal form of
|
||||
packaging a Major Component, but which is not part of that Major
|
||||
Component, and (b) serves only to enable use of the work with that
|
||||
Major Component, or to implement a Standard Interface for which an
|
||||
implementation is available to the public in source code form. A
|
||||
"Major Component", in this context, means a major essential component
|
||||
(kernel, window system, and so on) of the specific operating system
|
||||
(if any) on which the executable work runs, or a compiler used to
|
||||
produce the work, or an object code interpreter used to run it.
|
||||
|
||||
The "Corresponding Source" for a work in object code form means all
|
||||
the source code needed to generate, install, and (for an executable
|
||||
work) run the object code and to modify the work, including scripts to
|
||||
control those activities. However, it does not include the work's
|
||||
System Libraries, or general-purpose tools or generally available free
|
||||
programs which are used unmodified in performing those activities but
|
||||
which are not part of the work. For example, Corresponding Source
|
||||
includes interface definition files associated with source files for
|
||||
the work, and the source code for shared libraries and dynamically
|
||||
linked subprograms that the work is specifically designed to require,
|
||||
such as by intimate data communication or control flow between those
|
||||
subprograms and other parts of the work.
|
||||
|
||||
The Corresponding Source need not include anything that users
|
||||
can regenerate automatically from other parts of the Corresponding
|
||||
Source.
|
||||
|
||||
The Corresponding Source for a work in source code form is that
|
||||
same work.
|
||||
|
||||
2. Basic Permissions.
|
||||
|
||||
All rights granted under this License are granted for the term of
|
||||
copyright on the Program, and are irrevocable provided the stated
|
||||
conditions are met. This License explicitly affirms your unlimited
|
||||
permission to run the unmodified Program. The output from running a
|
||||
covered work is covered by this License only if the output, given its
|
||||
content, constitutes a covered work. This License acknowledges your
|
||||
rights of fair use or other equivalent, as provided by copyright law.
|
||||
|
||||
You may make, run and propagate covered works that you do not
|
||||
convey, without conditions so long as your license otherwise remains
|
||||
in force. You may convey covered works to others for the sole purpose
|
||||
of having them make modifications exclusively for you, or provide you
|
||||
with facilities for running those works, provided that you comply with
|
||||
the terms of this License in conveying all material for which you do
|
||||
not control copyright. Those thus making or running the covered works
|
||||
for you must do so exclusively on your behalf, under your direction
|
||||
and control, on terms that prohibit them from making any copies of
|
||||
your copyrighted material outside their relationship with you.
|
||||
|
||||
Conveying under any other circumstances is permitted solely under
|
||||
the conditions stated below. Sublicensing is not allowed; section 10
|
||||
makes it unnecessary.
|
||||
|
||||
3. Protecting Users' Legal Rights From Anti-Circumvention Law.
|
||||
|
||||
No covered work shall be deemed part of an effective technological
|
||||
measure under any applicable law fulfilling obligations under article
|
||||
11 of the WIPO copyright treaty adopted on 20 December 1996, or
|
||||
similar laws prohibiting or restricting circumvention of such
|
||||
measures.
|
||||
|
||||
When you convey a covered work, you waive any legal power to forbid
|
||||
circumvention of technological measures to the extent such circumvention
|
||||
is effected by exercising rights under this License with respect to
|
||||
the covered work, and you disclaim any intention to limit operation or
|
||||
modification of the work as a means of enforcing, against the work's
|
||||
users, your or third parties' legal rights to forbid circumvention of
|
||||
technological measures.
|
||||
|
||||
4. Conveying Verbatim Copies.
|
||||
|
||||
You may convey verbatim copies of the Program's source code as you
|
||||
receive it, in any medium, provided that you conspicuously and
|
||||
appropriately publish on each copy an appropriate copyright notice;
|
||||
keep intact all notices stating that this License and any
|
||||
non-permissive terms added in accord with section 7 apply to the code;
|
||||
keep intact all notices of the absence of any warranty; and give all
|
||||
recipients a copy of this License along with the Program.
|
||||
|
||||
You may charge any price or no price for each copy that you convey,
|
||||
and you may offer support or warranty protection for a fee.
|
||||
|
||||
5. Conveying Modified Source Versions.
|
||||
|
||||
You may convey a work based on the Program, or the modifications to
|
||||
produce it from the Program, in the form of source code under the
|
||||
terms of section 4, provided that you also meet all of these conditions:
|
||||
|
||||
a) The work must carry prominent notices stating that you modified
|
||||
it, and giving a relevant date.
|
||||
|
||||
b) The work must carry prominent notices stating that it is
|
||||
released under this License and any conditions added under section
|
||||
7. This requirement modifies the requirement in section 4 to
|
||||
"keep intact all notices".
|
||||
|
||||
c) You must license the entire work, as a whole, under this
|
||||
License to anyone who comes into possession of a copy. This
|
||||
License will therefore apply, along with any applicable section 7
|
||||
additional terms, to the whole of the work, and all its parts,
|
||||
regardless of how they are packaged. This License gives no
|
||||
permission to license the work in any other way, but it does not
|
||||
invalidate such permission if you have separately received it.
|
||||
|
||||
d) If the work has interactive user interfaces, each must display
|
||||
Appropriate Legal Notices; however, if the Program has interactive
|
||||
interfaces that do not display Appropriate Legal Notices, your
|
||||
work need not make them do so.
|
||||
|
||||
A compilation of a covered work with other separate and independent
|
||||
works, which are not by their nature extensions of the covered work,
|
||||
and which are not combined with it such as to form a larger program,
|
||||
in or on a volume of a storage or distribution medium, is called an
|
||||
"aggregate" if the compilation and its resulting copyright are not
|
||||
used to limit the access or legal rights of the compilation's users
|
||||
beyond what the individual works permit. Inclusion of a covered work
|
||||
in an aggregate does not cause this License to apply to the other
|
||||
parts of the aggregate.
|
||||
|
||||
6. Conveying Non-Source Forms.
|
||||
|
||||
You may convey a covered work in object code form under the terms
|
||||
of sections 4 and 5, provided that you also convey the
|
||||
machine-readable Corresponding Source under the terms of this License,
|
||||
in one of these ways:
|
||||
|
||||
a) Convey the object code in, or embodied in, a physical product
|
||||
(including a physical distribution medium), accompanied by the
|
||||
Corresponding Source fixed on a durable physical medium
|
||||
customarily used for software interchange.
|
||||
|
||||
b) Convey the object code in, or embodied in, a physical product
|
||||
(including a physical distribution medium), accompanied by a
|
||||
written offer, valid for at least three years and valid for as
|
||||
long as you offer spare parts or customer support for that product
|
||||
model, to give anyone who possesses the object code either (1) a
|
||||
copy of the Corresponding Source for all the software in the
|
||||
product that is covered by this License, on a durable physical
|
||||
medium customarily used for software interchange, for a price no
|
||||
more than your reasonable cost of physically performing this
|
||||
conveying of source, or (2) access to copy the
|
||||
Corresponding Source from a network server at no charge.
|
||||
|
||||
c) Convey individual copies of the object code with a copy of the
|
||||
written offer to provide the Corresponding Source. This
|
||||
alternative is allowed only occasionally and noncommercially, and
|
||||
only if you received the object code with such an offer, in accord
|
||||
with subsection 6b.
|
||||
|
||||
d) Convey the object code by offering access from a designated
|
||||
place (gratis or for a charge), and offer equivalent access to the
|
||||
Corresponding Source in the same way through the same place at no
|
||||
further charge. You need not require recipients to copy the
|
||||
Corresponding Source along with the object code. If the place to
|
||||
copy the object code is a network server, the Corresponding Source
|
||||
may be on a different server (operated by you or a third party)
|
||||
that supports equivalent copying facilities, provided you maintain
|
||||
clear directions next to the object code saying where to find the
|
||||
Corresponding Source. Regardless of what server hosts the
|
||||
Corresponding Source, you remain obligated to ensure that it is
|
||||
available for as long as needed to satisfy these requirements.
|
||||
|
||||
e) Convey the object code using peer-to-peer transmission, provided
|
||||
you inform other peers where the object code and Corresponding
|
||||
Source of the work are being offered to the general public at no
|
||||
charge under subsection 6d.
|
||||
|
||||
A separable portion of the object code, whose source code is excluded
|
||||
from the Corresponding Source as a System Library, need not be
|
||||
included in conveying the object code work.
|
||||
|
||||
A "User Product" is either (1) a "consumer product", which means any
|
||||
tangible personal property which is normally used for personal, family,
|
||||
or household purposes, or (2) anything designed or sold for incorporation
|
||||
into a dwelling. In determining whether a product is a consumer product,
|
||||
doubtful cases shall be resolved in favor of coverage. For a particular
|
||||
product received by a particular user, "normally used" refers to a
|
||||
typical or common use of that class of product, regardless of the status
|
||||
of the particular user or of the way in which the particular user
|
||||
actually uses, or expects or is expected to use, the product. A product
|
||||
is a consumer product regardless of whether the product has substantial
|
||||
commercial, industrial or non-consumer uses, unless such uses represent
|
||||
the only significant mode of use of the product.
|
||||
|
||||
"Installation Information" for a User Product means any methods,
|
||||
procedures, authorization keys, or other information required to install
|
||||
and execute modified versions of a covered work in that User Product from
|
||||
a modified version of its Corresponding Source. The information must
|
||||
suffice to ensure that the continued functioning of the modified object
|
||||
code is in no case prevented or interfered with solely because
|
||||
modification has been made.
|
||||
|
||||
If you convey an object code work under this section in, or with, or
|
||||
specifically for use in, a User Product, and the conveying occurs as
|
||||
part of a transaction in which the right of possession and use of the
|
||||
User Product is transferred to the recipient in perpetuity or for a
|
||||
fixed term (regardless of how the transaction is characterized), the
|
||||
Corresponding Source conveyed under this section must be accompanied
|
||||
by the Installation Information. But this requirement does not apply
|
||||
if neither you nor any third party retains the ability to install
|
||||
modified object code on the User Product (for example, the work has
|
||||
been installed in ROM).
|
||||
|
||||
The requirement to provide Installation Information does not include a
|
||||
requirement to continue to provide support service, warranty, or updates
|
||||
for a work that has been modified or installed by the recipient, or for
|
||||
the User Product in which it has been modified or installed. Access to a
|
||||
network may be denied when the modification itself materially and
|
||||
adversely affects the operation of the network or violates the rules and
|
||||
protocols for communication across the network.
|
||||
|
||||
Corresponding Source conveyed, and Installation Information provided,
|
||||
in accord with this section must be in a format that is publicly
|
||||
documented (and with an implementation available to the public in
|
||||
source code form), and must require no special password or key for
|
||||
unpacking, reading or copying.
|
||||
|
||||
7. Additional Terms.
|
||||
|
||||
"Additional permissions" are terms that supplement the terms of this
|
||||
License by making exceptions from one or more of its conditions.
|
||||
Additional permissions that are applicable to the entire Program shall
|
||||
be treated as though they were included in this License, to the extent
|
||||
that they are valid under applicable law. If additional permissions
|
||||
apply only to part of the Program, that part may be used separately
|
||||
under those permissions, but the entire Program remains governed by
|
||||
this License without regard to the additional permissions.
|
||||
|
||||
When you convey a copy of a covered work, you may at your option
|
||||
remove any additional permissions from that copy, or from any part of
|
||||
it. (Additional permissions may be written to require their own
|
||||
removal in certain cases when you modify the work.) You may place
|
||||
additional permissions on material, added by you to a covered work,
|
||||
for which you have or can give appropriate copyright permission.
|
||||
|
||||
Notwithstanding any other provision of this License, for material you
|
||||
add to a covered work, you may (if authorized by the copyright holders of
|
||||
that material) supplement the terms of this License with terms:
|
||||
|
||||
a) Disclaiming warranty or limiting liability differently from the
|
||||
terms of sections 15 and 16 of this License; or
|
||||
|
||||
b) Requiring preservation of specified reasonable legal notices or
|
||||
author attributions in that material or in the Appropriate Legal
|
||||
Notices displayed by works containing it; or
|
||||
|
||||
c) Prohibiting misrepresentation of the origin of that material, or
|
||||
requiring that modified versions of such material be marked in
|
||||
reasonable ways as different from the original version; or
|
||||
|
||||
d) Limiting the use for publicity purposes of names of licensors or
|
||||
authors of the material; or
|
||||
|
||||
e) Declining to grant rights under trademark law for use of some
|
||||
trade names, trademarks, or service marks; or
|
||||
|
||||
f) Requiring indemnification of licensors and authors of that
|
||||
material by anyone who conveys the material (or modified versions of
|
||||
it) with contractual assumptions of liability to the recipient, for
|
||||
any liability that these contractual assumptions directly impose on
|
||||
those licensors and authors.
|
||||
|
||||
All other non-permissive additional terms are considered "further
|
||||
restrictions" within the meaning of section 10. If the Program as you
|
||||
received it, or any part of it, contains a notice stating that it is
|
||||
governed by this License along with a term that is a further
|
||||
restriction, you may remove that term. If a license document contains
|
||||
a further restriction but permits relicensing or conveying under this
|
||||
License, you may add to a covered work material governed by the terms
|
||||
of that license document, provided that the further restriction does
|
||||
not survive such relicensing or conveying.
|
||||
|
||||
If you add terms to a covered work in accord with this section, you
|
||||
must place, in the relevant source files, a statement of the
|
||||
additional terms that apply to those files, or a notice indicating
|
||||
where to find the applicable terms.
|
||||
|
||||
Additional terms, permissive or non-permissive, may be stated in the
|
||||
form of a separately written license, or stated as exceptions;
|
||||
the above requirements apply either way.
|
||||
|
||||
8. Termination.
|
||||
|
||||
You may not propagate or modify a covered work except as expressly
|
||||
provided under this License. Any attempt otherwise to propagate or
|
||||
modify it is void, and will automatically terminate your rights under
|
||||
this License (including any patent licenses granted under the third
|
||||
paragraph of section 11).
|
||||
|
||||
However, if you cease all violation of this License, then your
|
||||
license from a particular copyright holder is reinstated (a)
|
||||
provisionally, unless and until the copyright holder explicitly and
|
||||
finally terminates your license, and (b) permanently, if the copyright
|
||||
holder fails to notify you of the violation by some reasonable means
|
||||
prior to 60 days after the cessation.
|
||||
|
||||
Moreover, your license from a particular copyright holder is
|
||||
reinstated permanently if the copyright holder notifies you of the
|
||||
violation by some reasonable means, this is the first time you have
|
||||
received notice of violation of this License (for any work) from that
|
||||
copyright holder, and you cure the violation prior to 30 days after
|
||||
your receipt of the notice.
|
||||
|
||||
Termination of your rights under this section does not terminate the
|
||||
licenses of parties who have received copies or rights from you under
|
||||
this License. If your rights have been terminated and not permanently
|
||||
reinstated, you do not qualify to receive new licenses for the same
|
||||
material under section 10.
|
||||
|
||||
9. Acceptance Not Required for Having Copies.
|
||||
|
||||
You are not required to accept this License in order to receive or
|
||||
run a copy of the Program. Ancillary propagation of a covered work
|
||||
occurring solely as a consequence of using peer-to-peer transmission
|
||||
to receive a copy likewise does not require acceptance. However,
|
||||
nothing other than this License grants you permission to propagate or
|
||||
modify any covered work. These actions infringe copyright if you do
|
||||
not accept this License. Therefore, by modifying or propagating a
|
||||
covered work, you indicate your acceptance of this License to do so.
|
||||
|
||||
10. Automatic Licensing of Downstream Recipients.
|
||||
|
||||
Each time you convey a covered work, the recipient automatically
|
||||
receives a license from the original licensors, to run, modify and
|
||||
propagate that work, subject to this License. You are not responsible
|
||||
for enforcing compliance by third parties with this License.
|
||||
|
||||
An "entity transaction" is a transaction transferring control of an
|
||||
organization, or substantially all assets of one, or subdividing an
|
||||
organization, or merging organizations. If propagation of a covered
|
||||
work results from an entity transaction, each party to that
|
||||
transaction who receives a copy of the work also receives whatever
|
||||
licenses to the work the party's predecessor in interest had or could
|
||||
give under the previous paragraph, plus a right to possession of the
|
||||
Corresponding Source of the work from the predecessor in interest, if
|
||||
the predecessor has it or can get it with reasonable efforts.
|
||||
|
||||
You may not impose any further restrictions on the exercise of the
|
||||
rights granted or affirmed under this License. For example, you may
|
||||
not impose a license fee, royalty, or other charge for exercise of
|
||||
rights granted under this License, and you may not initiate litigation
|
||||
(including a cross-claim or counterclaim in a lawsuit) alleging that
|
||||
any patent claim is infringed by making, using, selling, offering for
|
||||
sale, or importing the Program or any portion of it.
|
||||
|
||||
11. Patents.
|
||||
|
||||
A "contributor" is a copyright holder who authorizes use under this
|
||||
License of the Program or a work on which the Program is based. The
|
||||
work thus licensed is called the contributor's "contributor version".
|
||||
|
||||
A contributor's "essential patent claims" are all patent claims
|
||||
owned or controlled by the contributor, whether already acquired or
|
||||
hereafter acquired, that would be infringed by some manner, permitted
|
||||
by this License, of making, using, or selling its contributor version,
|
||||
but do not include claims that would be infringed only as a
|
||||
consequence of further modification of the contributor version. For
|
||||
purposes of this definition, "control" includes the right to grant
|
||||
patent sublicenses in a manner consistent with the requirements of
|
||||
this License.
|
||||
|
||||
Each contributor grants you a non-exclusive, worldwide, royalty-free
|
||||
patent license under the contributor's essential patent claims, to
|
||||
make, use, sell, offer for sale, import and otherwise run, modify and
|
||||
propagate the contents of its contributor version.
|
||||
|
||||
In the following three paragraphs, a "patent license" is any express
|
||||
agreement or commitment, however denominated, not to enforce a patent
|
||||
(such as an express permission to practice a patent or covenant not to
|
||||
sue for patent infringement). To "grant" such a patent license to a
|
||||
party means to make such an agreement or commitment not to enforce a
|
||||
patent against the party.
|
||||
|
||||
If you convey a covered work, knowingly relying on a patent license,
|
||||
and the Corresponding Source of the work is not available for anyone
|
||||
to copy, free of charge and under the terms of this License, through a
|
||||
publicly available network server or other readily accessible means,
|
||||
then you must either (1) cause the Corresponding Source to be so
|
||||
available, or (2) arrange to deprive yourself of the benefit of the
|
||||
patent license for this particular work, or (3) arrange, in a manner
|
||||
consistent with the requirements of this License, to extend the patent
|
||||
license to downstream recipients. "Knowingly relying" means you have
|
||||
actual knowledge that, but for the patent license, your conveying the
|
||||
covered work in a country, or your recipient's use of the covered work
|
||||
in a country, would infringe one or more identifiable patents in that
|
||||
country that you have reason to believe are valid.
|
||||
|
||||
If, pursuant to or in connection with a single transaction or
|
||||
arrangement, you convey, or propagate by procuring conveyance of, a
|
||||
covered work, and grant a patent license to some of the parties
|
||||
receiving the covered work authorizing them to use, propagate, modify
|
||||
or convey a specific copy of the covered work, then the patent license
|
||||
you grant is automatically extended to all recipients of the covered
|
||||
work and works based on it.
|
||||
|
||||
A patent license is "discriminatory" if it does not include within
|
||||
the scope of its coverage, prohibits the exercise of, or is
|
||||
conditioned on the non-exercise of one or more of the rights that are
|
||||
specifically granted under this License. You may not convey a covered
|
||||
work if you are a party to an arrangement with a third party that is
|
||||
in the business of distributing software, under which you make payment
|
||||
to the third party based on the extent of your activity of conveying
|
||||
the work, and under which the third party grants, to any of the
|
||||
parties who would receive the covered work from you, a discriminatory
|
||||
patent license (a) in connection with copies of the covered work
|
||||
conveyed by you (or copies made from those copies), or (b) primarily
|
||||
for and in connection with specific products or compilations that
|
||||
contain the covered work, unless you entered into that arrangement,
|
||||
or that patent license was granted, prior to 28 March 2007.
|
||||
|
||||
Nothing in this License shall be construed as excluding or limiting
|
||||
any implied license or other defenses to infringement that may
|
||||
otherwise be available to you under applicable patent law.
|
||||
|
||||
12. No Surrender of Others' Freedom.
|
||||
|
||||
If conditions are imposed on you (whether by court order, agreement or
|
||||
otherwise) that contradict the conditions of this License, they do not
|
||||
excuse you from the conditions of this License. If you cannot convey a
|
||||
covered work so as to satisfy simultaneously your obligations under this
|
||||
License and any other pertinent obligations, then as a consequence you may
|
||||
not convey it at all. For example, if you agree to terms that obligate you
|
||||
to collect a royalty for further conveying from those to whom you convey
|
||||
the Program, the only way you could satisfy both those terms and this
|
||||
License would be to refrain entirely from conveying the Program.
|
||||
|
||||
13. Use with the GNU Affero General Public License.
|
||||
|
||||
Notwithstanding any other provision of this License, you have
|
||||
permission to link or combine any covered work with a work licensed
|
||||
under version 3 of the GNU Affero General Public License into a single
|
||||
combined work, and to convey the resulting work. The terms of this
|
||||
License will continue to apply to the part which is the covered work,
|
||||
but the special requirements of the GNU Affero General Public License,
|
||||
section 13, concerning interaction through a network will apply to the
|
||||
combination as such.
|
||||
|
||||
14. Revised Versions of this License.
|
||||
|
||||
The Free Software Foundation may publish revised and/or new versions of
|
||||
the GNU General Public License from time to time. Such new versions will
|
||||
be similar in spirit to the present version, but may differ in detail to
|
||||
address new problems or concerns.
|
||||
|
||||
Each version is given a distinguishing version number. If the
|
||||
Program specifies that a certain numbered version of the GNU General
|
||||
Public License "or any later version" applies to it, you have the
|
||||
option of following the terms and conditions either of that numbered
|
||||
version or of any later version published by the Free Software
|
||||
Foundation. If the Program does not specify a version number of the
|
||||
GNU General Public License, you may choose any version ever published
|
||||
by the Free Software Foundation.
|
||||
|
||||
If the Program specifies that a proxy can decide which future
|
||||
versions of the GNU General Public License can be used, that proxy's
|
||||
public statement of acceptance of a version permanently authorizes you
|
||||
to choose that version for the Program.
|
||||
|
||||
Later license versions may give you additional or different
|
||||
permissions. However, no additional obligations are imposed on any
|
||||
author or copyright holder as a result of your choosing to follow a
|
||||
later version.
|
||||
|
||||
15. Disclaimer of Warranty.
|
||||
|
||||
THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
|
||||
APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
|
||||
HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
|
||||
OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
|
||||
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
|
||||
IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
|
||||
ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
|
||||
|
||||
16. Limitation of Liability.
|
||||
|
||||
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
|
||||
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
|
||||
THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
|
||||
GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
|
||||
USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
|
||||
DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
|
||||
PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
|
||||
EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
|
||||
SUCH DAMAGES.
|
||||
|
||||
17. Interpretation of Sections 15 and 16.
|
||||
|
||||
If the disclaimer of warranty and limitation of liability provided
|
||||
above cannot be given local legal effect according to their terms,
|
||||
reviewing courts shall apply local law that most closely approximates
|
||||
an absolute waiver of all civil liability in connection with the
|
||||
Program, unless a warranty or assumption of liability accompanies a
|
||||
copy of the Program in return for a fee.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
How to Apply These Terms to Your New Programs
|
||||
|
||||
If you develop a new program, and you want it to be of the greatest
|
||||
possible use to the public, the best way to achieve this is to make it
|
||||
free software which everyone can redistribute and change under these terms.
|
||||
|
||||
To do so, attach the following notices to the program. It is safest
|
||||
to attach them to the start of each source file to most effectively
|
||||
state the exclusion of warranty; and each file should have at least
|
||||
the "copyright" line and a pointer to where the full notice is found.
|
||||
|
||||
<one line to give the program's name and a brief idea of what it does.>
|
||||
Copyright (C) <year> <name of author>
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
Also add information on how to contact you by electronic and paper mail.
|
||||
|
||||
If the program does terminal interaction, make it output a short
|
||||
notice like this when it starts in an interactive mode:
|
||||
|
||||
<program> Copyright (C) <year> <name of author>
|
||||
This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
|
||||
This is free software, and you are welcome to redistribute it
|
||||
under certain conditions; type `show c' for details.
|
||||
|
||||
The hypothetical commands `show w' and `show c' should show the appropriate
|
||||
parts of the General Public License. Of course, your program's commands
|
||||
might be different; for a GUI interface, you would use an "about box".
|
||||
|
||||
You should also get your employer (if you work as a programmer) or school,
|
||||
if any, to sign a "copyright disclaimer" for the program, if necessary.
|
||||
For more information on this, and how to apply and follow the GNU GPL, see
|
||||
<https://www.gnu.org/licenses/>.
|
||||
|
||||
The GNU General Public License does not permit incorporating your program
|
||||
into proprietary programs. If your program is a subroutine library, you
|
||||
may consider it more useful to permit linking proprietary applications with
|
||||
the library. If this is what you want to do, use the GNU Lesser General
|
||||
Public License instead of this License. But first, please read
|
||||
<https://www.gnu.org/licenses/why-not-lgpl.html>.
|
131
README.md
131
README.md
|
@ -1,45 +1,29 @@
|
|||
# plate-tool
|
||||
|
||||
A web-based tool for creating and visualizing picklists for your favorite (possibly acoustic) liquid handler.
|
||||
A web-based tool for creating assays for your favorite (acoustic) liquid handler.
|
||||
|
||||
## Table of Contents
|
||||
- [Usage](#usage)
|
||||
- [Plates](#plates)
|
||||
- [Adding plates](#adding-plates)
|
||||
- [Modifying plates](#modifying-plates)
|
||||
- [Transfers](#transfers)
|
||||
- [Adding a transfer](#adding-a-transfer)
|
||||
- [Modifying transfers](#modifying-transfers)
|
||||
- [Importing and Exporting](#importing-and-Exporting)
|
||||
- [Export as CSV](#export-as-csv)
|
||||
- [Export as JSON](#export-as-json)
|
||||
- [Import from JSON](#import-from-json)
|
||||
- [Import Transfer from CSV](#import-transfer-from-csv)
|
||||
- [Other Neat Features](#other-neat-features)
|
||||
- [Installation](#installation)
|
||||
- [Usage](#Usage)
|
||||
- [Installation](#Installation)
|
||||
|
||||
## Usage
|
||||
|
||||
### Plates
|
||||
#### Adding plates
|
||||
### Adding plates
|
||||
When you open plate tool for the first time,
|
||||
you'll be greeted by a message informing you that no plates are selected.
|
||||
|
||||
To add a new plate, click the "Add" button for the corresponding plate type:
|
||||
To add a new plate, click the "New Plate" button:
|
||||
|
||||
Once you've added at least one source plate and one destination plate,
|
||||
click one of each to select them.
|
||||
The right-most pane will now display these plates.
|
||||
|
||||
#### Modifying plates
|
||||
### Modifying and deleting plates
|
||||
Suppose you erroneously created a plate, or misspelled its name.
|
||||
Double click on that plate in the list (top-left pane) and a new modal will open.
|
||||
Here you can rename a plate or delete it.
|
||||
You may also change the format of a plate
|
||||
(note that this will not delete any data if you accidentally switch to a smaller format).
|
||||
|
||||
### Transfers
|
||||
#### Adding a transfer
|
||||
### Adding a transfer
|
||||
Now that you have two plates selected,
|
||||
it's time to add a transfer.
|
||||
We can see all of the properties of our transfer in the bottom-left pane.
|
||||
|
@ -51,7 +35,7 @@ However, it is much easier to click-and-drag the desired region.
|
|||
If we click and hold on a well (see right pane), that specifies our start well.
|
||||
Then, we can drag and subsequently release on our desired end well.
|
||||
|
||||
Our selected wells will be bolded (thicker outline).
|
||||
Our selected wells will be highlighted in light blue for our source plate and light red for our destination plate.
|
||||
You might also notice that some wells are hatched:
|
||||
this indicates wells that will be used in the transfer.
|
||||
Not all selected wells will necessarily be hatched,
|
||||
|
@ -60,7 +44,7 @@ depending on the transfer type and interleave settings.
|
|||
When all of the settings are to your liking, click the "Save" button.
|
||||
Note that it now appears in the "Transfers" section of the list pane.
|
||||
|
||||
#### Modifying transfers
|
||||
### Modifying and deleting transfers
|
||||
If you already saved a transfer and would like to change it,
|
||||
click on its entry in the list.
|
||||
Now change the properties of the transfer as you did during initial creation.
|
||||
|
@ -68,29 +52,6 @@ When finished, click the "Save" button to commit these changes.
|
|||
|
||||
If you no longer need a transfer, select it as above and then click the "Delete" button.
|
||||
|
||||
#### Interleave
|
||||
Interleave can be set for both source and destination plates.
|
||||
Essentially, it can be read as "use every Nth well".
|
||||
That is, a source row interleave of 2 would use every other row of the selected region.
|
||||
It is permitted to have interleave in both dimensions on both plates in a single transfer.
|
||||
|
||||
#### Pooling
|
||||
Consider a case where you want to condense an entire column in a source plate into just one row in the destination.
|
||||
Instead of creating multiple transfers, it is sufficient to set the destination row interleave to 0.
|
||||
An 0 interleave can be thought of as condensing that dimension to a point.
|
||||
For this reason, 0 interleaves are not permitted on source plates (consider what this would represent).
|
||||
Similarly, 0 interleaves are not permitted in replicate transfers (see next section).
|
||||
|
||||
#### Replicates
|
||||
Where pooling permits a "many-to-one" transfer, replicates are "one-to-many".
|
||||
This behavior is achieved by selecting a region in the destination plate instead of just a plate.
|
||||
(If the corners of the destination region are not identical, it is a replicate.)
|
||||
|
||||
Plate-tool will attempt to fit as many copies into the selected destination region as space permits.
|
||||
Partial copies will not be created.
|
||||
That is, if a source region is 3 wells wide and a destination region is 7 wells wide,
|
||||
2 copies will be made, and the 7th well in the destination will be left unused.
|
||||
|
||||
### Importing and Exporting
|
||||
|
||||
#### Export as CSV
|
||||
|
@ -98,23 +59,10 @@ Exporting the transfers we have created to a CSV format is the primary (if not s
|
|||
To do so, first note the "File" tab at the top-left of the screen (above the list pane).
|
||||
Mouse over this tab, and a few more options will be revealed.
|
||||
We want to export: mouse over export and select "Export as CSV".
|
||||
You will be prompted by your browser to select a location for your file.
|
||||
You will be reminded that this is a one-way export (see JSON export/import below),
|
||||
and then prompted by your browser to select a location for your file.
|
||||
|
||||
As of version `0.4.0`, it is possible to pick a CSV export format:
|
||||
Mouse over options, then export, then click "Change CSV export type".
|
||||
In the dialog that opens, select your desired export type.
|
||||
Currently, plate-tool supports:
|
||||
- Normal
|
||||
- This format can be imported by Cellario's cherrypick hook.
|
||||
- Echo Client
|
||||
- This format is useful if you want to run a picklist directly from the
|
||||
Echo Client software.
|
||||
This will export just the transfers between the currently selected plates;
|
||||
I assume you'd be using this feature in a non-automation context
|
||||
and know to load your plates into your Echo yourself.
|
||||
|
||||
#### Export as JSON
|
||||
##### (Saving Your Work)
|
||||
#### Export as JSON (Saving Your Work)
|
||||
Currently, it is not possible to export to a format produced by other similar software.
|
||||
However, you might reasonably want to save a copy of your work
|
||||
either as a backup or to share.
|
||||
|
@ -122,8 +70,7 @@ Mouse over the "File" tab, then "Export" as above, then alternatively select "Ex
|
|||
Your browser will then prompt you to pick a suitable location to save your work as a file.
|
||||
(See note 1 below)
|
||||
|
||||
#### Import from JSON
|
||||
##### (Recovering Your Work)
|
||||
#### Import from JSON (Recovering Your Work)
|
||||
If we want to import one such file, mouse over the "File" tab as before
|
||||
and select "Import", and finally click "Import from JSON".
|
||||
This opens a modal where you are prompted to upload (see note 2)
|
||||
|
@ -131,6 +78,13 @@ your file; it will then be processed and loaded.
|
|||
Keep in mind that this will overwrite any work you currently have open,
|
||||
so you may wish to export first (see above).
|
||||
|
||||
#### Import Transfer from CSV (Using a picklist as a transfer)
|
||||
If you have a CSV generated by another tool (or plate-tool),
|
||||
you can import it as a single transfer.
|
||||
To do so, mouse over the "File" tab, then "Import", and finally "Import Transfer from CSV".
|
||||
When creating transfers via this method, the transfer cannot be edited.
|
||||
This is useful if you have a pre-existing picklist that you would like to visualize in plate-tool.
|
||||
|
||||
_Note 1_: JSON files are plaintext!
|
||||
By default there is little whitespace (this makes comprehending them a challenge)
|
||||
but if we pass it through a "JSON Beautifier" (enter this into your search engine of choice)
|
||||
|
@ -145,28 +99,6 @@ You are welcome to verify (use your browser's developer tools, it should have a
|
|||
that this application does not "phone home".
|
||||
Your data is stored locally (unless you choose to export it and distribute it yourself).
|
||||
|
||||
#### Import Transfer from CSV
|
||||
##### (Using a picklist as a transfer)
|
||||
If you have a CSV generated by another tool (or plate-tool),
|
||||
you can import it as a single transfer.
|
||||
To do so, mouse over the "File" tab, then "Import", and finally "Import Transfer from CSV".
|
||||
When creating transfers via this method, the transfer cannot be edited.
|
||||
This is useful if you have a pre-existing picklist that you would like to visualize in plate-tool.
|
||||
|
||||
You may either manually map plates in a picklist to plates you've already created, or click "Auto" to:
|
||||
1. Generate all plates in the picklist
|
||||
2. Generate transfers for all source:destination pairs.
|
||||
|
||||
_Note_: If you try to use this feature and no plates are available to select,
|
||||
there was likely an issue parsing your picklist.
|
||||
Your browser's console may have guidance as to why parsing failed;
|
||||
plate-tool was probably expecting a different name for a column than was in your file.
|
||||
|
||||
_Note_: If you find a picklist that Cellario *can* import that plate-tool cannot,
|
||||
please email me!
|
||||
Odds are your picklist contains a weird edge case I've not considered,
|
||||
and I would like to fix that!
|
||||
|
||||
### Other Neat Features
|
||||
|
||||
#### Taking Pictures of Plates
|
||||
|
@ -176,7 +108,6 @@ plate-tool will do some magic to take a screenshot of your plate
|
|||
and deposit it in your clipboard for you.
|
||||
You can then paste this into PowerPoint, GIMP, or whereever else
|
||||
you want a pretty picture of a plate.
|
||||
I hope this is helpful for arts and crafts.
|
||||
|
||||
_NOTE:_ I won't guarantee this feature will work in all contexts;
|
||||
it relies on your browser thinking that you have plate-tool open
|
||||
|
@ -193,24 +124,13 @@ To disable the indicators, mouse over "Options" (top-left of screen), then "Styl
|
|||
then click "Toggle transfer hashes".
|
||||
To turn them back on, do the exact same thing.
|
||||
|
||||
#### Transfer Volume Heatmap (Experimental)
|
||||
This can be used to verify that all of the wells in a plate will have the same volume
|
||||
transferred at a glance.
|
||||
Wells will be colored based on the sum of all transfers using that plate.
|
||||
|
||||
To toggle this feature, mouse over "Options", then "Styles", then click "Toggle volume heatmap".
|
||||
|
||||
_NOTE_: The scale for the colors is spaced linearly; if you have a well that is being used
|
||||
significantly more than some others, it may be difficult to see the difference between other wells
|
||||
with more similar volumes.
|
||||
If you have a use case that would benefit from a logarithmic scale here, please let me know.
|
||||
|
||||
## Installation
|
||||
|
||||
Plate tool is hosted [here](https://ilia.moe/cool-stuff/plate-tool/) for your convenience.
|
||||
However, you're absolutely welcome to host your own instance (even locally).
|
||||
Here's how:
|
||||
(_Note:_ If you run Windows you're absolutely fine to install rustup in Powershell, and the subsequent steps should be very similar but likely with different filepaths. I haven't personally validated this. )
|
||||
(_Note:_ If you run Windows you're probably best off doing the following in WSL2)
|
||||
|
||||
1. Make sure you have a working Rust toolchain
|
||||
1. Installing `rustup` is the easiest way to do this. See [their website](https://rustup.rs/),
|
||||
|
@ -220,14 +140,7 @@ Here's how:
|
|||
2. Install [trunk](https://trunkrs.dev/)
|
||||
- Run `cargo install --locked trunk`
|
||||
3. Clone this repository using git
|
||||
4. Enter the plate-tool-web directory and run `trunk serve`
|
||||
4. Enter the project directory and run `trunk serve`
|
||||
- You may need to check where `cargo` is installing binaries by default. For me, they're at `~/.cargo/bin`.
|
||||
If trunk is not automatically placed in your path, you would then run `/your/path/to/.cargo/bin/trunk serve`.
|
||||
- You can instead run `trunk build --release` for a more performant binary.
|
||||
|
||||
## Bug Reports and Further Help
|
||||
|
||||
Any requests for help or assistance with bugs can be sent to platetool(at)ilia.moe
|
||||
|
||||
If reporting a bug, ideally include what it was you were trying to do and, if possible, a screenshot or any logs in
|
||||
your browser's console.
|
||||
|
|
|
@ -7,8 +7,6 @@ dialog {
|
|||
|
||||
color: $color-dark;
|
||||
background: $color-white;
|
||||
|
||||
padding-right: 5%;
|
||||
}
|
||||
|
||||
dialog > form[method="dialog"] {
|
||||
|
@ -37,22 +35,3 @@ dialog > form[method="dialog"] {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
.shifted_dialog {
|
||||
top: 50vh;
|
||||
left: 50vw;
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
.close_button {
|
||||
color: red;
|
||||
position: absolute;
|
||||
top: 5%;
|
||||
right: 2%;
|
||||
background: rgba(0%,0%,0%,10%);
|
||||
|
||||
&:hover {
|
||||
color: rgb(0%,100%,100%);
|
||||
background: rgba(0%,0%,0%,80%);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,18 @@
|
|||
@use "sass:color";
|
||||
@use "../variables" as *;
|
||||
|
||||
div.plate_container {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
justify-content: space-evenly;
|
||||
align-items: center;
|
||||
|
||||
border: 2px solid $color-dark;
|
||||
grid-column: right / right;
|
||||
grid-row: upper / 3;
|
||||
|
||||
h2 {
|
||||
margin-bottom: 1%;
|
||||
text-align: center;
|
||||
}
|
||||
}
|
|
@ -57,35 +57,13 @@ td.current_select div.plate_cell_inner {
|
|||
.W1536 {
|
||||
th {
|
||||
font-size: 0.9rem;
|
||||
line-height: 0px;
|
||||
}
|
||||
tr:first-child {
|
||||
th {
|
||||
line-height: inherit;
|
||||
}
|
||||
}
|
||||
td {
|
||||
padding: 0;
|
||||
}
|
||||
td.current_select div.plate_cell_inner {
|
||||
border: 2px solid black;
|
||||
}
|
||||
}
|
||||
|
||||
.W3456 {
|
||||
th {
|
||||
font-size: 0.6rem;
|
||||
font-size: 0.9rem;
|
||||
line-height: 0px;
|
||||
}
|
||||
tr:first-child {
|
||||
th {
|
||||
line-height: inherit;
|
||||
}
|
||||
}
|
||||
td {
|
||||
padding: 0;
|
||||
}
|
||||
td.current_select div.plate_cell_inner {
|
||||
border: 2px solid black;
|
||||
padding-bottom: 0.4rem;
|
||||
}
|
||||
}
|
|
@ -1,6 +1,5 @@
|
|||
@use "sass:color";
|
||||
@use "../variables" as *;
|
||||
@use "../button" as *;
|
||||
|
||||
div.transfer_menu {
|
||||
position: relative;
|
||||
|
@ -41,11 +40,6 @@ div.transfer_menu {
|
|||
}
|
||||
}
|
||||
|
||||
div.transfer_menu input[type="button"] {
|
||||
@include standard_button;
|
||||
}
|
||||
|
||||
|
||||
input {
|
||||
text-align: center;
|
||||
margin-left: 0.5em;
|
||||
|
@ -56,10 +50,10 @@ input {
|
|||
padding: 0;
|
||||
|
||||
&[type="text"] {
|
||||
width: 6em;
|
||||
width: 4em;
|
||||
}
|
||||
&[name="name"] {
|
||||
width: calc(100% - 6em); // Override above
|
||||
width: 6em; // Override above
|
||||
}
|
||||
&[type="number"] {
|
||||
width: 2em;
|
|
@ -1,6 +1,5 @@
|
|||
@use "sass:color";
|
||||
@use "../variables" as *;
|
||||
@use "../button" as *;
|
||||
|
||||
$selection-border-width: 2px;
|
||||
|
||||
|
@ -54,17 +53,3 @@ div.tree li {
|
|||
background: color.change($color-light, $alpha: 0.2);
|
||||
}
|
||||
}
|
||||
|
||||
div.tree--header {
|
||||
margin-top: 1%;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
div.tree--header button {
|
||||
@include standard_button;
|
||||
|
||||
&::before {
|
||||
content: "Add";
|
||||
}
|
||||
}
|
|
@ -30,7 +30,6 @@ div.upper_menu {
|
|||
margin: 0;
|
||||
cursor: pointer;
|
||||
font-size: calc($menu-height*0.7);
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
* {
|
|
@ -4,7 +4,6 @@
|
|||
<meta charset="utf-8" />
|
||||
<link data-trunk rel="scss" href="assets/scss/index.scss">
|
||||
<link data-trunk rel="copy-dir" href="assets/fonts">
|
||||
<link data-trunk rel="rust" data-bin="plate-tool-web" />
|
||||
<script data-trunk src="assets/js/screenshot_utility.js"></script>
|
||||
<script data-trunk src="assets/js/html2canvas.js"></script>
|
||||
<title>Plate Tool</title>
|
|
@ -1,2 +0,0 @@
|
|||
/target
|
||||
/dist
|
|
@ -1,339 +0,0 @@
|
|||
# This file is automatically @generated by Cargo.
|
||||
# It is not intended for manual editing.
|
||||
version = 3
|
||||
|
||||
[[package]]
|
||||
name = "aho-corasick"
|
||||
version = "1.1.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b2969dcb958b36655471fc61f7e416fa76033bdd4bfed0678d8fee1e2d07a1f0"
|
||||
dependencies = [
|
||||
"memchr",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "atomic"
|
||||
version = "0.5.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "c59bdb34bc650a32731b31bd8f0829cc15d24a708ee31559e0bb34f2bc320cba"
|
||||
|
||||
[[package]]
|
||||
name = "bumpalo"
|
||||
version = "3.14.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "7f30e7476521f6f8af1a1c4c0b8cc94f0bee37d91763d0ca2665f299b6cd8aec"
|
||||
|
||||
[[package]]
|
||||
name = "cfg-if"
|
||||
version = "1.0.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
|
||||
|
||||
[[package]]
|
||||
name = "csv"
|
||||
version = "1.3.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ac574ff4d437a7b5ad237ef331c17ccca63c46479e5b5453eb8e10bb99a759fe"
|
||||
dependencies = [
|
||||
"csv-core",
|
||||
"itoa",
|
||||
"ryu",
|
||||
"serde",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "csv-core"
|
||||
version = "0.1.11"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "5efa2b3d7902f4b634a20cae3c9c4e6209dc4779feb6863329607560143efa70"
|
||||
dependencies = [
|
||||
"memchr",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "getrandom"
|
||||
version = "0.2.12"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "190092ea657667030ac6a35e305e62fc4dd69fd98ac98631e5d3a2b1575a12b5"
|
||||
dependencies = [
|
||||
"cfg-if",
|
||||
"js-sys",
|
||||
"libc",
|
||||
"wasi",
|
||||
"wasm-bindgen",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "itoa"
|
||||
version = "1.0.10"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b1a46d1a171d865aa5f83f92695765caa047a9b4cbae2cbf37dbd613a793fd4c"
|
||||
|
||||
[[package]]
|
||||
name = "js-sys"
|
||||
version = "0.3.68"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "406cda4b368d531c842222cf9d2600a9a4acce8d29423695379c6868a143a9ee"
|
||||
dependencies = [
|
||||
"wasm-bindgen",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "libc"
|
||||
version = "0.2.153"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "9c198f91728a82281a64e1f4f9eeb25d82cb32a5de251c6bd1b5154d63a8e7bd"
|
||||
|
||||
[[package]]
|
||||
name = "log"
|
||||
version = "0.4.20"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b5e6163cb8c49088c2c36f57875e58ccd8c87c7427f7fbd50ea6710b2f3f2e8f"
|
||||
|
||||
[[package]]
|
||||
name = "memchr"
|
||||
version = "2.7.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "523dc4f511e55ab87b694dc30d0f820d60906ef06413f93d4d7a1385599cc149"
|
||||
|
||||
[[package]]
|
||||
name = "once_cell"
|
||||
version = "1.19.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "3fdb12b2476b595f9358c5161aa467c2438859caa136dec86c26fdd2efe17b92"
|
||||
|
||||
[[package]]
|
||||
name = "plate-tool-lib"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"csv",
|
||||
"getrandom",
|
||||
"log",
|
||||
"rand",
|
||||
"regex",
|
||||
"serde",
|
||||
"serde_json",
|
||||
"uuid",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "ppv-lite86"
|
||||
version = "0.2.17"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "5b40af805b3121feab8a3c29f04d8ad262fa8e0561883e7653e024ae4479e6de"
|
||||
|
||||
[[package]]
|
||||
name = "proc-macro2"
|
||||
version = "1.0.78"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e2422ad645d89c99f8f3e6b88a9fdeca7fabeac836b1002371c4367c8f984aae"
|
||||
dependencies = [
|
||||
"unicode-ident",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "quote"
|
||||
version = "1.0.35"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "291ec9ab5efd934aaf503a6466c5d5251535d108ee747472c3977cc5acc868ef"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rand"
|
||||
version = "0.8.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404"
|
||||
dependencies = [
|
||||
"libc",
|
||||
"rand_chacha",
|
||||
"rand_core",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rand_chacha"
|
||||
version = "0.3.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88"
|
||||
dependencies = [
|
||||
"ppv-lite86",
|
||||
"rand_core",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rand_core"
|
||||
version = "0.6.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c"
|
||||
dependencies = [
|
||||
"getrandom",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "regex"
|
||||
version = "1.10.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b62dbe01f0b06f9d8dc7d49e05a0785f153b00b2c227856282f671e0318c9b15"
|
||||
dependencies = [
|
||||
"aho-corasick",
|
||||
"memchr",
|
||||
"regex-automata",
|
||||
"regex-syntax",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "regex-automata"
|
||||
version = "0.4.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "5bb987efffd3c6d0d8f5f89510bb458559eab11e4f869acb20bf845e016259cd"
|
||||
dependencies = [
|
||||
"aho-corasick",
|
||||
"memchr",
|
||||
"regex-syntax",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "regex-syntax"
|
||||
version = "0.8.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "c08c74e62047bb2de4ff487b251e4a92e24f48745648451635cec7d591162d9f"
|
||||
|
||||
[[package]]
|
||||
name = "ryu"
|
||||
version = "1.0.16"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f98d2aa92eebf49b69786be48e4477826b256916e84a57ff2a4f21923b48eb4c"
|
||||
|
||||
[[package]]
|
||||
name = "serde"
|
||||
version = "1.0.196"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "870026e60fa08c69f064aa766c10f10b1d62db9ccd4d0abb206472bee0ce3b32"
|
||||
dependencies = [
|
||||
"serde_derive",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "serde_derive"
|
||||
version = "1.0.196"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "33c85360c95e7d137454dc81d9a4ed2b8efd8fbe19cee57357b32b9771fccb67"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "serde_json"
|
||||
version = "1.0.113"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "69801b70b1c3dac963ecb03a364ba0ceda9cf60c71cfe475e99864759c8b8a79"
|
||||
dependencies = [
|
||||
"itoa",
|
||||
"ryu",
|
||||
"serde",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "syn"
|
||||
version = "2.0.48"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "0f3531638e407dfc0814761abb7c00a5b54992b849452a0646b7f65c9f770f3f"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"unicode-ident",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "unicode-ident"
|
||||
version = "1.0.12"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b"
|
||||
|
||||
[[package]]
|
||||
name = "uuid"
|
||||
version = "1.7.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f00cc9702ca12d3c81455259621e676d0f7251cec66a21e98fe2e9a37db93b2a"
|
||||
dependencies = [
|
||||
"atomic",
|
||||
"getrandom",
|
||||
"rand",
|
||||
"serde",
|
||||
"uuid-macro-internal",
|
||||
"wasm-bindgen",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "uuid-macro-internal"
|
||||
version = "1.7.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "7abb14ae1a50dad63eaa768a458ef43d298cd1bd44951677bd10b732a9ba2a2d"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "wasi"
|
||||
version = "0.11.0+wasi-snapshot-preview1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423"
|
||||
|
||||
[[package]]
|
||||
name = "wasm-bindgen"
|
||||
version = "0.2.91"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "c1e124130aee3fb58c5bdd6b639a0509486b0338acaaae0c84a5124b0f588b7f"
|
||||
dependencies = [
|
||||
"cfg-if",
|
||||
"wasm-bindgen-macro",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "wasm-bindgen-backend"
|
||||
version = "0.2.91"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "c9e7e1900c352b609c8488ad12639a311045f40a35491fb69ba8c12f758af70b"
|
||||
dependencies = [
|
||||
"bumpalo",
|
||||
"log",
|
||||
"once_cell",
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn",
|
||||
"wasm-bindgen-shared",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "wasm-bindgen-macro"
|
||||
version = "0.2.91"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b30af9e2d358182b5c7449424f017eba305ed32a7010509ede96cdc4696c46ed"
|
||||
dependencies = [
|
||||
"quote",
|
||||
"wasm-bindgen-macro-support",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "wasm-bindgen-macro-support"
|
||||
version = "0.2.91"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "642f325be6301eb8107a83d12a8ac6c1e1c54345a7ef1a9261962dfefda09e66"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn",
|
||||
"wasm-bindgen-backend",
|
||||
"wasm-bindgen-shared",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "wasm-bindgen-shared"
|
||||
version = "0.2.91"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "4f186bd2dcf04330886ce82d6f33dd75a7bfcf69ecf5763b89fcde53b6ac9838"
|
|
@ -1,19 +0,0 @@
|
|||
[package]
|
||||
name = "plate-tool-lib"
|
||||
version = "0.5.0"
|
||||
edition = "2021"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
log = "0.4"
|
||||
regex = "1"
|
||||
uuid = { version = "1.6", features = ["v7", "fast-rng", "macro-diagnostics", "js", "serde"] }
|
||||
serde = { version = "1.0", features = ["derive"] }
|
||||
serde_json = "1.0"
|
||||
csv = "1.2"
|
||||
getrandom = { version = "0.2", features = ["js"] }
|
||||
rand = { version = "0.8", features = ["small_rng"] }
|
||||
lazy_static = "1.4"
|
||||
serde_with = { version = "3.9.0", features = ["json"] }
|
||||
serde_yaml = "0.9.34"
|
|
@ -1,27 +0,0 @@
|
|||
use serde::Serialize;
|
||||
|
||||
use super::TransferRecord;
|
||||
|
||||
/// Format preferred by the Echo Client when using the Pick-List function.
|
||||
///
|
||||
/// Note that this does not export plate info!
|
||||
/// Exports of this type should combine all transfers between the two actively selected plates.
|
||||
#[derive(Serialize, Debug)]
|
||||
pub struct EchoClientTransferRecord {
|
||||
#[serde(rename = "SrcWell")]
|
||||
pub source_well: String,
|
||||
#[serde(rename = "DestWell")]
|
||||
pub destination_well: String,
|
||||
#[serde(rename = "XferVol")]
|
||||
pub volume: f32,
|
||||
}
|
||||
|
||||
impl From<TransferRecord> for EchoClientTransferRecord {
|
||||
fn from(value: TransferRecord) -> Self {
|
||||
EchoClientTransferRecord {
|
||||
source_well: value.source_well,
|
||||
destination_well: value.destination_well,
|
||||
volume: value.volume,
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,231 +0,0 @@
|
|||
//! Auto module for importing picklists without creating plates first
|
||||
//!
|
||||
//! Before the auto module, it was necessary for a user to create the plates
|
||||
//! used in an imported transfer before import.
|
||||
|
||||
use super::{string_well_to_pt, TransferRecord, read_csv};
|
||||
use crate::plate::{PlateFormat, PlateType};
|
||||
use crate::plate_instances::PlateInstance;
|
||||
use crate::transfer::Transfer;
|
||||
use crate::transfer_volume::{TransferVolume, VolumeMaps};
|
||||
use crate::Well;
|
||||
use crate::transfer_region::{CustomRegion, Region, TransferRegion};
|
||||
|
||||
use std::collections::{HashSet, HashMap};
|
||||
|
||||
pub struct AutoOutput {
|
||||
pub sources: Vec<PlateInstance>,
|
||||
pub destinations: Vec<PlateInstance>,
|
||||
pub transfers: Vec<Transfer>,
|
||||
}
|
||||
|
||||
/// Two lists of plates that are guaranteed to be unique (no duplicate plates)
|
||||
struct UniquePlates {
|
||||
sources: Vec<PlateInstance>,
|
||||
destinations: Vec<PlateInstance>,
|
||||
}
|
||||
|
||||
const W96_COL_MAX: u8 = 12;
|
||||
const W96_ROW_MAX: u8 = 8;
|
||||
const W384_COL_MAX: u8 = 24;
|
||||
const W384_ROW_MAX: u8 = 16;
|
||||
const W1536_COL_MAX: u8 = 48;
|
||||
const W1536_ROW_MAX: u8 = 32;
|
||||
|
||||
/// Main function for the auto module
|
||||
/// Takes a list of pre-deserialized transfer records and generates output
|
||||
/// This output is 3 lists of:
|
||||
/// 1. The source plates used in the picklist
|
||||
/// 2. The destination plates used in the picklist
|
||||
/// 3. All of the transfers between those plates
|
||||
pub fn auto(records: &[TransferRecord]) -> AutoOutput {
|
||||
let unique_plates = find_unique_plates(records);
|
||||
let transfers = get_transfer_for_all_pairs(records, &unique_plates);
|
||||
|
||||
AutoOutput { sources: unique_plates.sources, destinations: unique_plates.destinations, transfers }
|
||||
}
|
||||
|
||||
/// Helper function that reads a CSV and immediately dumps the resulting transfer records
|
||||
/// into the auto function defined in this module.
|
||||
pub fn read_csv_auto(data: &str) -> AutoOutput {
|
||||
let transfer_records = read_csv(data);
|
||||
auto(&transfer_records)
|
||||
}
|
||||
|
||||
/// Looks through a list of transfer records and generates two lists
|
||||
/// of all of the unique plates found in those transfers.
|
||||
/// Worth noting that the Transfer struct requires two associated PlateInstances;
|
||||
/// these PlateInstance structs are generated here---they are not present in a TransferRecord.
|
||||
/// See notes on the UniquePlates struct
|
||||
fn find_unique_plates(records: &[TransferRecord]) -> UniquePlates {
|
||||
let mut source_names: HashSet<&str> = HashSet::new();
|
||||
let mut destination_names: HashSet<&str> = HashSet::new();
|
||||
|
||||
for record in records {
|
||||
source_names.insert(&record.source_plate);
|
||||
destination_names.insert(&record.destination_plate);
|
||||
}
|
||||
|
||||
let mut sources: Vec<PlateInstance> = Vec::with_capacity(source_names.len());
|
||||
for source_name in source_names {
|
||||
let filtered_records: Vec<&TransferRecord> = records
|
||||
.iter()
|
||||
.filter(|x| x.source_plate == source_name)
|
||||
.collect();
|
||||
let format_guess = guess_plate_size(&filtered_records, PlateType::Source);
|
||||
sources.push(PlateInstance::new(
|
||||
PlateType::Source,
|
||||
format_guess,
|
||||
source_name.to_string(),
|
||||
))
|
||||
}
|
||||
|
||||
let mut destinations: Vec<PlateInstance> = Vec::with_capacity(destination_names.len());
|
||||
for destination_name in destination_names {
|
||||
let filtered_records: Vec<&TransferRecord> = records
|
||||
.iter()
|
||||
.filter(|x| x.destination_plate == destination_name)
|
||||
.collect();
|
||||
let format_guess = guess_plate_size(&filtered_records, PlateType::Destination);
|
||||
destinations.push(PlateInstance::new(
|
||||
PlateType::Destination,
|
||||
format_guess,
|
||||
destination_name.to_string(),
|
||||
))
|
||||
}
|
||||
|
||||
UniquePlates {
|
||||
sources,
|
||||
destinations,
|
||||
}
|
||||
}
|
||||
|
||||
/// Tries to guess the format of a plate given the southeastern-est well used.
|
||||
/// A picklist does not necessarily contain plate format info; this method guesses
|
||||
/// based on the well furthest from A1 that exists in a transfer.
|
||||
/// It's possible for a 1536 well plate to be seen as a 384 well if all of the wells
|
||||
/// used could have fit in the top-left quadrant of a 384 well plate
|
||||
/// (i.e. all lower than P24 in this case)
|
||||
fn guess_plate_size(plate_filtered_records: &[&TransferRecord], which: PlateType) -> PlateFormat {
|
||||
let mut guess = PlateFormat::W96; // Never guess smaller than 96
|
||||
for record in plate_filtered_records {
|
||||
if let Some(Well { row, col }) = string_well_to_pt(match which {
|
||||
PlateType::Source => &record.source_well,
|
||||
PlateType::Destination => &record.destination_well,
|
||||
}) {
|
||||
if row > W1536_ROW_MAX || col > W1536_COL_MAX {
|
||||
return PlateFormat::W3456;
|
||||
} else if row > W384_ROW_MAX || col > W384_COL_MAX {
|
||||
guess = PlateFormat::W1536;
|
||||
} else if row > W96_ROW_MAX || col > W96_COL_MAX {
|
||||
guess = PlateFormat::W384;
|
||||
}
|
||||
}
|
||||
}
|
||||
guess
|
||||
}
|
||||
|
||||
fn get_transfer_for_all_pairs(
|
||||
records: &[TransferRecord],
|
||||
unique_plates: &UniquePlates,
|
||||
) -> Vec<Transfer> {
|
||||
let mut transfers: Vec<Transfer> = Vec::new();
|
||||
for source_instance in &unique_plates.sources {
|
||||
for destination_instance in &unique_plates.destinations {
|
||||
if let Some(transfer) =
|
||||
get_transfer_for_pair(records, source_instance, destination_instance)
|
||||
{
|
||||
transfers.push(transfer);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
transfers
|
||||
}
|
||||
|
||||
/// Given a source and destination plate, get all of the wells transferred
|
||||
/// from source to destination and turn this into a Transfer.
|
||||
///
|
||||
/// Note that even if you have what looks like two separate transfers,
|
||||
/// this will join all transfers for a given source-dest pair.
|
||||
/// For example:
|
||||
/// Consider expanding all of src:A1 to the column dst:A
|
||||
/// and src:B1 -> row dst:1
|
||||
/// If you were making this transfer in plate tool, it would be easiest
|
||||
/// to do this as two separate transfers.
|
||||
/// On import, this would be seen as one transfer.
|
||||
fn get_transfer_for_pair(
|
||||
records: &[TransferRecord],
|
||||
source: &PlateInstance,
|
||||
destination: &PlateInstance,
|
||||
) -> Option<Transfer> {
|
||||
let source_name: &str = &source.name;
|
||||
let destination_name: &str = &destination.name;
|
||||
|
||||
let mut filtered_records = records
|
||||
.iter()
|
||||
.filter(|x| x.source_plate == source_name && x.destination_plate == destination_name)
|
||||
.peekable();
|
||||
|
||||
filtered_records.peek()?;
|
||||
|
||||
let mut source_wells: HashSet<Well> = HashSet::new();
|
||||
let mut destination_wells: HashSet<Well> = HashSet::new();
|
||||
|
||||
// Volume Hash Maps
|
||||
let mut source_only_volume_map: HashMap<Well, f32> = HashMap::new();
|
||||
let mut destination_only_volume_map: HashMap<Well, f32> = HashMap::new();
|
||||
let mut paired_volume_map: HashMap<(Well, Well), f32> = HashMap::new();
|
||||
|
||||
for record in filtered_records {
|
||||
let source_point_opt = string_well_to_pt(&record.source_well);
|
||||
let destination_point_opt = string_well_to_pt(&record.destination_well);
|
||||
|
||||
if source_point_opt.and(destination_point_opt).is_some() {
|
||||
let source_point = source_point_opt.unwrap();
|
||||
let destination_point = destination_point_opt.unwrap();
|
||||
|
||||
source_wells.insert(source_point);
|
||||
destination_wells.insert(destination_point);
|
||||
|
||||
source_only_volume_map.entry(source_point).and_modify(|v| *v += record.volume)
|
||||
.or_insert(record.volume);
|
||||
destination_only_volume_map.entry(destination_point).and_modify(|v| *v += record.volume)
|
||||
.or_insert(record.volume);
|
||||
paired_volume_map.entry((source_point, destination_point)).and_modify(|v| *v += record.volume)
|
||||
.or_insert_with(|| record.volume); // No idea why this one needs to be different
|
||||
}
|
||||
}
|
||||
let source_wells_vec: Vec<Well> = source_wells.into_iter().collect();
|
||||
let destination_wells_vec: Vec<Well> = destination_wells.into_iter().collect();
|
||||
|
||||
let transfer_volume: TransferVolume = TransferVolume::WellMap(VolumeMaps {
|
||||
source_only: source_only_volume_map,
|
||||
destination_only: destination_only_volume_map,
|
||||
paired: paired_volume_map,
|
||||
});
|
||||
|
||||
let custom_region: Region =
|
||||
Region::Custom(CustomRegion::new(source_wells_vec, destination_wells_vec));
|
||||
|
||||
let transfer_region = TransferRegion {
|
||||
source_plate: source.plate,
|
||||
dest_plate: destination.plate,
|
||||
interleave_source: (1, 1),
|
||||
interleave_dest: (1, 1),
|
||||
source_region: custom_region.clone(),
|
||||
dest_region: custom_region,
|
||||
};
|
||||
|
||||
let transfer_name = format!("{} to {}", source.name, destination.name);
|
||||
|
||||
let mut transfer = Transfer::new(
|
||||
source.clone(),
|
||||
destination.clone(),
|
||||
transfer_region,
|
||||
transfer_name,
|
||||
);
|
||||
transfer.volume = transfer_volume;
|
||||
|
||||
Some(transfer)
|
||||
}
|
|
@ -1,109 +0,0 @@
|
|||
use crate::transfer_volume::TransferVolume;
|
||||
use crate::util::*;
|
||||
use crate::{transfer::Transfer, Well};
|
||||
|
||||
use super::{
|
||||
alternative_formats::EchoClientTransferRecord, mangle_headers::mangle_headers,
|
||||
transfer_record::TransferRecordDeserializeIntermediate, TransferRecord,
|
||||
};
|
||||
use lazy_static::lazy_static;
|
||||
use regex::Regex;
|
||||
use std::error::Error;
|
||||
|
||||
pub fn transfer_to_records(
|
||||
tr: &Transfer,
|
||||
src_barcode: &str,
|
||||
dest_barcode: &str,
|
||||
) -> Vec<TransferRecord> {
|
||||
let source_wells = tr.transfer_region.get_source_wells();
|
||||
let map = tr.transfer_region.calculate_map();
|
||||
|
||||
let mut records: Vec<TransferRecord> = vec![];
|
||||
if let TransferVolume::WellMap(wm) = &tr.volume {
|
||||
log::debug!("{:?}\n{}", wm.paired, wm.paired.len());
|
||||
}
|
||||
|
||||
for s_well in source_wells {
|
||||
let dest_wells = map(s_well);
|
||||
if let Some(dest_wells) = dest_wells {
|
||||
for d_well in dest_wells {
|
||||
// Get volume here:
|
||||
let volume: f32 = match &tr.volume {
|
||||
TransferVolume::Single(x) => *x, // If all have the same value, use it everywhere
|
||||
TransferVolume::WellMap(wm) => {
|
||||
*wm.paired.get(&(s_well, d_well)).unwrap_or(&2.5f32)
|
||||
}
|
||||
};
|
||||
|
||||
records.push(TransferRecord {
|
||||
source_plate: src_barcode.to_string(),
|
||||
source_well: format!("{}{}", num_to_letters(s_well.row).unwrap(), s_well.col),
|
||||
destination_plate: dest_barcode.to_string(),
|
||||
destination_well: format!(
|
||||
"{}{}",
|
||||
num_to_letters(d_well.row).unwrap(),
|
||||
d_well.col
|
||||
),
|
||||
volume,
|
||||
concentration: None,
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
records
|
||||
}
|
||||
|
||||
pub fn records_to_csv(trs: Vec<TransferRecord>) -> Result<String, Box<dyn Error>> {
|
||||
let mut wtr = csv::WriterBuilder::new().from_writer(vec![]);
|
||||
for record in trs {
|
||||
wtr.serialize(record)?
|
||||
}
|
||||
let data = String::from_utf8(wtr.into_inner()?)?;
|
||||
Ok(data)
|
||||
}
|
||||
|
||||
pub fn records_to_echo_client_csv(trs: Vec<TransferRecord>) -> Result<String, Box<dyn Error>> {
|
||||
let mut wtr = csv::WriterBuilder::new().from_writer(vec![]);
|
||||
for record in trs {
|
||||
wtr.serialize(Into::<EchoClientTransferRecord>::into(record))?
|
||||
}
|
||||
let data = String::from_utf8(wtr.into_inner()?)?;
|
||||
Ok(data)
|
||||
}
|
||||
|
||||
/// Converts "spreadsheet format" well identification to coordinates
|
||||
pub fn string_well_to_pt(input: &str) -> Option<Well> {
|
||||
lazy_static! {
|
||||
static ref REGEX: Regex = Regex::new(r"([A-Z,a-z]+)(\d+)").unwrap();
|
||||
|
||||
// Can this be removed?
|
||||
static ref REGEX_ALT: Regex = Regex::new(r"(\d+)").unwrap();
|
||||
}
|
||||
if let Some(c1) = REGEX.captures(input) {
|
||||
if let (Some(row), Some(col)) = (letters_to_num(&c1[1]), c1[2].parse::<u8>().ok()) {
|
||||
return Some(Well { row, col });
|
||||
} else {
|
||||
return None;
|
||||
}
|
||||
}
|
||||
None
|
||||
}
|
||||
|
||||
pub fn read_csv(data: &str) -> Vec<TransferRecord> {
|
||||
let modified = mangle_headers(data);
|
||||
let mut rdr = csv::Reader::from_reader(modified.as_bytes());
|
||||
let mut records: Vec<TransferRecord> = Vec::new();
|
||||
for record in rdr.deserialize::<TransferRecordDeserializeIntermediate>() {
|
||||
match record {
|
||||
Ok(r) => {
|
||||
if !r.is_empty() {
|
||||
records.push(r.into());
|
||||
}
|
||||
}
|
||||
Err(e) => {
|
||||
log::debug!("{:?}", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
records
|
||||
}
|
|
@ -1,74 +0,0 @@
|
|||
//! This contains the `mangle_headers` function and its helpers
|
||||
//!
|
||||
//! Mangling headers is necessary to normalize CSV column names before
|
||||
//! deserialization can be done by Serde.
|
||||
//! Field detection occurs in `detect_field`.
|
||||
//!
|
||||
//! As of lib 0.4.0, unrecognized headers are ignored and left untouched by mangling.
|
||||
//! However, they are not passed through to any subsequent exports from plate-tool.
|
||||
|
||||
pub fn mangle_headers(data: &str) -> String {
|
||||
let (header, rows) = data.split_at(data.find('\n').unwrap());
|
||||
let fields = header.trim().split(',');
|
||||
let mut modified_headers: Vec<String> = Vec::new();
|
||||
for field in fields {
|
||||
if let Some(f) = detect_field(field) {
|
||||
modified_headers.push(f.to_string());
|
||||
} else {
|
||||
log::debug!("Unk field: {:?}", field)
|
||||
}
|
||||
}
|
||||
|
||||
modified_headers.join(",") + "\n" + rows
|
||||
}
|
||||
|
||||
fn detect_field(field: &str) -> Option<Field> {
|
||||
// NOTE: Don't return none! Consider refactor to -> Field later on.
|
||||
// Returning none means a field will be dropped, which requires the user to manually drop
|
||||
// columns from their picklist.
|
||||
match field.trim().to_lowercase() {
|
||||
x if x.contains("source") || x.contains("src") => match x {
|
||||
_ if x.contains("plate") || x.contains("barcode") => Some(Field::SourcePlate),
|
||||
_ if x.contains("well") => Some(Field::SourceWell),
|
||||
_ if x.contains("format") || x.contains("fmt") => Some(Field::SourceFormat),
|
||||
_ => Some(Field::Other(x)), // Retain unknown fields
|
||||
},
|
||||
x if x.contains("destination") || x.contains("dest") => match x {
|
||||
_ if x.contains("plate") || x.contains("barcode") => Some(Field::DestinationPlate),
|
||||
_ if x.contains("well") => Some(Field::DestinationWell),
|
||||
_ if x.contains("format") || x.contains("fmt") => Some(Field::DestinationFormat),
|
||||
_ => Some(Field::Other(x)), // Retain unknown fields
|
||||
},
|
||||
x if x.contains("volume") => Some(Field::Volume),
|
||||
x if x.contains("concentration") => Some(Field::Concentration),
|
||||
x => Some(Field::Other(x)), // Retain unknown fields
|
||||
}
|
||||
}
|
||||
|
||||
enum Field {
|
||||
SourcePlate,
|
||||
DestinationPlate,
|
||||
SourceWell,
|
||||
DestinationWell,
|
||||
SourceFormat,
|
||||
DestinationFormat,
|
||||
Volume,
|
||||
Concentration,
|
||||
Other(String),
|
||||
}
|
||||
|
||||
impl ToString for Field {
|
||||
fn to_string(&self) -> String {
|
||||
match self {
|
||||
Field::SourcePlate => "sourceplate".to_string(),
|
||||
Field::DestinationPlate => "destinationplate".to_string(),
|
||||
Field::SourceWell => "sourcewell".to_string(),
|
||||
Field::DestinationWell => "destinationwell".to_string(),
|
||||
Field::SourceFormat => "sourceformat".to_string(),
|
||||
Field::DestinationFormat => "destinationformat".to_string(),
|
||||
Field::Volume => "volume".to_string(),
|
||||
Field::Concentration => "concentration".to_string(),
|
||||
Field::Other(x) => x.to_string(),
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,10 +0,0 @@
|
|||
mod transfer_record;
|
||||
mod conversion;
|
||||
mod auto;
|
||||
mod mangle_headers;
|
||||
mod alternative_formats;
|
||||
|
||||
pub use transfer_record::TransferRecord;
|
||||
pub use conversion::*;
|
||||
|
||||
pub use auto::{auto, read_csv_auto};
|
|
@ -1,107 +0,0 @@
|
|||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use crate::{plate::PlateFormat, util::num_to_letters};
|
||||
|
||||
/// Represents a single line of a CSV picklist.
|
||||
/// In practice, this is generated from the deserialize intermediate.
|
||||
/// A list of `TransferRecord`s can be used to create a `transfer::Transfer` struct;
|
||||
/// see the `auto` module for this.
|
||||
#[derive(Serialize, Debug, Clone)]
|
||||
pub struct TransferRecord {
|
||||
#[serde(rename = "Source Barcode")]
|
||||
pub source_plate: String,
|
||||
#[serde(rename = "Source Well")]
|
||||
pub source_well: String,
|
||||
#[serde(rename = "Dest Barcode")]
|
||||
pub destination_plate: String,
|
||||
#[serde(rename = "Destination Well")]
|
||||
pub destination_well: String,
|
||||
#[serde(rename = "Transfer Volume")]
|
||||
pub volume: f32,
|
||||
#[serde(rename = "Concentration")]
|
||||
pub concentration: Option<f32>,
|
||||
}
|
||||
|
||||
/// The deserialization intermediate is generated from a mangled CSV s.t.
|
||||
/// the column headers are standardized to those given to the derive macro.
|
||||
///
|
||||
/// `TransferRecord` can *always* be generated from the intermediate.
|
||||
/// Currently there's no reason why the inverse couldn't be true,
|
||||
/// but there's no reason to convert back into the deserialize-only intermediate.
|
||||
#[derive(Deserialize, Debug, Clone)]
|
||||
pub struct TransferRecordDeserializeIntermediate {
|
||||
#[serde(rename = "sourceplate")]
|
||||
source_plate: String,
|
||||
#[serde(rename = "destinationplate")]
|
||||
destination_plate: String,
|
||||
#[serde(rename = "sourcewell")]
|
||||
source_well: String,
|
||||
#[serde(rename = "sourceformat")]
|
||||
source_format: Option<String>,
|
||||
#[serde(rename = "destinationwell")]
|
||||
destination_well: String,
|
||||
#[serde(rename = "destinationformat")]
|
||||
destination_format: Option<String>,
|
||||
#[serde(rename = "volume")]
|
||||
volume: Option<f32>,
|
||||
#[serde(rename = "concentration")]
|
||||
concentration: Option<f32>,
|
||||
}
|
||||
|
||||
impl From<TransferRecordDeserializeIntermediate> for TransferRecord {
|
||||
fn from(value: TransferRecordDeserializeIntermediate) -> Self {
|
||||
let mut source_well: String = value.source_well;
|
||||
if let Some(pformat) = value
|
||||
.source_format
|
||||
.and_then(|x| PlateFormat::try_from(x.as_str()).ok())
|
||||
{
|
||||
if let Ok(well_number) = source_well.parse::<u16>() {
|
||||
if let Some(alphanumeric) = numeric_well_to_alphanumeric(well_number, pformat) {
|
||||
source_well = alphanumeric;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
let mut destination_well: String = value.destination_well;
|
||||
if let Some(pformat) = value
|
||||
.destination_format
|
||||
.and_then(|x| PlateFormat::try_from(x.as_str()).ok())
|
||||
{
|
||||
if let Ok(well_number) = destination_well.parse::<u16>() {
|
||||
if let Some(alphanumeric) = numeric_well_to_alphanumeric(well_number, pformat) {
|
||||
destination_well = alphanumeric;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
let volume = value.volume.unwrap_or(2.5f32);
|
||||
|
||||
TransferRecord {
|
||||
source_plate: value.source_plate,
|
||||
destination_plate: value.destination_plate,
|
||||
source_well,
|
||||
destination_well,
|
||||
volume,
|
||||
concentration: value.concentration,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl TransferRecordDeserializeIntermediate {
|
||||
/// Used to cull malformed picklist entries that lack required information
|
||||
pub fn is_empty(&self) -> bool {
|
||||
self.source_plate.is_empty()
|
||||
|| self.destination_plate.is_empty()
|
||||
|| self.source_well.is_empty()
|
||||
|| self.destination_well.is_empty()
|
||||
}
|
||||
}
|
||||
|
||||
fn numeric_well_to_alphanumeric(input: u16, pformat: PlateFormat) -> Option<String> {
|
||||
let column_height: u16 = pformat.size().0 as u16;
|
||||
let column = input.div_ceil(column_height);
|
||||
let row = input % column_height;
|
||||
let row_str = num_to_letters(row as u8)?;
|
||||
|
||||
Some(format!("{}{}", row_str, column))
|
||||
}
|
|
@ -1,30 +0,0 @@
|
|||
use serde::{Deserialize, Serialize};
|
||||
use std::collections::HashMap;
|
||||
|
||||
use crate::Well;
|
||||
|
||||
type WellPair = (Well, Well);
|
||||
|
||||
#[non_exhaustive]
|
||||
#[derive(Debug, PartialEq, Deserialize, Serialize, Clone)]
|
||||
pub enum TransferVolume {
|
||||
Single(f32),
|
||||
WellMap(VolumeMaps),
|
||||
}
|
||||
|
||||
#[serde_with::serde_as]
|
||||
#[derive(Debug, PartialEq, Deserialize, Serialize, Clone)]
|
||||
pub struct VolumeMaps {
|
||||
#[serde_as(as = "HashMap<serde_with::json::JsonString, _>")]
|
||||
pub source_only: HashMap<Well, f32>,
|
||||
#[serde_as(as = "HashMap<serde_with::json::JsonString, _>")]
|
||||
pub destination_only: HashMap<Well, f32>,
|
||||
#[serde_as(as = "HashMap<serde_with::json::JsonString, _>")]
|
||||
pub paired: HashMap<WellPair, f32>,
|
||||
}
|
||||
|
||||
impl Default for TransferVolume {
|
||||
fn default() -> Self {
|
||||
TransferVolume::Single(2.5f32)
|
||||
}
|
||||
}
|
|
@ -1,69 +0,0 @@
|
|||
pub fn letters_to_num(letters: &str) -> Option<u8> {
|
||||
let mut num: u8 = 0;
|
||||
for (i, letter) in letters.to_ascii_uppercase().chars().rev().enumerate() {
|
||||
let n = letter as u8;
|
||||
if !(65..=90).contains(&n) {
|
||||
return None;
|
||||
}
|
||||
num = num.checked_add((26_i32.pow(i as u32) * (n as i32 - 64)).try_into().ok()?)?;
|
||||
}
|
||||
Some(num)
|
||||
}
|
||||
pub fn num_to_letters(num: u8) -> Option<String> {
|
||||
if num == 0 {
|
||||
return None;
|
||||
} // Otherwise, we will not return none!
|
||||
// As another note, we can't represent higher than "IV" anyway;
|
||||
// thus there's no reason for a loop (26^n with n>1 will NOT occur).
|
||||
let mut text = "".to_string();
|
||||
let mut digit1 = num.div_euclid(26u8);
|
||||
let mut digit2 = num.rem_euclid(26u8);
|
||||
if digit1 > 0 && digit2 == 0u8 {
|
||||
digit1 -= 1;
|
||||
digit2 = 26;
|
||||
}
|
||||
if digit1 != 0 {
|
||||
text.push((64 + digit1) as char)
|
||||
}
|
||||
text.push((64 + digit2) as char);
|
||||
|
||||
Some(text.to_string())
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::{letters_to_num, num_to_letters};
|
||||
|
||||
#[test]
|
||||
fn test_letters_to_num() {
|
||||
assert_eq!(letters_to_num("D"), Some(4));
|
||||
assert_eq!(letters_to_num("d"), None);
|
||||
assert_eq!(letters_to_num("AD"), Some(26 + 4));
|
||||
assert_eq!(letters_to_num("CG"), Some(3 * 26 + 7));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_num_to_letters() {
|
||||
println!("27 is {:?}", num_to_letters(27));
|
||||
assert_eq!(num_to_letters(1), Some("A".to_string()));
|
||||
assert_eq!(num_to_letters(26), Some("Z".to_string()));
|
||||
assert_eq!(num_to_letters(27), Some("AA".to_string()));
|
||||
assert_eq!(num_to_letters(111), Some("DG".to_string()));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_l2n_and_n2l() {
|
||||
assert_eq!(
|
||||
num_to_letters(letters_to_num("A").unwrap()),
|
||||
Some("A".to_string())
|
||||
);
|
||||
assert_eq!(
|
||||
num_to_letters(letters_to_num("BJ").unwrap()),
|
||||
Some("BJ".to_string())
|
||||
);
|
||||
for i in 1..=255 {
|
||||
assert_eq!(letters_to_num(&num_to_letters(i).unwrap()), Some(i));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -1,9 +0,0 @@
|
|||
use serde::{Deserialize, Serialize};
|
||||
|
||||
#[derive(Clone, Copy, PartialEq, Eq, Deserialize, Serialize, Debug, Hash)]
|
||||
pub struct Well {
|
||||
/// Top to bottom assuming landscape, i.e. lettered
|
||||
pub row: u8,
|
||||
/// Left to right assuming landscape, i.e. numbered
|
||||
pub col: u8,
|
||||
}
|
|
@ -1,2 +0,0 @@
|
|||
/target
|
||||
/dist
|
|
@ -1,36 +0,0 @@
|
|||
[package]
|
||||
name = "plate-tool-web"
|
||||
version = "0.5.0"
|
||||
edition = "2021"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
plate-tool-lib = { path = "../plate-tool-lib" }
|
||||
yew = { version = "0.21.0", features = ["csr"] }
|
||||
yewdux = "0.10"
|
||||
wasm-bindgen = "0.2"
|
||||
web-sys = { version = "0.3", features = ["FormData", "HtmlFormElement",
|
||||
"HtmlDialogElement", "Blob", "Url", "Window",
|
||||
"HtmlAnchorElement", "ReadableStream", "HtmlSelectElement", "HtmlOptionElement", "HtmlButtonElement",
|
||||
"FileReader", "HtmlCollection"] }
|
||||
js-sys = "0.3"
|
||||
log = "0.4"
|
||||
wasm-logger = "0.2"
|
||||
regex = "1"
|
||||
lazy_static = "1.4"
|
||||
uuid = { version = "1.6", features = ["v7", "fast-rng", "macro-diagnostics", "js", "serde"] }
|
||||
serde = { version = "1.0", features = ["derive"] }
|
||||
serde_json = "1.0"
|
||||
csv = "1.2"
|
||||
getrandom = { version = "0.2", features = ["js"] }
|
||||
rand = { version = "0.8", features = ["small_rng"] }
|
||||
|
||||
[dev-dependencies]
|
||||
wasm-bindgen-test = "0.3.0"
|
||||
|
||||
[profile.release]
|
||||
opt-level = 2
|
||||
|
||||
[profile.dev.package."*"]
|
||||
opt-level = 2
|
|
@ -1,27 +0,0 @@
|
|||
@use "sass:color";
|
||||
@use "./variables" as *;
|
||||
|
||||
$selection-border-width: 2px;
|
||||
|
||||
@mixin standard_button {
|
||||
color: inherit;
|
||||
|
||||
display: inline;
|
||||
margin-left: 3px;
|
||||
border: 2px solid rgba(1,1,1,0.2);
|
||||
background: transparent;
|
||||
|
||||
user-select: none;
|
||||
list-style: none;
|
||||
line-height: 1em;
|
||||
|
||||
&::before {
|
||||
text-align: center;
|
||||
vertical-align: middle;
|
||||
}
|
||||
&:hover {
|
||||
background: color.change($color-light, $alpha: 0.08);
|
||||
transition: background 0.1s;
|
||||
border: $selection-border-width solid color.change($color-light, $alpha:0.3);
|
||||
}
|
||||
}
|
|
@ -1,66 +0,0 @@
|
|||
@use "sass:color";
|
||||
@use "../variables" as *;
|
||||
|
||||
div.plate_container {
|
||||
position: relative;
|
||||
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
justify-content: space-evenly;
|
||||
align-items: center;
|
||||
|
||||
border: 2px solid $color-dark;
|
||||
grid-column: right / right;
|
||||
grid-row: upper / 3;
|
||||
|
||||
h2 {
|
||||
margin-bottom: 1%;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
&>div {
|
||||
display: grid;
|
||||
grid-template-rows: auto auto;
|
||||
grid-template-rows: auto auto;
|
||||
|
||||
&>h2:nth-of-type(1) {
|
||||
grid-column: 2;
|
||||
grid-row: 1;
|
||||
}
|
||||
|
||||
&>h2:nth-of-type(2) {
|
||||
grid-column: 1;
|
||||
grid-row: 2;
|
||||
writing-mode: vertical-rl;
|
||||
transform: rotate(-180deg);
|
||||
}
|
||||
|
||||
&>div {
|
||||
grid-column:2;
|
||||
grid-row: 2;
|
||||
}
|
||||
}
|
||||
|
||||
div.plate_container--upper-left {
|
||||
position: absolute;
|
||||
top: 0.5em;
|
||||
left: 0.5em;
|
||||
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
}
|
||||
|
||||
div.plate_container--heatmap-notice {
|
||||
animation: 1s 1 attention_on_load;
|
||||
}
|
||||
}
|
||||
|
||||
@keyframes attention_on_load {
|
||||
from{
|
||||
color: $color-light;
|
||||
transform: scale(1.05);
|
||||
}
|
||||
to {
|
||||
color: inherit;
|
||||
}
|
||||
}
|
|
@ -1,63 +0,0 @@
|
|||
#![allow(non_snake_case)]
|
||||
|
||||
use js_sys::Array;
|
||||
|
||||
use wasm_bindgen::{JsCast, JsValue};
|
||||
use web_sys::{
|
||||
Blob, HtmlAnchorElement, Url,
|
||||
};
|
||||
use yew::prelude::*;
|
||||
|
||||
|
||||
use crate::components::states::MainState;
|
||||
|
||||
use crate::state_to_csv;
|
||||
|
||||
// type NoParamsCallback = Box<dyn Fn(())>;
|
||||
|
||||
pub fn export_csv_button_callback(main_state: std::rc::Rc<MainState>) -> Callback<MouseEvent> {
|
||||
Callback::from(move |_| {
|
||||
if main_state.transfers.is_empty() {
|
||||
web_sys::window()
|
||||
.unwrap()
|
||||
.alert_with_message("No transfers to export.")
|
||||
.unwrap();
|
||||
return;
|
||||
}
|
||||
if let Ok(csv) = state_to_csv(&main_state) {
|
||||
save_str(&csv, "transfers.csv");
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
pub fn export_json_button_callback(main_state: std::rc::Rc<MainState>) -> Callback<MouseEvent> {
|
||||
Callback::from(move |_| {
|
||||
if let Ok(json) = serde_json::to_string(&main_state) {
|
||||
save_str(&json, "plate-tool-state.json");
|
||||
} else {
|
||||
web_sys::window()
|
||||
.unwrap()
|
||||
.alert_with_message("Failed to export.")
|
||||
.unwrap();
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
fn save_str(data: &str, name: &str) {
|
||||
let blob =
|
||||
Blob::new_with_str_sequence(&Array::from_iter(std::iter::once(JsValue::from_str(data))));
|
||||
if let Ok(blob) = blob {
|
||||
let url = Url::create_object_url_with_blob(&blob).expect("We have a blob, why not URL?");
|
||||
// Beneath is the cool hack to download files
|
||||
let window = web_sys::window().unwrap();
|
||||
let document = window.document().unwrap();
|
||||
let anchor = document
|
||||
.create_element("a")
|
||||
.unwrap()
|
||||
.dyn_into::<HtmlAnchorElement>()
|
||||
.unwrap();
|
||||
anchor.set_download(name);
|
||||
anchor.set_href(&url);
|
||||
anchor.click();
|
||||
}
|
||||
}
|
|
@ -1,96 +0,0 @@
|
|||
#![allow(non_snake_case)]
|
||||
|
||||
use wasm_bindgen::{prelude::*, JsCast};
|
||||
use web_sys::{HtmlDialogElement, HtmlFormElement, HtmlInputElement};
|
||||
use yew::prelude::*;
|
||||
use yewdux::prelude::*;
|
||||
|
||||
use crate::components::states::MainState;
|
||||
|
||||
use super::create_close_button;
|
||||
|
||||
pub fn input_json_input_callback(
|
||||
main_dispatch: Dispatch<MainState>,
|
||||
modal: HtmlDialogElement,
|
||||
) -> Closure<dyn FnMut(Event)> {
|
||||
Closure::<dyn FnMut(_)>::new(move |e: Event| {
|
||||
if let Some(input) = e.current_target() {
|
||||
let input = input
|
||||
.dyn_into::<HtmlInputElement>()
|
||||
.expect("We know this is an input.");
|
||||
if let Some(files) = input.files() {
|
||||
if let Some(file) = files.get(0) {
|
||||
let fr = web_sys::FileReader::new().unwrap();
|
||||
fr.read_as_text(&file).unwrap();
|
||||
let fr1 = fr.clone(); // Clone to avoid outliving closure
|
||||
let main_dispatch = main_dispatch.clone(); // Clone to satisfy FnMut
|
||||
// trait
|
||||
let modal = modal.clone();
|
||||
let onload = Closure::<dyn FnMut(_)>::new(move |_: Event| {
|
||||
if let Some(value) = &fr1.result().ok().and_then(|v| v.as_string()) {
|
||||
let ms = serde_json::from_str::<MainState>(value);
|
||||
match ms {
|
||||
Ok(ms) => main_dispatch.set(ms),
|
||||
Err(e) => log::debug!("{:?}", e),
|
||||
};
|
||||
modal.close();
|
||||
}
|
||||
});
|
||||
fr.set_onload(Some(onload.as_ref().unchecked_ref()));
|
||||
onload.forget(); // Magic (don't touch)
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
pub fn import_json_button_callback(main_dispatch: Dispatch<MainState>) -> Callback<MouseEvent> {
|
||||
Callback::from(move |_| {
|
||||
let window = web_sys::window().unwrap();
|
||||
let document = window.document().unwrap();
|
||||
let body = document.body().unwrap();
|
||||
let modal = document
|
||||
.create_element("dialog")
|
||||
.unwrap()
|
||||
.dyn_into::<HtmlDialogElement>()
|
||||
.unwrap();
|
||||
modal.set_text_content(Some("Import File:"));
|
||||
let onclose_callback = {
|
||||
let modal = modal.clone();
|
||||
Closure::<dyn FnMut(_)>::new(move |_: Event| {
|
||||
modal.remove();
|
||||
})
|
||||
};
|
||||
modal.set_onclose(Some(onclose_callback.as_ref().unchecked_ref()));
|
||||
|
||||
let close_button = create_close_button(&onclose_callback);
|
||||
onclose_callback.forget();
|
||||
modal.append_child(&close_button).unwrap();
|
||||
|
||||
let form = document
|
||||
.create_element("form")
|
||||
.unwrap()
|
||||
.dyn_into::<HtmlFormElement>()
|
||||
.unwrap();
|
||||
let input = document
|
||||
.create_element("input")
|
||||
.unwrap()
|
||||
.dyn_into::<HtmlInputElement>()
|
||||
.unwrap();
|
||||
input.set_type("file");
|
||||
input.set_accept(".json");
|
||||
form.append_child(&input).unwrap();
|
||||
|
||||
let input_callback = {
|
||||
let main_dispatch = main_dispatch.clone();
|
||||
let modal = modal.clone();
|
||||
input_json_input_callback(main_dispatch, modal)
|
||||
};
|
||||
input.set_onchange(Some(input_callback.as_ref().unchecked_ref()));
|
||||
input_callback.forget(); // Magic straight from the docs, don't touch :(
|
||||
|
||||
modal.append_child(&form).unwrap();
|
||||
body.append_child(&modal).unwrap();
|
||||
modal.show_modal().unwrap();
|
||||
})
|
||||
}
|
|
@ -1,18 +0,0 @@
|
|||
mod export_callbacks;
|
||||
mod input_json_callbacks;
|
||||
mod import_csv_callbacks;
|
||||
mod settings_callbacks;
|
||||
mod plate_edits_callbacks;
|
||||
mod util;
|
||||
|
||||
pub use util::*;
|
||||
|
||||
pub use export_callbacks::*;
|
||||
|
||||
pub use input_json_callbacks::*;
|
||||
|
||||
pub use import_csv_callbacks::*;
|
||||
|
||||
pub use settings_callbacks::*;
|
||||
|
||||
pub use plate_edits_callbacks::*;
|
|
@ -1,43 +0,0 @@
|
|||
#![allow(non_snake_case)]
|
||||
|
||||
use yew::prelude::*;
|
||||
use yewdux::prelude::*;
|
||||
|
||||
use crate::components::{new_plate_dialog::{NewPlateDialogType}, states::{CurrentTransfer, MainState}};
|
||||
|
||||
type NoParamsCallback = Box<dyn Fn(())>;
|
||||
|
||||
pub fn new_plate_dialog_callback(
|
||||
new_plate_dialog_is_open: UseStateHandle<Option<NewPlateDialogType>>,
|
||||
) -> NoParamsCallback {
|
||||
let new_plate_dialog_is_open = new_plate_dialog_is_open.clone();
|
||||
Box::new(move |_| {
|
||||
new_plate_dialog_is_open.set(None);
|
||||
})
|
||||
}
|
||||
|
||||
pub fn open_new_plate_dialog_callback(
|
||||
new_plate_dialog_is_open: UseStateHandle<Option<NewPlateDialogType>>
|
||||
) -> Box<dyn Fn(NewPlateDialogType)> {
|
||||
let new_plate_dialog_is_open = new_plate_dialog_is_open.clone();
|
||||
Box::new(move |dt| {
|
||||
new_plate_dialog_is_open.set(Some(dt));
|
||||
})
|
||||
}
|
||||
|
||||
pub fn new_button_callback(
|
||||
main_dispatch: Dispatch<MainState>,
|
||||
ct_dispatch: Dispatch<CurrentTransfer>,
|
||||
) -> Callback<web_sys::MouseEvent> {
|
||||
Callback::from(move |_| {
|
||||
let window = web_sys::window().unwrap();
|
||||
let confirm =
|
||||
window.confirm_with_message("This will reset all plates and transfers. Proceed?");
|
||||
if let Ok(confirm) = confirm {
|
||||
if confirm {
|
||||
main_dispatch.set(MainState::default());
|
||||
ct_dispatch.set(CurrentTransfer::default());
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
|
@ -1,116 +0,0 @@
|
|||
#![allow(non_snake_case)]
|
||||
|
||||
|
||||
use wasm_bindgen::{prelude::*, JsCast};
|
||||
use web_sys::{
|
||||
HtmlDialogElement, HtmlFormElement, HtmlOptionElement, HtmlSelectElement,
|
||||
};
|
||||
|
||||
use yew::prelude::*;
|
||||
use yewdux::prelude::*;
|
||||
|
||||
use crate::components::states::{CsvExportType, MainState};
|
||||
|
||||
use super::create_close_button;
|
||||
|
||||
pub fn toggle_in_transfer_hashes_callback(
|
||||
main_dispatch: Dispatch<MainState>,
|
||||
) -> Callback<web_sys::MouseEvent> {
|
||||
let main_dispatch = main_dispatch.clone();
|
||||
Callback::from(move |_| {
|
||||
main_dispatch.reduce_mut(|state| {
|
||||
state.preferences.in_transfer_hashes ^= true;
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
pub fn toggle_volume_heatmap_callback(
|
||||
main_dispatch: Dispatch<MainState>,
|
||||
) -> Callback<web_sys::MouseEvent> {
|
||||
let main_dispatch = main_dispatch.clone();
|
||||
Callback::from(move |_| {
|
||||
main_dispatch.reduce_mut(|state| {
|
||||
state.preferences.volume_heatmap ^= true;
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
pub fn toggle_show_current_coordinates_callback(
|
||||
main_dispatch: Dispatch<MainState>,
|
||||
) -> Callback<web_sys::MouseEvent> {
|
||||
let main_dispatch = main_dispatch.clone();
|
||||
Callback::from(move |_| {
|
||||
main_dispatch.reduce_mut(|state| {
|
||||
state.preferences.show_current_coordinates ^= true;
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
pub fn change_csv_export_type_callback(
|
||||
main_dispatch: Dispatch<MainState>,
|
||||
) -> Callback<web_sys::MouseEvent> {
|
||||
let main_dispatch = main_dispatch.clone();
|
||||
Callback::from(move |_| {
|
||||
let window = web_sys::window().unwrap();
|
||||
let document = window.document().unwrap();
|
||||
let body = document.body().unwrap();
|
||||
let modal = document
|
||||
.create_element("dialog")
|
||||
.unwrap()
|
||||
.dyn_into::<HtmlDialogElement>()
|
||||
.unwrap();
|
||||
let onclose_callback = {
|
||||
let modal = modal.clone();
|
||||
Closure::<dyn FnMut(_)>::new(move |_: Event| {
|
||||
modal.remove();
|
||||
})
|
||||
};
|
||||
modal.set_onclose(Some(onclose_callback.as_ref().unchecked_ref()));
|
||||
modal.set_text_content(Some("CSV Export Type"));
|
||||
|
||||
let close_button = create_close_button(&onclose_callback);
|
||||
onclose_callback.forget();
|
||||
modal.append_child(&close_button).unwrap();
|
||||
|
||||
let form = document
|
||||
.create_element("form")
|
||||
.unwrap()
|
||||
.dyn_into::<HtmlFormElement>()
|
||||
.unwrap();
|
||||
let export_type = document
|
||||
.create_element("select")
|
||||
.unwrap()
|
||||
.dyn_into::<HtmlSelectElement>()
|
||||
.unwrap();
|
||||
for t in [CsvExportType::Normal, CsvExportType::EchoClient] {
|
||||
let option = document
|
||||
.create_element("option")
|
||||
.unwrap()
|
||||
.dyn_into::<HtmlOptionElement>()
|
||||
.unwrap();
|
||||
option.set_value(&t.to_string());
|
||||
option.set_text(&t.to_string());
|
||||
option.set_selected(t == main_dispatch.get().preferences.csv_export_type);
|
||||
|
||||
export_type.append_child(&option).unwrap();
|
||||
}
|
||||
form.append_child(&export_type).unwrap();
|
||||
|
||||
let form_change_callback = {
|
||||
let export_type = export_type.clone();
|
||||
let main_dispatch = main_dispatch.clone();
|
||||
Closure::<dyn FnMut(_)>::new(move |_: Event| {
|
||||
let current: CsvExportType = export_type.value().as_str().into();
|
||||
main_dispatch.reduce_mut(|state| {
|
||||
state.preferences.csv_export_type = current;
|
||||
});
|
||||
})};
|
||||
form.set_onchange(Some(form_change_callback.as_ref().unchecked_ref()));
|
||||
form_change_callback.forget();
|
||||
|
||||
modal.append_child(&form).unwrap();
|
||||
|
||||
body.append_child(&modal).unwrap();
|
||||
modal.show_modal().unwrap();
|
||||
})
|
||||
}
|
|
@ -1,19 +0,0 @@
|
|||
#![allow(non_snake_case)]
|
||||
|
||||
use wasm_bindgen::{prelude::*, JsCast};
|
||||
use web_sys::HtmlElement;
|
||||
use yew::prelude::*;
|
||||
|
||||
pub fn create_close_button(close: &Closure<dyn FnMut(Event)>) -> HtmlElement {
|
||||
let document = web_sys::window().unwrap().document().unwrap();
|
||||
let close_button = document
|
||||
.create_element("button")
|
||||
.unwrap()
|
||||
.dyn_into::<HtmlElement>()
|
||||
.unwrap();
|
||||
close_button.set_text_content(Some("✖"));
|
||||
close_button.set_class_name("close_button");
|
||||
close_button.set_onclick(Some(close.as_ref().unchecked_ref()));
|
||||
|
||||
close_button
|
||||
}
|
|
@ -1,74 +0,0 @@
|
|||
use uuid::Uuid;
|
||||
use wasm_bindgen::JsCast;
|
||||
use web_sys::{EventTarget, HtmlElement, HtmlInputElement, HtmlOptionElement, HtmlSelectElement};
|
||||
use yew::prelude::*;
|
||||
use yewdux::prelude::*;
|
||||
|
||||
use crate::components::states::MainState;
|
||||
use plate_tool_lib::plate::PlateFormat;
|
||||
|
||||
type NoParamsCallback = Box<dyn Fn(())>;
|
||||
|
||||
pub fn open_plate_info_callback(
|
||||
plate_menu_id: UseStateHandle<Option<Uuid>>,
|
||||
) -> Callback<MouseEvent> {
|
||||
Callback::from(move |e: MouseEvent| {
|
||||
let target: Option<EventTarget> = e.target();
|
||||
let li = target.and_then(|t| t.dyn_into::<HtmlElement>().ok());
|
||||
if let Some(li) = li {
|
||||
if let Ok(id) = li.id().as_str().parse::<u128>() {
|
||||
plate_menu_id.set(Some(Uuid::from_u128(id)));
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
pub fn plate_info_close_callback(plate_menu_id: UseStateHandle<Option<Uuid>>) -> NoParamsCallback {
|
||||
Box::new(move |_| {
|
||||
plate_menu_id.set(None);
|
||||
})
|
||||
}
|
||||
|
||||
pub fn plate_info_delete_callback(
|
||||
main_dispatch: Dispatch<MainState>,
|
||||
plate_menu_id: UseStateHandle<Option<Uuid>>,
|
||||
) -> NoParamsCallback {
|
||||
Box::new(move |_| {
|
||||
if let Some(id) = *plate_menu_id {
|
||||
main_dispatch.reduce_mut(|state| {
|
||||
state.del_plate(id);
|
||||
});
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
pub fn rename_onchange(id: Uuid, main_dispatch: Dispatch<MainState>) -> Callback<Event> {
|
||||
Callback::from(move |e: Event| {
|
||||
log::debug!("Changed name");
|
||||
let input = e
|
||||
.target()
|
||||
.expect("Event must have target")
|
||||
.dyn_into::<HtmlInputElement>()
|
||||
.unwrap();
|
||||
main_dispatch.reduce_mut(|state| state.rename_plate(id, &input.value()))
|
||||
})
|
||||
}
|
||||
|
||||
pub fn format_onchange(id: Uuid, main_dispatch: Dispatch<MainState>) -> Callback<Event> {
|
||||
Callback::from(move |e: Event| {
|
||||
log::debug!("Changing plate format");
|
||||
let new_format: Option<PlateFormat> = e
|
||||
.target()
|
||||
.expect("Event must have target")
|
||||
.dyn_into::<HtmlSelectElement>()
|
||||
.unwrap()
|
||||
.selected_options()
|
||||
.get_with_index(0)
|
||||
.map(|el| el.dyn_into::<HtmlOptionElement>().unwrap())
|
||||
.map(|opt_el| opt_el.value())
|
||||
.and_then(|value| PlateFormat::try_from(value.as_str()).ok());
|
||||
if let Some(format) = new_format {
|
||||
main_dispatch.reduce_mut(|state| state.change_format(id, &format));
|
||||
}
|
||||
})
|
||||
}
|
|
@ -1,217 +0,0 @@
|
|||
use plate_tool_lib::{plate::PlateType};
|
||||
use uuid::Uuid;
|
||||
use wasm_bindgen::{prelude::*, JsCast};
|
||||
use web_sys::{
|
||||
HtmlDialogElement, HtmlElement, HtmlOptionElement,
|
||||
HtmlSelectElement,
|
||||
};
|
||||
|
||||
use yew::prelude::*;
|
||||
use yewdux::prelude::*;
|
||||
|
||||
use std::rc::Rc;
|
||||
use std::str::FromStr;
|
||||
|
||||
use crate::components::callbacks::main_window_callbacks::create_close_button;
|
||||
use crate::components::states::MainState;
|
||||
|
||||
pub fn merge_button_callback(main_dispatch: Dispatch<MainState>, id: Uuid) -> Callback<MouseEvent> {
|
||||
Callback::from(move |_| {
|
||||
let dialog_opt = create_merge_dialog(main_dispatch.clone(), id);
|
||||
if let Some(dialog) = dialog_opt {
|
||||
let window = web_sys::window().unwrap();
|
||||
let document = window.document().unwrap();
|
||||
let body = document.body().unwrap();
|
||||
let _ = body.append_child(&dialog);
|
||||
dialog.set_open(true);
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
fn create_merge_dialog(main_dispatch: Dispatch<MainState>, id: Uuid) -> Option<HtmlDialogElement> {
|
||||
let other_plates = get_all_plates_except(main_dispatch.clone(), id);
|
||||
if other_plates.is_empty() {
|
||||
return None;
|
||||
}
|
||||
|
||||
let dialog = create_dialog();
|
||||
|
||||
let select = create_select_for_plates(&other_plates);
|
||||
dialog.append_child(&select).unwrap();
|
||||
let select_rc = Rc::new(select);
|
||||
let ok_button = create_ok_button(main_dispatch.clone(), select_rc.clone(), id);
|
||||
dialog.append_child(&ok_button).unwrap();
|
||||
|
||||
Some(dialog)
|
||||
}
|
||||
|
||||
fn create_dialog() -> HtmlDialogElement {
|
||||
let window = web_sys::window().unwrap();
|
||||
let document = window.document().unwrap();
|
||||
|
||||
let dialog = document
|
||||
.create_element("dialog")
|
||||
.unwrap()
|
||||
.dyn_into::<HtmlDialogElement>()
|
||||
.unwrap();
|
||||
dialog.set_class_name("dialog shifted_dialog");
|
||||
let onclose_callback = {
|
||||
let dialog = dialog.clone();
|
||||
Closure::<dyn FnMut(_)>::new(move |_: Event| {
|
||||
dialog.remove();
|
||||
})
|
||||
};
|
||||
dialog.set_onclose(Some(onclose_callback.as_ref().unchecked_ref()));
|
||||
|
||||
let close_button = create_close_button(&onclose_callback);
|
||||
onclose_callback.forget();
|
||||
dialog.append_child(&close_button).unwrap();
|
||||
|
||||
let header = document.create_element("h2").unwrap();
|
||||
header.set_inner_html("Merge Plates");
|
||||
dialog.append_child(&header).unwrap();
|
||||
|
||||
dialog
|
||||
}
|
||||
|
||||
fn create_ok_button(
|
||||
main_dispatch: Dispatch<MainState>,
|
||||
select: Rc<HtmlSelectElement>,
|
||||
id: Uuid,
|
||||
) -> HtmlElement {
|
||||
let window = web_sys::window().unwrap();
|
||||
let document = window.document().unwrap();
|
||||
|
||||
let button = document
|
||||
.create_element("button")
|
||||
.unwrap()
|
||||
.dyn_into::<HtmlElement>()
|
||||
.unwrap();
|
||||
button.set_inner_html("Ok");
|
||||
let callback = ok_button_callback(main_dispatch, select, id);
|
||||
button.set_onclick(Some(callback.as_ref().unchecked_ref()));
|
||||
callback.forget();
|
||||
|
||||
button
|
||||
}
|
||||
|
||||
fn ok_button_callback(
|
||||
main_dispatch: Dispatch<MainState>,
|
||||
select: Rc<HtmlSelectElement>,
|
||||
to_id: Uuid,
|
||||
) -> Closure<dyn FnMut(Event)> {
|
||||
Closure::<dyn FnMut(_)>::new(move |_: Event| {
|
||||
let selected = select
|
||||
.selected_options()
|
||||
.get_with_index(0)
|
||||
.map(|el| el.dyn_into::<HtmlOptionElement>().unwrap())
|
||||
.map(|opt_el| opt_el.value())
|
||||
.and_then(|uuid_str| Uuid::from_str(&uuid_str).ok());
|
||||
if let Some(from_id) = selected {
|
||||
let plate_type = find_plate_type(main_dispatch.clone(), from_id).unwrap();
|
||||
let binding = main_dispatch.get();
|
||||
let merge_to = match plate_type {
|
||||
PlateType::Source => binding.source_plates.iter().find(|x| x.get_uuid() == to_id).unwrap(),
|
||||
PlateType::Destination => binding
|
||||
.destination_plates
|
||||
.iter()
|
||||
.find(|x| x.get_uuid() == to_id).unwrap(),
|
||||
};
|
||||
|
||||
main_dispatch.reduce_mut(|x| {
|
||||
let merged_transfers = x.transfers.iter_mut().filter(|x| match plate_type {
|
||||
PlateType::Source => x.source_id,
|
||||
PlateType::Destination => x.dest_id
|
||||
} == from_id);
|
||||
|
||||
for transfer in merged_transfers {
|
||||
match plate_type {
|
||||
PlateType::Source => {
|
||||
transfer.source_id = to_id;
|
||||
transfer.transfer_region.source_plate = merge_to.plate;
|
||||
},
|
||||
PlateType::Destination => {
|
||||
transfer.dest_id = to_id;
|
||||
transfer.transfer_region.dest_plate = merge_to.plate;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
match plate_type {
|
||||
PlateType::Source => x.source_plates.retain(|y| y.get_uuid() != from_id),
|
||||
PlateType::Destination => x.destination_plates.retain(|y| y.get_uuid() != from_id)
|
||||
};
|
||||
});
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
fn create_select_for_plates(infos: &Vec<(Uuid, String)>) -> HtmlSelectElement {
|
||||
let window = web_sys::window().unwrap();
|
||||
let document = window.document().unwrap();
|
||||
|
||||
let select = document
|
||||
.create_element("select")
|
||||
.unwrap()
|
||||
.dyn_into::<HtmlSelectElement>()
|
||||
.unwrap();
|
||||
for info in infos {
|
||||
let _ = select.append_child(&create_option_for_plate(info));
|
||||
}
|
||||
|
||||
select
|
||||
}
|
||||
|
||||
fn create_option_for_plate(info: &(Uuid, String)) -> HtmlOptionElement {
|
||||
let window = web_sys::window().unwrap();
|
||||
let document = window.document().unwrap();
|
||||
|
||||
let opt = document
|
||||
.create_element("option")
|
||||
.unwrap()
|
||||
.dyn_into::<HtmlOptionElement>()
|
||||
.unwrap();
|
||||
opt.set_value(&info.0.to_string());
|
||||
opt.set_inner_text(&info.1);
|
||||
|
||||
opt
|
||||
}
|
||||
|
||||
fn get_all_plates_except(main_dispatch: Dispatch<MainState>, id: Uuid) -> Vec<(Uuid, String)> {
|
||||
let plate_type = find_plate_type(main_dispatch.clone(), id);
|
||||
if plate_type.is_none() {
|
||||
return Vec::new();
|
||||
} // Return early if not found somehow
|
||||
let plate_type = plate_type.unwrap();
|
||||
|
||||
let binding = main_dispatch.get();
|
||||
let all_plates_iter = match plate_type {
|
||||
PlateType::Source => binding.source_plates.iter(),
|
||||
PlateType::Destination => binding.destination_plates.iter(),
|
||||
};
|
||||
|
||||
all_plates_iter
|
||||
.map(|x| (x.get_uuid(), x.name.to_string()))
|
||||
.filter(|y| y.0 != id)
|
||||
.collect()
|
||||
}
|
||||
|
||||
fn find_plate_type(main_dispatch: Dispatch<MainState>, id: Uuid) -> Option<PlateType> {
|
||||
if main_dispatch
|
||||
.get()
|
||||
.source_plates
|
||||
.iter()
|
||||
.any(|x| x.get_uuid() == id)
|
||||
{
|
||||
Some(PlateType::Source)
|
||||
} else if main_dispatch
|
||||
.get()
|
||||
.destination_plates
|
||||
.iter()
|
||||
.any(|x| x.get_uuid() == id)
|
||||
{
|
||||
return Some(PlateType::Destination);
|
||||
} else {
|
||||
return None;
|
||||
}
|
||||
}
|
|
@ -1,9 +0,0 @@
|
|||
mod select_callbacks;
|
||||
mod info_dialog_callbacks;
|
||||
mod merge_callbacks;
|
||||
|
||||
pub use select_callbacks::*;
|
||||
|
||||
pub use info_dialog_callbacks::*;
|
||||
|
||||
pub use merge_callbacks::*;
|
|
@ -1,5 +0,0 @@
|
|||
pub mod plate_container;
|
||||
mod util;
|
||||
mod plate_callbacks;
|
||||
mod plate_data;
|
||||
mod plate;
|
|
@ -1,348 +0,0 @@
|
|||
#![allow(non_snake_case)]
|
||||
|
||||
use std::collections::HashMap;
|
||||
|
||||
|
||||
use plate_tool_lib::transfer_volume::TransferVolume;
|
||||
use yew::prelude::*;
|
||||
use yewdux::prelude::*;
|
||||
|
||||
use crate::components::states::{CurrentTransfer, MainState};
|
||||
use plate_tool_lib::plate::PlateType;
|
||||
use plate_tool_lib::transfer::Transfer;
|
||||
use plate_tool_lib::transfer_region::Region;
|
||||
use plate_tool_lib::Well;
|
||||
|
||||
// Color Palette for the Source Plates, can be changed here
|
||||
use crate::components::plates::util::Palettes;
|
||||
const PALETTE: super::util::ColorPalette = Palettes::RAINBOW;
|
||||
|
||||
use plate_tool_lib::util::num_to_letters;
|
||||
|
||||
use super::plate_data::*;
|
||||
use super::plate_callbacks;
|
||||
|
||||
#[function_component]
|
||||
pub fn Plate(props: &PlateProps) -> Html {
|
||||
let (main_state, _) = use_store::<MainState>();
|
||||
let (ct_state, ct_dispatch) = use_store::<CurrentTransfer>();
|
||||
let m_start_handle: MStartHandle = use_state_eq(|| None);
|
||||
let m_end_handle: MEndHandle = use_state_eq(|| None);
|
||||
let m_stat_handle: MStatHandle = use_state_eq(|| false);
|
||||
|
||||
if !(*m_stat_handle) {
|
||||
let region = match props.ptype {
|
||||
PlateType::Source => ct_state.transfer.transfer_region.source_region.clone(),
|
||||
PlateType::Destination => ct_state.transfer.transfer_region.dest_region.clone(),
|
||||
};
|
||||
let (pt1, pt2) = match region {
|
||||
Region::Point(Well {row: x, col: y }) => ((x, y), (x, y)),
|
||||
Region::Rect(c1, c2) => ((c1.row, c1.col ), (c2.row, c2.col)),
|
||||
Region::Custom(_) => ((0, 0), (0, 0)),
|
||||
};
|
||||
m_start_handle.set(Some(pt1));
|
||||
m_end_handle.set(Some(pt2));
|
||||
}
|
||||
|
||||
let tooltip_map: HashMap<Well, Vec<&Transfer>>;
|
||||
let volume_map: HashMap<Well, f32>;
|
||||
let volume_max: f32;
|
||||
{
|
||||
let transfers = main_state.transfers.iter().filter(|t| match props.ptype {
|
||||
PlateType::Source => t.source_id == props.source_plate.get_uuid(),
|
||||
PlateType::Destination => t.dest_id == props.destination_plate.get_uuid(),
|
||||
});
|
||||
let mut tooltip_map_temp: HashMap<Well, Vec<&Transfer>> = HashMap::new();
|
||||
let mut volume_map_temp: HashMap<Well, f32> = HashMap::new();
|
||||
let mut volume_max_temp: f32 = f32::NEG_INFINITY;
|
||||
for transfer in transfers {
|
||||
let wells = match props.ptype {
|
||||
PlateType::Source => transfer.transfer_region.get_source_wells(),
|
||||
PlateType::Destination => transfer.transfer_region.get_destination_wells(),
|
||||
};
|
||||
for well in wells {
|
||||
if let Some(val) = tooltip_map_temp.get_mut(&well) {
|
||||
val.push(transfer);
|
||||
} else {
|
||||
tooltip_map_temp.insert(well, vec![transfer]);
|
||||
}
|
||||
let temp_volume: f32 = match &transfer.volume {
|
||||
TransferVolume::Single(x) => *x,
|
||||
TransferVolume::WellMap(wm) => {
|
||||
*match props.ptype {
|
||||
PlateType::Source => wm.source_only.get(&well),
|
||||
PlateType::Destination => wm.destination_only.get(&well)
|
||||
}.unwrap_or(&2.5f32)
|
||||
},
|
||||
_ => unreachable!(),
|
||||
};
|
||||
// Usage to be used as a volume multiplier; should be in [1, U32_MAX]
|
||||
// First convert to f64 (u32 can not fit in f32 directly) and then cast
|
||||
// to round into the closest f32.
|
||||
let usage: f32 = Into::<f64>::into(count_plate_usage(transfer, &well).unwrap_or(1u32).max(1u32)) as f32;
|
||||
|
||||
if let Some(val) = volume_map_temp.get_mut(&well) {
|
||||
*val += temp_volume * usage;
|
||||
} else {
|
||||
volume_map_temp.insert(well, temp_volume * usage);
|
||||
}
|
||||
volume_max_temp = f32::max(volume_max_temp, *volume_map_temp.get(&well).expect("Just added"));
|
||||
}
|
||||
}
|
||||
tooltip_map = tooltip_map_temp;
|
||||
volume_map = volume_map_temp;
|
||||
volume_max = volume_max_temp;
|
||||
};
|
||||
|
||||
let wells = match props.ptype {
|
||||
PlateType::Source => ct_state.transfer.transfer_region.get_source_wells(),
|
||||
PlateType::Destination => ct_state.transfer.transfer_region.get_destination_wells(),
|
||||
};
|
||||
|
||||
let ordered_ids: Vec<uuid::Uuid> = {
|
||||
let mut ids: Vec<uuid::Uuid> = main_state.transfers.clone().iter().map(|x| x.id).collect();
|
||||
ids.sort_unstable();
|
||||
ids
|
||||
};
|
||||
|
||||
let mouse_callback = {
|
||||
let m_start_handle = m_start_handle.clone();
|
||||
let m_end_handle = m_end_handle.clone();
|
||||
let m_stat_handle = m_stat_handle.clone();
|
||||
let send_coordinates = props.send_coordinates.clone();
|
||||
plate_callbacks::mouse_callback(m_start_handle, m_end_handle, m_stat_handle, send_coordinates)
|
||||
};
|
||||
|
||||
let mouseup_callback = {
|
||||
let m_start_handle = m_start_handle.clone();
|
||||
let m_end_handle = m_end_handle.clone();
|
||||
plate_callbacks::mouseup_callback(m_start_handle, m_end_handle, m_stat_handle, ct_dispatch, props.ptype)
|
||||
};
|
||||
|
||||
let mouseleave_callback = Callback::clone(&mouseup_callback);
|
||||
|
||||
let screenshot_callback = Callback::from(|_| {
|
||||
let _ = js_sys::eval("copy_screenshot_src()");
|
||||
});
|
||||
|
||||
let width = match props.ptype {
|
||||
PlateType::Source => props.source_plate.plate.size().1,
|
||||
PlateType::Destination => props.destination_plate.plate.size().1,
|
||||
};
|
||||
let height = match props.ptype {
|
||||
PlateType::Source => props.source_plate.plate.size().0,
|
||||
PlateType::Destination => props.destination_plate.plate.size().0,
|
||||
};
|
||||
let pformat = match props.ptype {
|
||||
PlateType::Source => props.source_plate.plate.plate_format,
|
||||
PlateType::Destination => props.destination_plate.plate.plate_format,
|
||||
};
|
||||
let column_header = {
|
||||
let headers = (1..=width)
|
||||
.map(|j| {
|
||||
html! {<th>
|
||||
{format!("{:0>2}", j)}
|
||||
</th>}
|
||||
})
|
||||
.collect::<Html>();
|
||||
html! {<tr><th />{ headers }</tr>}
|
||||
};
|
||||
let rows =
|
||||
(1..=height)
|
||||
.map(|i| {
|
||||
let row_header = html! {<th>{num_to_letters(i)}</th>};
|
||||
let row = (1..=width)
|
||||
.map(|j| {
|
||||
let color = {
|
||||
if !main_state.preferences.volume_heatmap {
|
||||
tooltip_map.get(&Well { row: i, col: j })
|
||||
.and_then(|t| t.last())
|
||||
.map(|t| PALETTE.get_ordered(t.get_uuid(), &ordered_ids))
|
||||
} else {
|
||||
volume_map.get(&Well { row: i, col: j })
|
||||
.map(|t| PALETTE.get_linear(*t as f64, volume_max as f64))
|
||||
}
|
||||
};
|
||||
let title = {
|
||||
let mut out = String::new();
|
||||
let used_by = tooltip_map.get(&Well { row: i, col: j }).map(|transfers| format!("Used by: {}", transfers.iter().map(|t| t.name.clone())
|
||||
.collect::<Vec<_>>().join(", ")));
|
||||
if let Some(val) = used_by {
|
||||
out += &val;
|
||||
}
|
||||
let volume_sum = volume_map.get(&Well { row: i, col: j })
|
||||
.map(|t| format!("Volume: {}", t));
|
||||
if let Some(val) = volume_sum {
|
||||
if !out.is_empty() { out += "\n" }
|
||||
out += &val;
|
||||
}
|
||||
out
|
||||
};
|
||||
html! {
|
||||
<PlateCell i={i} j={j}
|
||||
selected={in_rect(*m_start_handle.clone(), *m_end_handle.clone(), (i,j))}
|
||||
mouse={mouse_callback.clone()}
|
||||
in_transfer={wells.contains(&Well { row: i, col: j }) && main_state.preferences.in_transfer_hashes}
|
||||
color={ color }
|
||||
cell_height={props.cell_height}
|
||||
title={title}
|
||||
/>
|
||||
}
|
||||
})
|
||||
.collect::<Html>();
|
||||
html! {
|
||||
<tr>
|
||||
{ row_header }{ row }
|
||||
</tr>
|
||||
}
|
||||
})
|
||||
.collect::<Html>();
|
||||
|
||||
html! {
|
||||
<div ondblclick={screenshot_callback}
|
||||
class={classes!{match props.ptype {
|
||||
PlateType::Source => "source_plate",
|
||||
PlateType::Destination => "dest_plate",
|
||||
},
|
||||
"W".to_owned()+&pformat.to_string()}}>
|
||||
<table
|
||||
onmouseup={move |e| {
|
||||
mouseup_callback.emit(e);
|
||||
}}
|
||||
onmouseleave={move |e| {
|
||||
mouseleave_callback.emit(e);
|
||||
}}>
|
||||
{ column_header }
|
||||
{ rows }
|
||||
</table>
|
||||
</div>
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(PartialEq, Properties)]
|
||||
pub struct PlateCellProps {
|
||||
i: u8,
|
||||
j: u8,
|
||||
selected: bool,
|
||||
mouse: Callback<(u8, u8, MouseEventType)>,
|
||||
in_transfer: Option<bool>,
|
||||
color: Option<[f64; 3]>,
|
||||
cell_height: f64,
|
||||
title: Option<String>,
|
||||
}
|
||||
|
||||
#[function_component]
|
||||
fn PlateCell(props: &PlateCellProps) -> Html {
|
||||
let selected_class = match props.selected {
|
||||
true => Some("current_select"),
|
||||
false => None,
|
||||
};
|
||||
let in_transfer_class = match props.in_transfer {
|
||||
Some(true) => Some("in_transfer"),
|
||||
_ => None,
|
||||
};
|
||||
let color = props.color.unwrap_or([255.0, 255.0, 255.0]);
|
||||
let mouse = Callback::clone(&props.mouse);
|
||||
let mouse2 = Callback::clone(&props.mouse);
|
||||
let (i, j) = (props.i, props.j);
|
||||
|
||||
html! {
|
||||
<td class={classes!("plate_cell", selected_class, in_transfer_class)}
|
||||
style={format!("height: {}px;", props.cell_height)}
|
||||
id={format!("color={:?}", props.color)}
|
||||
onmousedown={move |_| {
|
||||
mouse.emit((i,j, MouseEventType::Mousedown))
|
||||
}}
|
||||
onmouseenter={move |_| {
|
||||
mouse2.emit((i,j, MouseEventType::Mouseenter))
|
||||
}}>
|
||||
<div class="plate_cell_inner"
|
||||
style={format!("background: rgba({},{},{},1);", color[0], color[1], color[2])}
|
||||
title={if let Some(text) = &props.title {
|
||||
text.clone()
|
||||
} else {"".to_string()}}/>
|
||||
</td>
|
||||
}
|
||||
}
|
||||
|
||||
pub fn in_rect(corner1: Option<(u8, u8)>, corner2: Option<(u8, u8)>, pt: (u8, u8)) -> bool {
|
||||
if let (Some(c1), Some(c2)) = (corner1, corner2) {
|
||||
pt.0 <= u8::max(c1.0, c2.0)
|
||||
&& pt.0 >= u8::min(c1.0, c2.0)
|
||||
&& pt.1 <= u8::max(c1.1, c2.1)
|
||||
&& pt.1 >= u8::min(c1.1, c2.1)
|
||||
} else {
|
||||
false
|
||||
}
|
||||
}
|
||||
|
||||
fn count_plate_usage(transfer: &Transfer, well: &Well) -> Option<u32> {
|
||||
if let Region::Custom(_) = transfer.transfer_region.source_region {
|
||||
return None;
|
||||
}
|
||||
|
||||
let map = transfer.transfer_region.calculate_map();
|
||||
map(*well).map(|list| list.len() as u32)
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use wasm_bindgen_test::*;
|
||||
|
||||
use super::in_rect;
|
||||
|
||||
// in_rect tests
|
||||
#[test]
|
||||
#[wasm_bindgen_test]
|
||||
fn test_in_rect1() {
|
||||
// Test in center of rect
|
||||
let c1 = (1, 1);
|
||||
let c2 = (10, 10);
|
||||
let pt = (5, 5);
|
||||
assert!(in_rect(Some(c1), Some(c2), pt));
|
||||
// Order of the corners should not matter:
|
||||
assert!(in_rect(Some(c2), Some(c1), pt));
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[wasm_bindgen_test]
|
||||
fn test_in_rect2() {
|
||||
// Test on top/bottom edges of rect
|
||||
let c1 = (1, 1);
|
||||
let c2 = (10, 10);
|
||||
let pt1 = (1, 5);
|
||||
let pt2 = (10, 5);
|
||||
assert!(in_rect(Some(c1), Some(c2), pt1));
|
||||
assert!(in_rect(Some(c1), Some(c2), pt2));
|
||||
// Order of the corners should not matter:
|
||||
assert!(in_rect(Some(c2), Some(c1), pt1));
|
||||
assert!(in_rect(Some(c2), Some(c1), pt2));
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[wasm_bindgen_test]
|
||||
fn test_in_rect3() {
|
||||
// Test on left/right edges of rect
|
||||
let c1 = (1, 1);
|
||||
let c2 = (10, 10);
|
||||
let pt1 = (5, 1);
|
||||
let pt2 = (5, 10);
|
||||
assert!(in_rect(Some(c1), Some(c2), pt1));
|
||||
assert!(in_rect(Some(c1), Some(c2), pt2));
|
||||
// Order of the corners should not matter:
|
||||
assert!(in_rect(Some(c2), Some(c1), pt1));
|
||||
assert!(in_rect(Some(c2), Some(c1), pt2));
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[wasm_bindgen_test]
|
||||
fn test_in_rect4() {
|
||||
// Test cases that should fail
|
||||
let c1 = (1, 1);
|
||||
let c2 = (10, 10);
|
||||
let pt1 = (0, 0);
|
||||
let pt2 = (15, 15);
|
||||
assert!(!in_rect(Some(c1), Some(c2), pt1));
|
||||
assert!(!in_rect(Some(c1), Some(c2), pt2));
|
||||
}
|
||||
}
|
|
@ -1,59 +0,0 @@
|
|||
use yew::prelude::*;
|
||||
use yewdux::prelude::*;
|
||||
|
||||
use crate::components::states::CurrentTransfer;
|
||||
use plate_tool_lib::transfer_region::Region;
|
||||
use plate_tool_lib::plate::PlateType;
|
||||
|
||||
// Color Palette for the Source Plates, can be changed here
|
||||
|
||||
use super::super::transfer_menu::RegionDisplay;
|
||||
|
||||
use super::plate_data::*;
|
||||
|
||||
pub fn mouse_callback(
|
||||
m_start_handle: MStartHandle,
|
||||
m_end_handle: MEndHandle,
|
||||
m_stat_handle: MStatHandle,
|
||||
send_coordinates: Option<Callback<(u8,u8)>>
|
||||
) -> Callback<(u8, u8, MouseEventType)> {
|
||||
Callback::from(move |(i, j, t)| match t {
|
||||
MouseEventType::Mousedown => {
|
||||
m_start_handle.set(Some((i, j)));
|
||||
m_end_handle.set(Some((i, j)));
|
||||
m_stat_handle.set(true);
|
||||
}
|
||||
MouseEventType::Mouseenter => {
|
||||
if let Some(cb) = send_coordinates.as_ref() {
|
||||
cb.emit((i,j));
|
||||
}
|
||||
if *m_stat_handle {
|
||||
m_end_handle.set(Some((i, j)));
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
pub fn mouseup_callback(
|
||||
m_start_handle: MStartHandle,
|
||||
m_end_handle: MEndHandle,
|
||||
m_stat_handle: MStatHandle,
|
||||
ct_dispatch: Dispatch<CurrentTransfer>,
|
||||
ptype: PlateType,
|
||||
) -> Callback<MouseEvent> {
|
||||
Callback::from(move |_: MouseEvent| {
|
||||
m_stat_handle.set(false);
|
||||
if let Some(ul) = *m_start_handle {
|
||||
if let Some(br) = *m_end_handle {
|
||||
if let Ok(rd) = RegionDisplay::try_from((ul.1, ul.0, br.1, br.0)) {
|
||||
ct_dispatch.reduce_mut(|state| {
|
||||
match ptype {
|
||||
PlateType::Source => state.transfer.transfer_region.source_region = Region::from(&rd),
|
||||
PlateType::Destination => state.transfer.transfer_region.dest_region = Region::from(&rd)
|
||||
};
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
|
@ -1,24 +0,0 @@
|
|||
|
||||
use yew::prelude::*;
|
||||
|
||||
use plate_tool_lib::plate_instances::PlateInstance;
|
||||
use plate_tool_lib::plate::PlateType;
|
||||
|
||||
#[derive(PartialEq, Properties)]
|
||||
pub struct PlateProps {
|
||||
pub source_plate: PlateInstance,
|
||||
pub destination_plate: PlateInstance,
|
||||
pub cell_height: f64,
|
||||
pub ptype: PlateType,
|
||||
pub send_coordinates: Option<Callback<(u8,u8)>>,
|
||||
}
|
||||
|
||||
pub type MStartHandle = UseStateHandle<Option<(u8, u8)>>;
|
||||
pub type MEndHandle = UseStateHandle<Option<(u8, u8)>>;
|
||||
pub type MStatHandle = UseStateHandle<bool>;
|
||||
|
||||
#[derive(Debug)]
|
||||
pub enum MouseEventType {
|
||||
Mousedown,
|
||||
Mouseenter,
|
||||
}
|
|
@ -1,99 +0,0 @@
|
|||
#![allow(non_snake_case)]
|
||||
mod components;
|
||||
|
||||
use std::error::Error;
|
||||
|
||||
use components::main_window::MainWindow;
|
||||
use components::states::MainState;
|
||||
use plate_tool_lib::csv::*;
|
||||
use yew::prelude::*;
|
||||
|
||||
#[cfg(debug_assertions)]
|
||||
use plate_tool_lib::*;
|
||||
|
||||
#[function_component]
|
||||
pub fn App() -> Html {
|
||||
html! {
|
||||
<MainWindow />
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(debug_assertions)]
|
||||
pub fn plate_test() {
|
||||
let source = plate::Plate::new(plate::PlateType::Source, plate::PlateFormat::W96);
|
||||
let destination = plate::Plate::new(plate::PlateType::Destination, plate::PlateFormat::W384);
|
||||
|
||||
let transfer = transfer_region::TransferRegion {
|
||||
source_plate: source,
|
||||
source_region: transfer_region::Region::Rect(Well { row: 1, col: 1 }, Well { row: 2, col: 2 }),
|
||||
dest_plate: destination,
|
||||
dest_region: transfer_region::Region::Rect(Well { row: 2, col: 2 }, Well { row: 11, col: 11 }),
|
||||
interleave_source: (1, 1),
|
||||
interleave_dest: (3, 3),
|
||||
};
|
||||
println!("{}", transfer);
|
||||
let sws = transfer.get_source_wells();
|
||||
let m = transfer.calculate_map();
|
||||
for w in sws {
|
||||
println!("{:?} -> {:?}", w, m(w));
|
||||
}
|
||||
}
|
||||
|
||||
pub fn state_to_csv(state: &MainState) -> Result<String, Box<dyn Error>> {
|
||||
match state.preferences.csv_export_type {
|
||||
components::states::CsvExportType::Normal => state_to_csv_regular(state),
|
||||
components::states::CsvExportType::EchoClient => state_to_csv_echo_client(state)
|
||||
}
|
||||
}
|
||||
|
||||
fn state_to_csv_regular(state: &MainState) -> Result<String, Box<dyn Error>> {
|
||||
let mut records: Vec<TransferRecord> = Vec::new();
|
||||
for transfer in &state.transfers {
|
||||
let src_barcode = state
|
||||
.source_plates
|
||||
.iter()
|
||||
.find(|spi| spi.get_uuid() == transfer.source_id)
|
||||
.ok_or("Found unpurged transfer")?;
|
||||
let dest_barcode = state
|
||||
.destination_plates
|
||||
.iter()
|
||||
.find(|dpi| dpi.get_uuid() == transfer.dest_id)
|
||||
.ok_or("Found unpurged transfer")?;
|
||||
records.append(&mut transfer_to_records(
|
||||
transfer,
|
||||
&src_barcode.name,
|
||||
&dest_barcode.name,
|
||||
))
|
||||
}
|
||||
records_to_csv(records)
|
||||
}
|
||||
|
||||
fn state_to_csv_echo_client(state: &MainState) -> Result<String, Box<dyn Error>> {
|
||||
let current_src = state.selected_source_plate;
|
||||
let current_dst = state.selected_dest_plate;
|
||||
|
||||
let mut records: Vec<TransferRecord> = Vec::new();
|
||||
for transfer in &state.transfers {
|
||||
|
||||
let src_barcode = state
|
||||
.source_plates
|
||||
.iter()
|
||||
.find(|spi| spi.get_uuid() == transfer.source_id)
|
||||
.ok_or("Found unpurged transfer")?;
|
||||
|
||||
let dest_barcode = state
|
||||
.destination_plates
|
||||
.iter()
|
||||
.find(|dpi| dpi.get_uuid() == transfer.dest_id)
|
||||
.ok_or("Found unpurged transfer")?;
|
||||
|
||||
if src_barcode.get_uuid() == current_src && dest_barcode.get_uuid() == current_dst {
|
||||
records.append(&mut transfer_to_records(
|
||||
transfer,
|
||||
&src_barcode.name,
|
||||
&dest_barcode.name,
|
||||
))
|
||||
}
|
||||
}
|
||||
records_to_echo_client_csv(records)
|
||||
}
|
|
@ -1,24 +1,122 @@
|
|||
#![allow(non_snake_case)]
|
||||
use std::collections::HashSet;
|
||||
|
||||
use wasm_bindgen::{prelude::*, JsCast};
|
||||
use js_sys::Array;
|
||||
use lazy_static::lazy_static;
|
||||
use regex::Regex;
|
||||
use wasm_bindgen::{prelude::*, JsCast, JsValue};
|
||||
use web_sys::{
|
||||
FileReader, HtmlButtonElement, HtmlDialogElement, HtmlElement, HtmlFormElement,
|
||||
HtmlInputElement, HtmlOptionElement, HtmlSelectElement,
|
||||
Blob, FileReader, HtmlAnchorElement, HtmlButtonElement, HtmlDialogElement, HtmlFormElement,
|
||||
HtmlInputElement, HtmlOptionElement, HtmlSelectElement, Url,
|
||||
};
|
||||
use yew::prelude::*;
|
||||
use yewdux::prelude::*;
|
||||
|
||||
use crate::components::states::MainState;
|
||||
use crate::components::states::{CurrentTransfer, MainState};
|
||||
use crate::components::transfer_menu::letters_to_num;
|
||||
|
||||
use plate_tool_lib::transfer::Transfer;
|
||||
use plate_tool_lib::transfer_region::{Region, TransferRegion};
|
||||
use plate_tool_lib::Well;
|
||||
use crate::data::transfer::Transfer;
|
||||
use crate::data::transfer_region::{Region, TransferRegion};
|
||||
|
||||
use plate_tool_lib::csv::{auto, string_well_to_pt, TransferRecord};
|
||||
use crate::data::csv::{state_to_csv, TransferRecord};
|
||||
|
||||
use super::create_close_button;
|
||||
type NoParamsCallback = Box<dyn Fn(()) -> ()>;
|
||||
|
||||
pub fn import_transfer_csv_input_callback(
|
||||
pub fn toggle_in_transfer_hashes_callback(
|
||||
main_dispatch: Dispatch<MainState>,
|
||||
) -> Callback<web_sys::MouseEvent> {
|
||||
let main_dispatch = main_dispatch.clone();
|
||||
Callback::from(move |_| {
|
||||
main_dispatch.reduce_mut(|state| {
|
||||
state.preferences.in_transfer_hashes ^= true;
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
pub fn new_plate_dialog_callback(
|
||||
new_plate_dialog_is_open: UseStateHandle<bool>,
|
||||
) -> NoParamsCallback {
|
||||
let new_plate_dialog_is_open = new_plate_dialog_is_open.clone();
|
||||
Box::new(move |_| {
|
||||
new_plate_dialog_is_open.set(false);
|
||||
})
|
||||
}
|
||||
|
||||
pub fn open_new_plate_dialog_callback(
|
||||
new_plate_dialog_is_open: UseStateHandle<bool>,
|
||||
) -> NoParamsCallback {
|
||||
let new_plate_dialog_is_open = new_plate_dialog_is_open.clone();
|
||||
Box::new(move |_| {
|
||||
new_plate_dialog_is_open.set(true);
|
||||
})
|
||||
}
|
||||
|
||||
pub fn new_button_callback(
|
||||
main_dispatch: Dispatch<MainState>,
|
||||
ct_dispatch: Dispatch<CurrentTransfer>,
|
||||
) -> Callback<web_sys::MouseEvent> {
|
||||
Callback::from(move |_| {
|
||||
let window = web_sys::window().unwrap();
|
||||
let confirm =
|
||||
window.confirm_with_message("This will reset all plates and transfers. Proceed?");
|
||||
if let Ok(confirm) = confirm {
|
||||
if confirm {
|
||||
main_dispatch.set(MainState::default());
|
||||
ct_dispatch.set(CurrentTransfer::default());
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
fn save_str(data: &str, name: &str) {
|
||||
let blob =
|
||||
Blob::new_with_str_sequence(&Array::from_iter(std::iter::once(JsValue::from_str(data))));
|
||||
if let Ok(blob) = blob {
|
||||
let url = Url::create_object_url_with_blob(&blob).expect("We have a blob, why not URL?");
|
||||
// Beneath is the cool hack to download files
|
||||
let window = web_sys::window().unwrap();
|
||||
let document = window.document().unwrap();
|
||||
let anchor = document
|
||||
.create_element("a")
|
||||
.unwrap()
|
||||
.dyn_into::<HtmlAnchorElement>()
|
||||
.unwrap();
|
||||
anchor.set_download(name);
|
||||
anchor.set_href(&url);
|
||||
anchor.click();
|
||||
}
|
||||
}
|
||||
|
||||
pub fn export_csv_button_callback(main_state: std::rc::Rc<MainState>) -> Callback<MouseEvent> {
|
||||
Callback::from(move |_| {
|
||||
if main_state.transfers.is_empty() {
|
||||
web_sys::window()
|
||||
.unwrap()
|
||||
.alert_with_message("No transfers to export.")
|
||||
.unwrap();
|
||||
return;
|
||||
}
|
||||
web_sys::window().unwrap().alert_with_message("CSV export is currently not importable. Export as JSON if you'd like to back up your work!").unwrap();
|
||||
if let Ok(csv) = state_to_csv(&main_state) {
|
||||
save_str(&csv, "transfers.csv");
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
pub fn export_json_button_callback(main_state: std::rc::Rc<MainState>) -> Callback<MouseEvent> {
|
||||
Callback::from(move |_| {
|
||||
if let Ok(json) = serde_json::to_string(&main_state) {
|
||||
save_str(&json, "plate-tool-state.json");
|
||||
} else {
|
||||
web_sys::window()
|
||||
.unwrap()
|
||||
.alert_with_message("Failed to export.")
|
||||
.unwrap();
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
pub fn input_json_input_callback(
|
||||
main_dispatch: Dispatch<MainState>,
|
||||
modal: HtmlDialogElement,
|
||||
) -> Closure<dyn FnMut(Event)> {
|
||||
|
@ -35,7 +133,16 @@ pub fn import_transfer_csv_input_callback(
|
|||
let main_dispatch = main_dispatch.clone(); // Clone to satisfy FnMut
|
||||
// trait
|
||||
let modal = modal.clone();
|
||||
let onload = import_transfer_csv_onload_callback(main_dispatch, fr1, modal);
|
||||
let onload = Closure::<dyn FnMut(_)>::new(move |_: Event| {
|
||||
if let Some(value) = &fr1.result().ok().and_then(|v| v.as_string()) {
|
||||
let ms = serde_json::from_str::<MainState>(value);
|
||||
match ms {
|
||||
Ok(ms) => main_dispatch.set(ms),
|
||||
Err(e) => log::debug!("{:?}", e),
|
||||
};
|
||||
modal.close();
|
||||
}
|
||||
});
|
||||
fr.set_onload(Some(onload.as_ref().unchecked_ref()));
|
||||
onload.forget(); // Magic (don't touch)
|
||||
}
|
||||
|
@ -44,7 +151,7 @@ pub fn import_transfer_csv_input_callback(
|
|||
})
|
||||
}
|
||||
|
||||
pub fn import_transfer_csv_callback(main_dispatch: Dispatch<MainState>) -> Callback<MouseEvent> {
|
||||
pub fn import_json_button_callback(main_dispatch: Dispatch<MainState>) -> Callback<MouseEvent> {
|
||||
Callback::from(move |_| {
|
||||
let window = web_sys::window().unwrap();
|
||||
let document = window.document().unwrap();
|
||||
|
@ -62,10 +169,7 @@ pub fn import_transfer_csv_callback(main_dispatch: Dispatch<MainState>) -> Callb
|
|||
})
|
||||
};
|
||||
modal.set_onclose(Some(onclose_callback.as_ref().unchecked_ref()));
|
||||
|
||||
let close_button = create_close_button(&onclose_callback);
|
||||
onclose_callback.forget();
|
||||
modal.append_child(&close_button).unwrap();
|
||||
|
||||
let form = document
|
||||
.create_element("form")
|
||||
|
@ -78,13 +182,13 @@ pub fn import_transfer_csv_callback(main_dispatch: Dispatch<MainState>) -> Callb
|
|||
.dyn_into::<HtmlInputElement>()
|
||||
.unwrap();
|
||||
input.set_type("file");
|
||||
input.set_accept(".csv");
|
||||
input.set_accept(".json");
|
||||
form.append_child(&input).unwrap();
|
||||
|
||||
let input_callback = {
|
||||
let main_dispatch = main_dispatch.clone();
|
||||
let modal = modal.clone();
|
||||
import_transfer_csv_input_callback(main_dispatch, modal)
|
||||
input_json_input_callback(main_dispatch, modal)
|
||||
};
|
||||
input.set_onchange(Some(input_callback.as_ref().unchecked_ref()));
|
||||
input_callback.forget(); // Magic straight from the docs, don't touch :(
|
||||
|
@ -95,6 +199,83 @@ pub fn import_transfer_csv_callback(main_dispatch: Dispatch<MainState>) -> Callb
|
|||
})
|
||||
}
|
||||
|
||||
pub fn import_transfer_csv_submit_callback(
|
||||
main_dispatch: Dispatch<MainState>,
|
||||
from_source: HtmlSelectElement,
|
||||
to_source: HtmlSelectElement,
|
||||
from_dest: HtmlSelectElement,
|
||||
to_dest: HtmlSelectElement,
|
||||
records: Vec<TransferRecord>,
|
||||
) -> Closure<dyn FnMut(Event)> {
|
||||
Closure::<dyn FnMut(_)>::new(move |_: Event| {
|
||||
let from_source = from_source.value();
|
||||
let to_source = to_source.value();
|
||||
let from_dest = from_dest.value();
|
||||
let to_dest = to_dest.value();
|
||||
|
||||
lazy_static! {
|
||||
static ref REGEX: Regex = Regex::new(r"([A-Z]+)(\d+)").unwrap();
|
||||
}
|
||||
let records: Vec<((u8, u8), (u8, u8))> = records
|
||||
.iter()
|
||||
.filter(|record| record.source_plate == from_source)
|
||||
.filter(|record| record.destination_plate == from_dest)
|
||||
.map(|record| {
|
||||
let c1 = REGEX.captures(&record.source_well).unwrap();
|
||||
let c2 = REGEX.captures(&record.destination_well).unwrap();
|
||||
log::debug!("{} {}", &record.source_well, &record.destination_well);
|
||||
log::debug!("{},{} {},{}", &c1[1], &c1[2], &c2[1], &c2[2]);
|
||||
|
||||
(
|
||||
(
|
||||
letters_to_num(&c1[1]).unwrap(),
|
||||
c1[2].parse::<u8>().unwrap(),
|
||||
),
|
||||
(
|
||||
letters_to_num(&c2[1]).unwrap(),
|
||||
c2[2].parse::<u8>().unwrap(),
|
||||
),
|
||||
)
|
||||
})
|
||||
.collect();
|
||||
|
||||
let spi = main_dispatch
|
||||
.get()
|
||||
.source_plates
|
||||
.iter()
|
||||
.find(|src| src.name == to_source)
|
||||
.unwrap()
|
||||
.clone();
|
||||
let dpi = main_dispatch
|
||||
.get()
|
||||
.destination_plates
|
||||
.iter()
|
||||
.find(|dest| dest.name == to_dest)
|
||||
.unwrap()
|
||||
.clone();
|
||||
|
||||
let custom_region = Region::new_custom(&records);
|
||||
let transfer_region = TransferRegion {
|
||||
source_region: custom_region.clone(),
|
||||
dest_region: custom_region,
|
||||
interleave_source: (1, 1),
|
||||
interleave_dest: (1, 1),
|
||||
source_plate: spi.plate,
|
||||
dest_plate: dpi.plate,
|
||||
};
|
||||
|
||||
let transfer = Transfer::new(spi, dpi, transfer_region, "Custom Transfer".to_string());
|
||||
main_dispatch.reduce_mut(|state| {
|
||||
state.transfers.push(transfer);
|
||||
state.selected_transfer = state
|
||||
.transfers
|
||||
.last()
|
||||
.expect("An element should have just been added")
|
||||
.get_uuid();
|
||||
});
|
||||
})
|
||||
}
|
||||
|
||||
pub fn import_transfer_csv_onload_callback(
|
||||
main_dispatch: Dispatch<MainState>,
|
||||
file_reader: FileReader,
|
||||
|
@ -102,7 +283,19 @@ pub fn import_transfer_csv_onload_callback(
|
|||
) -> Closure<dyn FnMut(Event)> {
|
||||
Closure::<dyn FnMut(_)>::new(move |_: Event| {
|
||||
if let Some(value) = &file_reader.result().ok().and_then(|v| v.as_string()) {
|
||||
let records = plate_tool_lib::csv::read_csv(value);
|
||||
let mut rdr = csv::Reader::from_reader(value.as_bytes());
|
||||
let mut records = Vec::new();
|
||||
for record in rdr.deserialize::<crate::data::csv::TransferRecord>() {
|
||||
match record {
|
||||
Ok(r) => {
|
||||
//log::debug!("{:?}", r);
|
||||
records.push(r);
|
||||
}
|
||||
Err(e) => {
|
||||
log::debug!("{:?}", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
let mut sources: HashSet<String> = HashSet::new();
|
||||
let mut destinations: HashSet<String> = HashSet::new();
|
||||
|
@ -113,17 +306,6 @@ pub fn import_transfer_csv_onload_callback(
|
|||
|
||||
let window = web_sys::window().unwrap();
|
||||
let document = window.document().unwrap();
|
||||
|
||||
let auto_button = document
|
||||
.create_element("button")
|
||||
.unwrap()
|
||||
.dyn_into::<HtmlElement>()
|
||||
.unwrap();
|
||||
auto_button.set_inner_text("Auto");
|
||||
let auto_button_callback = auto_callback(main_dispatch.clone(), &records);
|
||||
auto_button.set_onclick(Some(auto_button_callback.as_ref().unchecked_ref()));
|
||||
auto_button_callback.forget();
|
||||
|
||||
let form = document
|
||||
.create_element("form")
|
||||
.unwrap()
|
||||
|
@ -220,87 +402,32 @@ pub fn import_transfer_csv_onload_callback(
|
|||
form.append_child(&to_dest).unwrap();
|
||||
modal.append_child(&submit).unwrap();
|
||||
modal.append_child(&form).unwrap();
|
||||
modal.append_child(&auto_button).unwrap();
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
pub fn import_transfer_csv_submit_callback(
|
||||
pub fn import_transfer_csv_input_callback(
|
||||
main_dispatch: Dispatch<MainState>,
|
||||
from_source: HtmlSelectElement,
|
||||
to_source: HtmlSelectElement,
|
||||
from_dest: HtmlSelectElement,
|
||||
to_dest: HtmlSelectElement,
|
||||
records: Vec<TransferRecord>,
|
||||
modal: HtmlDialogElement,
|
||||
) -> Closure<dyn FnMut(Event)> {
|
||||
Closure::<dyn FnMut(_)>::new(move |_: Event| {
|
||||
let from_source = from_source.value();
|
||||
let to_source = to_source.value();
|
||||
let from_dest = from_dest.value();
|
||||
let to_dest = to_dest.value();
|
||||
|
||||
let records: Vec<(Well, Well)> = records
|
||||
.iter()
|
||||
.filter(|record| record.source_plate == from_source)
|
||||
.filter(|record| record.destination_plate == from_dest)
|
||||
.map(|record| {
|
||||
(
|
||||
string_well_to_pt(&record.source_well).unwrap(),
|
||||
string_well_to_pt(&record.destination_well).unwrap(),
|
||||
)
|
||||
})
|
||||
.collect();
|
||||
|
||||
let spi = main_dispatch
|
||||
.get()
|
||||
.source_plates
|
||||
.iter()
|
||||
.find(|src| src.name == to_source)
|
||||
.unwrap()
|
||||
.clone();
|
||||
let dpi = main_dispatch
|
||||
.get()
|
||||
.destination_plates
|
||||
.iter()
|
||||
.find(|dest| dest.name == to_dest)
|
||||
.unwrap()
|
||||
.clone();
|
||||
|
||||
let custom_region = Region::new_custom(&records);
|
||||
let transfer_region = TransferRegion {
|
||||
source_region: custom_region.clone(),
|
||||
dest_region: custom_region,
|
||||
interleave_source: (1, 1),
|
||||
interleave_dest: (1, 1),
|
||||
source_plate: spi.plate,
|
||||
dest_plate: dpi.plate,
|
||||
};
|
||||
|
||||
let transfer = Transfer::new(spi, dpi, transfer_region, "Custom Transfer".to_string());
|
||||
main_dispatch.reduce_mut(|state| {
|
||||
state.transfers.push(transfer);
|
||||
state.selected_transfer = state
|
||||
.transfers
|
||||
.last()
|
||||
.expect("An element should have just been added")
|
||||
.get_uuid();
|
||||
});
|
||||
})
|
||||
}
|
||||
|
||||
fn auto_callback(
|
||||
main_dispatch: Dispatch<MainState>,
|
||||
records: &[TransferRecord],
|
||||
) -> Closure<dyn FnMut(Event)> {
|
||||
let records = Vec::from(records);
|
||||
Closure::<dyn FnMut(_)>::new(move |_| {
|
||||
let res = auto(&records);
|
||||
main_dispatch.reduce_mut(|state| {
|
||||
state.source_plates.extend(res.sources);
|
||||
state
|
||||
.destination_plates
|
||||
.extend(res.destinations);
|
||||
state.transfers.extend(res.transfers);
|
||||
});
|
||||
Closure::<dyn FnMut(_)>::new(move |e: Event| {
|
||||
if let Some(input) = e.current_target() {
|
||||
let input = input
|
||||
.dyn_into::<HtmlInputElement>()
|
||||
.expect("We know this is an input.");
|
||||
if let Some(files) = input.files() {
|
||||
if let Some(file) = files.get(0) {
|
||||
let fr = web_sys::FileReader::new().unwrap();
|
||||
fr.read_as_text(&file).unwrap();
|
||||
let fr1 = fr.clone(); // Clone to avoid outliving closure
|
||||
let main_dispatch = main_dispatch.clone(); // Clone to satisfy FnMut
|
||||
// trait
|
||||
let modal = modal.clone();
|
||||
let onload = import_transfer_csv_onload_callback(main_dispatch, fr1, modal);
|
||||
fr.set_onload(Some(onload.as_ref().unchecked_ref()));
|
||||
onload.forget(); // Magic (don't touch)
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
|
@ -5,8 +5,8 @@ use wasm_bindgen::JsCast;
|
|||
use web_sys::{EventTarget, FormData, HtmlFormElement};
|
||||
|
||||
use crate::components::states::MainState;
|
||||
use plate_tool_lib::plate::*;
|
||||
use plate_tool_lib::plate_instances::PlateInstance;
|
||||
use crate::data::plate::*;
|
||||
use crate::data::plate_instances::PlateInstance;
|
||||
|
||||
pub fn new_plate_callback(
|
||||
dispatch: Dispatch<MainState>,
|
|
@ -6,7 +6,7 @@ use yew::prelude::*;
|
|||
use yewdux::prelude::*;
|
||||
|
||||
use crate::components::transfer_menu::RegionDisplay;
|
||||
use plate_tool_lib::{transfer::Transfer, transfer_region::Region, transfer_volume::TransferVolume};
|
||||
use crate::data::{transfer::Transfer, transfer_region::Region};
|
||||
|
||||
use crate::components::states::{CurrentTransfer, MainState};
|
||||
|
||||
|
@ -142,7 +142,7 @@ pub fn on_volume_change_callback(ct_dispatch: Dispatch<CurrentTransfer>) -> Call
|
|||
.expect("Must have been emitted by input");
|
||||
if let Ok(num) = input.value().parse::<f32>() {
|
||||
ct_dispatch.reduce_mut(|state| {
|
||||
state.transfer.volume = TransferVolume::Single(num);
|
||||
state.transfer.volume = num;
|
||||
});
|
||||
}
|
||||
})
|
||||
|
@ -184,18 +184,12 @@ pub fn save_transfer_button_callback_callback(
|
|||
.iter()
|
||||
.find(|dpi| dpi.get_uuid() == main_state.selected_dest_plate)
|
||||
{
|
||||
// Only mutable for volume assignment!
|
||||
let mut new_transfer = Transfer::new(
|
||||
let new_transfer = Transfer::new(
|
||||
spi.clone(),
|
||||
dpi.clone(),
|
||||
ct_state.transfer.transfer_region.clone(),
|
||||
ct_state.transfer.name.clone(),
|
||||
);
|
||||
|
||||
// This clone is cheap - we know this is just a single value
|
||||
// so cloning f32 will be fast.
|
||||
new_transfer.volume = ct_state.transfer.volume.clone();
|
||||
|
||||
main_dispatch.reduce_mut(|state| {
|
||||
state.transfers.push(new_transfer);
|
||||
state.selected_transfer = state
|
|
@ -6,7 +6,44 @@ use yew::prelude::*;
|
|||
use yewdux::prelude::*;
|
||||
|
||||
use crate::components::states::{CurrentTransfer, MainState};
|
||||
use plate_tool_lib::transfer_region::Region;
|
||||
use crate::data::transfer_region::Region;
|
||||
|
||||
type NoParamsCallback = Box<dyn Fn(()) -> ()>;
|
||||
|
||||
pub fn open_plate_info_callback(
|
||||
plate_menu_id: UseStateHandle<Option<Uuid>>,
|
||||
) -> Callback<MouseEvent> {
|
||||
Callback::from(move |e: MouseEvent| {
|
||||
let target: Option<EventTarget> = e.target();
|
||||
let li = target.and_then(|t| t.dyn_into::<HtmlElement>().ok());
|
||||
if let Some(li) = li {
|
||||
if let Ok(id) = li.id().as_str().parse::<u128>() {
|
||||
plate_menu_id.set(Some(Uuid::from_u128(id)));
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
pub fn plate_info_close_callback(
|
||||
plate_menu_id: UseStateHandle<Option<Uuid>>,
|
||||
) -> NoParamsCallback {
|
||||
Box::new(move |_| {
|
||||
plate_menu_id.set(None);
|
||||
})
|
||||
}
|
||||
|
||||
pub fn plate_info_delete_callback(
|
||||
main_dispatch: Dispatch<MainState>,
|
||||
plate_menu_id: UseStateHandle<Option<Uuid>>,
|
||||
) -> NoParamsCallback {
|
||||
Box::new(move |_| {
|
||||
if let Some(id) = *plate_menu_id {
|
||||
main_dispatch.reduce_mut(|state| {
|
||||
state.del_plate(id);
|
||||
});
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
pub fn source_plate_select_callback(
|
||||
main_dispatch: Dispatch<MainState>,
|
||||
|
@ -52,11 +89,7 @@ pub fn destination_plate_select_callback(
|
|||
})
|
||||
}
|
||||
|
||||
pub fn transfer_select_callback(
|
||||
main_state: Rc<MainState>,
|
||||
main_dispatch: Dispatch<MainState>,
|
||||
ct_dispatch: Dispatch<CurrentTransfer>,
|
||||
) -> Callback<MouseEvent> {
|
||||
pub fn transfer_select_callback(main_state: Rc<MainState>, main_dispatch: Dispatch<MainState>, ct_dispatch: Dispatch<CurrentTransfer>) -> Callback<MouseEvent> {
|
||||
Callback::from(move |e: MouseEvent| {
|
||||
let target: Option<EventTarget> = e.target();
|
||||
let li = target.and_then(|t| t.dyn_into::<HtmlElement>().ok());
|
|
@ -1,14 +1,18 @@
|
|||
#![allow(non_snake_case)]
|
||||
|
||||
use js_sys::Array;
|
||||
use wasm_bindgen::{prelude::*, JsCast, JsValue};
|
||||
use web_sys::{Blob, HtmlAnchorElement, HtmlDialogElement, HtmlFormElement, HtmlInputElement, Url};
|
||||
use yew::prelude::*;
|
||||
use yewdux::prelude::*;
|
||||
|
||||
use crate::components::new_plate_dialog::{NewPlateDialog, NewPlateDialogType};
|
||||
use crate::components::new_plate_dialog::NewPlateDialog;
|
||||
use crate::components::plates::plate_container::PlateContainer;
|
||||
use crate::components::states::{CurrentTransfer, MainState};
|
||||
use crate::components::transfer_menu::TransferMenu;
|
||||
use crate::components::tree::Tree;
|
||||
|
||||
use plate_tool_lib::plate_instances::PlateInstance;
|
||||
use crate::data::plate_instances::PlateInstance;
|
||||
|
||||
use crate::components::callbacks::main_window_callbacks;
|
||||
|
||||
|
@ -43,22 +47,7 @@ pub fn MainWindow() -> Html {
|
|||
main_window_callbacks::toggle_in_transfer_hashes_callback(main_dispatch)
|
||||
};
|
||||
|
||||
let toggle_volume_heatmap_callback = {
|
||||
let main_dispatch = main_dispatch.clone();
|
||||
main_window_callbacks::toggle_volume_heatmap_callback(main_dispatch)
|
||||
};
|
||||
|
||||
let toggle_show_current_coordinates_callback = {
|
||||
let main_dispatch = main_dispatch.clone();
|
||||
main_window_callbacks::toggle_show_current_coordinates_callback(main_dispatch)
|
||||
};
|
||||
|
||||
let change_csv_export_type_callback = {
|
||||
let main_dispatch = main_dispatch.clone();
|
||||
main_window_callbacks::change_csv_export_type_callback(main_dispatch)
|
||||
};
|
||||
|
||||
let new_plate_dialog_is_open: UseStateHandle<Option<NewPlateDialogType>> = use_state_eq(|| None);
|
||||
let new_plate_dialog_is_open = use_state_eq(|| false);
|
||||
let new_plate_dialog_callback =
|
||||
main_window_callbacks::new_plate_dialog_callback(new_plate_dialog_is_open.clone());
|
||||
|
||||
|
@ -83,8 +72,53 @@ pub fn MainWindow() -> Html {
|
|||
main_window_callbacks::import_json_button_callback(main_dispatch)
|
||||
};
|
||||
|
||||
let import_transfer_csv_callback =
|
||||
main_window_callbacks::import_transfer_csv_callback(main_dispatch.clone());
|
||||
let import_transfer_csv_callback = {
|
||||
Callback::from(move |_| {
|
||||
let window = web_sys::window().unwrap();
|
||||
let document = window.document().unwrap();
|
||||
let body = document.body().unwrap();
|
||||
let modal = document
|
||||
.create_element("dialog")
|
||||
.unwrap()
|
||||
.dyn_into::<HtmlDialogElement>()
|
||||
.unwrap();
|
||||
modal.set_text_content(Some("Import File:"));
|
||||
let onclose_callback = {
|
||||
let modal = modal.clone();
|
||||
Closure::<dyn FnMut(_)>::new(move |_: Event| {
|
||||
modal.remove();
|
||||
})
|
||||
};
|
||||
modal.set_onclose(Some(onclose_callback.as_ref().unchecked_ref()));
|
||||
onclose_callback.forget();
|
||||
|
||||
let form = document
|
||||
.create_element("form")
|
||||
.unwrap()
|
||||
.dyn_into::<HtmlFormElement>()
|
||||
.unwrap();
|
||||
let input = document
|
||||
.create_element("input")
|
||||
.unwrap()
|
||||
.dyn_into::<HtmlInputElement>()
|
||||
.unwrap();
|
||||
input.set_type("file");
|
||||
input.set_accept(".csv");
|
||||
form.append_child(&input).unwrap();
|
||||
|
||||
let input_callback = {
|
||||
let main_dispatch = main_dispatch.clone();
|
||||
let modal = modal.clone();
|
||||
main_window_callbacks::import_transfer_csv_input_callback(main_dispatch, modal)
|
||||
};
|
||||
input.set_onchange(Some(input_callback.as_ref().unchecked_ref()));
|
||||
input_callback.forget(); // Magic straight from the docs, don't touch :(
|
||||
|
||||
modal.append_child(&form).unwrap();
|
||||
body.append_child(&modal).unwrap();
|
||||
modal.show_modal().unwrap();
|
||||
})
|
||||
};
|
||||
|
||||
html! {
|
||||
<>
|
||||
|
@ -113,14 +147,6 @@ pub fn MainWindow() -> Html {
|
|||
<button>{"Styles"}</button>
|
||||
<div>
|
||||
<button onclick={toggle_in_transfer_hashes_callback}>{"Toggle transfer hashes"}</button>
|
||||
<button onclick={toggle_volume_heatmap_callback}>{"Toggle volume heatmap"}</button>
|
||||
<button onclick={toggle_show_current_coordinates_callback}>{"Toggle current coordinates view"}</button>
|
||||
</div>
|
||||
</div>
|
||||
<div class="dropdown-sub">
|
||||
<button>{"Export"}</button>
|
||||
<div>
|
||||
<button onclick={change_csv_export_type_callback}>{"Change CSV export type"}</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
@ -130,10 +156,29 @@ pub fn MainWindow() -> Html {
|
|||
<TransferMenu />
|
||||
<PlateContainer source_dims={source_plate_instance}
|
||||
destination_dims={destination_plate_instance}/>
|
||||
if {new_plate_dialog_is_open.is_some()} {
|
||||
<NewPlateDialog close_callback={new_plate_dialog_callback} dialog_type={new_plate_dialog_is_open.unwrap()}/>
|
||||
if {*new_plate_dialog_is_open} {
|
||||
<NewPlateDialog close_callback={new_plate_dialog_callback}/>
|
||||
}
|
||||
</div>
|
||||
</>
|
||||
}
|
||||
}
|
||||
|
||||
fn save_str(data: &str, name: &str) {
|
||||
let blob =
|
||||
Blob::new_with_str_sequence(&Array::from_iter(std::iter::once(JsValue::from_str(data))));
|
||||
if let Ok(blob) = blob {
|
||||
let url = Url::create_object_url_with_blob(&blob).expect("We have a blob, why not URL?");
|
||||
// Beneath is the cool hack to download files
|
||||
let window = web_sys::window().unwrap();
|
||||
let document = window.document().unwrap();
|
||||
let anchor = document
|
||||
.create_element("a")
|
||||
.unwrap()
|
||||
.dyn_into::<HtmlAnchorElement>()
|
||||
.unwrap();
|
||||
anchor.set_download(name);
|
||||
anchor.set_href(&url);
|
||||
anchor.click();
|
||||
}
|
||||
}
|
|
@ -4,22 +4,13 @@ use yewdux::prelude::*;
|
|||
use web_sys::HtmlDialogElement;
|
||||
|
||||
use crate::components::states::MainState;
|
||||
use crate::data::plate_instances::PlateInstance;
|
||||
|
||||
use crate::components::callbacks::new_plate_dialog_callbacks;
|
||||
|
||||
#[derive(PartialEq, Properties)]
|
||||
pub struct NewPlateDialogProps {
|
||||
pub close_callback: Callback<()>,
|
||||
pub dialog_type: NewPlateDialogType,
|
||||
}
|
||||
|
||||
#[derive(PartialEq, Clone, Copy, Debug)]
|
||||
pub enum NewPlateDialogType {
|
||||
SourceOnly,
|
||||
DestinationOnly,
|
||||
|
||||
#[allow(dead_code)]
|
||||
Both, // Retained old functionality
|
||||
}
|
||||
|
||||
#[function_component]
|
||||
|
@ -41,8 +32,7 @@ pub fn NewPlateDialog(props: &NewPlateDialogProps) -> Html {
|
|||
{
|
||||
let dialog_ref = dialog_ref.clone();
|
||||
|
||||
use_effect_with(
|
||||
dialog_ref,
|
||||
use_effect_with_deps(
|
||||
|dialog_ref| {
|
||||
dialog_ref
|
||||
.cast::<HtmlDialogElement>()
|
||||
|
@ -50,18 +40,13 @@ pub fn NewPlateDialog(props: &NewPlateDialogProps) -> Html {
|
|||
.show_modal()
|
||||
.ok();
|
||||
},
|
||||
dialog_ref,
|
||||
);
|
||||
}
|
||||
|
||||
let header_interior_text = match props.dialog_type {
|
||||
NewPlateDialogType::Both => "",
|
||||
NewPlateDialogType::SourceOnly => " source",
|
||||
NewPlateDialogType::DestinationOnly => " destination",
|
||||
};
|
||||
|
||||
html! {
|
||||
<dialog ref={dialog_ref} class="dialog new_plate_dialog" onclose={onclose}>
|
||||
<h2>{format!("Create a{} plate:", header_interior_text)}</h2>
|
||||
<h2>{"Create a plate:"}</h2>
|
||||
<form onsubmit={new_plate_callback}>
|
||||
<input type="text" name="new_plate_name" placeholder="Name"/>
|
||||
<select name="plate_format">
|
||||
|
@ -74,7 +59,10 @@ pub fn NewPlateDialog(props: &NewPlateDialogProps) -> Html {
|
|||
<option value="1536">{"1536"}</option>
|
||||
<option value="3456">{"3456"}</option>
|
||||
</select>
|
||||
{ plate_type_selector(props.dialog_type) }
|
||||
<input type="radio" name="new_plate_type" id="npt_src" value="src" />
|
||||
<label for="npt_src">{"Source"}</label>
|
||||
<input type="radio" name="new_plate_type" id="npt_dest" value="dest" />
|
||||
<label for="npt_dest">{"Destination"}</label>
|
||||
<input type="submit" name="new_plate_button" value="Create" />
|
||||
</form>
|
||||
<form class="modal_close" method="dialog"><button /></form>
|
||||
|
@ -82,27 +70,9 @@ pub fn NewPlateDialog(props: &NewPlateDialogProps) -> Html {
|
|||
}
|
||||
}
|
||||
|
||||
fn plate_type_selector(t: NewPlateDialogType) -> Html {
|
||||
match t {
|
||||
NewPlateDialogType::Both => {
|
||||
html! {
|
||||
<>
|
||||
<input type="radio" name="new_plate_type" id="npt_src" value="src" />
|
||||
<label for="npt_src">{"Source"}</label>
|
||||
<input type="radio" name="new_plate_type" id="npt_dest" value="dest" />
|
||||
<label for="npt_dest">{"Destination"}</label>
|
||||
</>
|
||||
}
|
||||
},
|
||||
NewPlateDialogType::SourceOnly => {
|
||||
html! {
|
||||
<input type="hidden" name="new_plate_type" id="npt_src" value="src" />
|
||||
}
|
||||
},
|
||||
NewPlateDialogType::DestinationOnly => {
|
||||
html! {
|
||||
<input type="hidden" name="new_plate_type" id="npt_dest" value="dest" />
|
||||
}
|
||||
}
|
||||
impl From<&PlateInstance> for String {
|
||||
fn from(value: &PlateInstance) -> Self {
|
||||
// Could have other formatting here
|
||||
format!("{}, {}", value.name, value.plate.plate_format)
|
||||
}
|
||||
}
|
|
@ -0,0 +1,216 @@
|
|||
#![allow(non_snake_case)]
|
||||
|
||||
use std::collections::HashMap;
|
||||
use yew::prelude::*;
|
||||
use yewdux::prelude::*;
|
||||
|
||||
use crate::components::states::{CurrentTransfer, MainState};
|
||||
use crate::data::plate_instances::PlateInstance;
|
||||
use crate::data::transfer::Transfer;
|
||||
use crate::data::transfer_region::Region;
|
||||
|
||||
// Color Palette for the Source Plates, can be changed here
|
||||
use crate::components::plates::util::Palettes;
|
||||
const PALETTE: super::util::ColorPalette = Palettes::RAINBOW;
|
||||
|
||||
use super::super::transfer_menu::{num_to_letters, RegionDisplay};
|
||||
|
||||
#[derive(Properties, PartialEq)]
|
||||
pub struct DestinationPlateProps {
|
||||
pub source_plate: PlateInstance,
|
||||
pub destination_plate: PlateInstance,
|
||||
pub cell_height: f64,
|
||||
}
|
||||
|
||||
#[function_component]
|
||||
pub fn DestinationPlate(props: &DestinationPlateProps) -> Html {
|
||||
let (main_state, _) = use_store::<MainState>();
|
||||
let (ct_state, ct_dispatch) = use_store::<CurrentTransfer>();
|
||||
let m_start_handle: UseStateHandle<Option<(u8, u8)>> = use_state_eq(|| None);
|
||||
let m_end_handle: UseStateHandle<Option<(u8, u8)>> = use_state_eq(|| None);
|
||||
let m_stat_handle: UseStateHandle<bool> = use_state_eq(|| false);
|
||||
|
||||
if !(*m_stat_handle) {
|
||||
let (pt1, pt2) = match ct_state.transfer.transfer_region.dest_region {
|
||||
Region::Point((x, y)) => ((x, y), (x, y)),
|
||||
Region::Rect(c1, c2) => (c1, c2),
|
||||
Region::Custom(_) => ((0,0), (0,0)),
|
||||
};
|
||||
m_start_handle.set(Some(pt1));
|
||||
m_end_handle.set(Some(pt2));
|
||||
}
|
||||
let destination_wells = ct_state.transfer.transfer_region.get_destination_wells();
|
||||
|
||||
let ordered_ids: Vec<uuid::Uuid> = {
|
||||
let mut ids: Vec<uuid::Uuid> = main_state.transfers.clone().iter()
|
||||
.map(|x| x.id)
|
||||
.collect();
|
||||
ids.sort_unstable();
|
||||
ids
|
||||
};
|
||||
|
||||
let mouse_callback = {
|
||||
let m_start_handle = m_start_handle.clone();
|
||||
let m_end_handle = m_end_handle.clone();
|
||||
let m_stat_handle = m_stat_handle.clone();
|
||||
|
||||
Callback::from(move |(i, j, t)| match t {
|
||||
MouseEventType::Mousedown => {
|
||||
m_start_handle.set(Some((i, j)));
|
||||
m_end_handle.set(Some((i, j)));
|
||||
m_stat_handle.set(true);
|
||||
}
|
||||
MouseEventType::Mouseenter => {
|
||||
if *m_stat_handle {
|
||||
m_end_handle.set(Some((i, j)));
|
||||
}
|
||||
}
|
||||
})
|
||||
};
|
||||
|
||||
let transfer_map = {
|
||||
let ts = main_state
|
||||
.transfers
|
||||
.iter()
|
||||
.filter(|t| t.dest_id == props.destination_plate.get_uuid());
|
||||
let mut tooltip_map: HashMap<(u8, u8), Vec<&Transfer>> = HashMap::new();
|
||||
for t in ts {
|
||||
let dws = t.transfer_region.get_destination_wells();
|
||||
for dw in dws {
|
||||
if let Some(val) = tooltip_map.get_mut(&dw) {
|
||||
val.push(t);
|
||||
} else {
|
||||
tooltip_map.insert(dw, vec![t]);
|
||||
}
|
||||
}
|
||||
}
|
||||
tooltip_map
|
||||
};
|
||||
|
||||
let mouseup_callback = {
|
||||
let m_start_handle = m_start_handle.clone();
|
||||
let m_end_handle = m_end_handle.clone();
|
||||
|
||||
Callback::from(move |_: MouseEvent| {
|
||||
m_stat_handle.set(false);
|
||||
if let Some(ul) = *m_start_handle {
|
||||
if let Some(br) = *m_end_handle {
|
||||
if let Ok(rd) = RegionDisplay::try_from((ul.0, ul.1, br.0, br.1)) {
|
||||
ct_dispatch.reduce_mut(|state| {
|
||||
state.transfer.transfer_region.dest_region = Region::from(&rd);
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
};
|
||||
|
||||
let mouseleave_callback = Callback::clone(&mouseup_callback);
|
||||
|
||||
|
||||
let screenshot_callback = Callback::from(|_| {
|
||||
let _ = js_sys::eval("copy_screenshot_dest()");
|
||||
});
|
||||
|
||||
let column_header = {
|
||||
let headers = (1..=props.destination_plate.plate.size().1)
|
||||
.map(|j| {
|
||||
html! {<th>{format!("{:0>2}", j)}</th>}
|
||||
})
|
||||
.collect::<Html>();
|
||||
html! {<tr><th />{ headers }</tr>}
|
||||
};
|
||||
let rows = (1..=props.destination_plate.plate.size().0)
|
||||
.map(|i| {
|
||||
let row_header = html! {<th>{num_to_letters(i)}</th>};
|
||||
let row = (1..=props.destination_plate.plate.size().1).map(|j| {
|
||||
html! {
|
||||
<DestPlateCell i={i} j={j}
|
||||
selected={super::source_plate::in_rect(*m_start_handle.clone(), *m_end_handle.clone(), (i,j))}
|
||||
mouse={mouse_callback.clone()}
|
||||
in_transfer={destination_wells.contains(&(i,j)) && main_state.preferences.in_transfer_hashes}
|
||||
color={transfer_map.get(&(i,j))
|
||||
.and_then(|t| t.last())
|
||||
.map(|t| PALETTE.get_ordered(t.get_uuid(), &ordered_ids))
|
||||
}
|
||||
cell_height={props.cell_height}
|
||||
title={transfer_map.get(&(i,j)).map(|transfers| format!("Used by: {}", transfers.iter().map(|t| t.name.clone())
|
||||
.collect::<Vec<_>>().join(", ")))}
|
||||
/>
|
||||
}
|
||||
}).collect::<Html>();
|
||||
html! {
|
||||
<tr>
|
||||
{ row_header }{ row }
|
||||
</tr>
|
||||
}
|
||||
})
|
||||
.collect::<Html>();
|
||||
|
||||
html! {
|
||||
<div ondblclick={screenshot_callback}
|
||||
class={classes!{"dest_plate",
|
||||
"W".to_owned()+&props.source_plate.plate.plate_format.to_string()}}>
|
||||
<table
|
||||
onmouseup={move |e| {
|
||||
mouseup_callback.emit(e);
|
||||
}}
|
||||
onmouseleave={move |e| {
|
||||
mouseleave_callback.emit(e);
|
||||
}}>
|
||||
{ column_header }{ rows }
|
||||
</table>
|
||||
</div>
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub enum MouseEventType {
|
||||
Mousedown,
|
||||
Mouseenter,
|
||||
}
|
||||
|
||||
#[derive(Properties, PartialEq)]
|
||||
pub struct DestPlateCellProps {
|
||||
pub i: u8,
|
||||
pub j: u8,
|
||||
pub selected: bool,
|
||||
pub mouse: Callback<(u8, u8, MouseEventType)>,
|
||||
pub in_transfer: Option<bool>,
|
||||
color: Option<[f64; 3]>,
|
||||
cell_height: f64,
|
||||
title: Option<String>,
|
||||
}
|
||||
|
||||
#[function_component]
|
||||
fn DestPlateCell(props: &DestPlateCellProps) -> Html {
|
||||
let selected_class = match props.selected {
|
||||
true => Some("current_select"),
|
||||
false => None,
|
||||
};
|
||||
let in_transfer_class = match props.in_transfer {
|
||||
Some(true) => Some("in_transfer"),
|
||||
_ => None,
|
||||
};
|
||||
let color = props.color.unwrap_or([255.0, 255.0, 255.0]);
|
||||
let mouse = Callback::clone(&props.mouse);
|
||||
let mouse2 = Callback::clone(&props.mouse);
|
||||
let (i, j) = (props.i, props.j);
|
||||
|
||||
html! {
|
||||
<td class={classes!("plate_cell", selected_class, in_transfer_class)}
|
||||
style={format!("height: {}px;", props.cell_height)}
|
||||
onmousedown={move |_| {
|
||||
mouse.emit((i,j, MouseEventType::Mousedown))
|
||||
}}
|
||||
onmouseenter={move |_| {
|
||||
mouse2.emit((i,j, MouseEventType::Mouseenter))
|
||||
}}>
|
||||
<div class="plate_cell_inner"
|
||||
style={format!("background: rgba({},{},{},1);", color[0], color[1], color[2])}
|
||||
title={if let Some(text) = &props.title {
|
||||
text.clone()
|
||||
} else { "".to_string() }}/>
|
||||
</td>
|
||||
}
|
||||
}
|
|
@ -0,0 +1,4 @@
|
|||
pub mod destination_plate;
|
||||
pub mod plate_container;
|
||||
pub mod source_plate;
|
||||
mod util;
|
|
@ -1,17 +1,12 @@
|
|||
#![allow(non_snake_case)]
|
||||
use plate_tool_lib::util::num_to_letters;
|
||||
use wasm_bindgen::prelude::Closure;
|
||||
use wasm_bindgen::JsCast;
|
||||
use yew::prelude::*;
|
||||
|
||||
use plate_tool_lib::plate::PlateType;
|
||||
use plate_tool_lib::plate_instances::PlateInstance;
|
||||
use yewdux::functional::use_store;
|
||||
use crate::data::plate_instances::PlateInstance;
|
||||
|
||||
// use super::destination_plate::DestinationPlate;
|
||||
// use super::source_plate::SourcePlate;
|
||||
use super::plate::Plate;
|
||||
use crate::components::states::MainState;
|
||||
use super::destination_plate::DestinationPlate;
|
||||
use super::source_plate::SourcePlate;
|
||||
|
||||
#[derive(Properties, PartialEq)]
|
||||
pub struct PlateContainerProps {
|
||||
|
@ -21,8 +16,6 @@ pub struct PlateContainerProps {
|
|||
|
||||
#[function_component]
|
||||
pub fn PlateContainer(props: &PlateContainerProps) -> Html {
|
||||
let (main_state, _) = use_store::<MainState>();
|
||||
|
||||
let cell_height = {
|
||||
let height = web_sys::window()
|
||||
.unwrap()
|
||||
|
@ -54,52 +47,19 @@ pub fn PlateContainer(props: &PlateContainerProps) -> Html {
|
|||
.set_onresize(Some(onresize.as_ref().unchecked_ref()));
|
||||
onresize.forget(); // Magic!
|
||||
|
||||
let heatmap_enabled = main_state.preferences.volume_heatmap;
|
||||
let show_current_coordinates = main_state.preferences.show_current_coordinates;
|
||||
// (Row, Col)
|
||||
let current_coordinates = use_state(|| (0, 0));
|
||||
let send_coordinates = {
|
||||
if show_current_coordinates {
|
||||
let current_coordinates = current_coordinates.clone();
|
||||
Some(Callback::from(move |coords| {
|
||||
current_coordinates.set(coords)
|
||||
}))
|
||||
} else {
|
||||
None
|
||||
}
|
||||
};
|
||||
|
||||
html! {
|
||||
<div class="plate_container">
|
||||
<div class="plate_container--upper-left" >
|
||||
if heatmap_enabled {
|
||||
<div class="plate_container--heatmap-notice" >
|
||||
<h3>{"Volume Heatmap Enabled"}</h3>
|
||||
</div>
|
||||
}
|
||||
if show_current_coordinates {
|
||||
<div class="plate_container--location">
|
||||
<h3>{format!("R:{} C:{}",
|
||||
num_to_letters(current_coordinates.0).unwrap_or("".to_string()),
|
||||
current_coordinates.1)}</h3>
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
if let Some(spi) = props.source_dims.clone() {
|
||||
if let Some(dpi) = props.destination_dims.clone() {
|
||||
<div class="plate_container--source">
|
||||
<h2>{spi.name.clone()}</h2>
|
||||
<h2>{"Source"}</h2>
|
||||
<Plate source_plate={spi.clone()} destination_plate={dpi.clone()}
|
||||
cell_height={cell_height} ptype={PlateType::Source}
|
||||
send_coordinates={send_coordinates.clone()}
|
||||
/>
|
||||
<SourcePlate source_plate={spi.clone()} destination_plate={dpi.clone()}
|
||||
cell_height={cell_height}/>
|
||||
</div>
|
||||
<div class="plate_container--destination">
|
||||
<h2>{dpi.name.clone()}</h2>
|
||||
<h2>{"Destination"}</h2>
|
||||
<Plate source_plate={spi.clone()} destination_plate={dpi.clone()}
|
||||
cell_height={cell_height} ptype={PlateType::Destination} send_coordinates={send_coordinates.clone()}/>
|
||||
<DestinationPlate source_plate={spi.clone()} destination_plate={dpi.clone()}
|
||||
cell_height={cell_height}/>
|
||||
</div>
|
||||
} else {
|
||||
<h2>{"No Destination Plate Selected"}</h2>
|
|
@ -0,0 +1,294 @@
|
|||
#![allow(non_snake_case)]
|
||||
|
||||
use std::collections::HashMap;
|
||||
use yew::prelude::*;
|
||||
use yewdux::prelude::*;
|
||||
|
||||
use crate::components::states::{CurrentTransfer, MainState};
|
||||
use crate::data::plate_instances::PlateInstance;
|
||||
use crate::data::transfer::Transfer;
|
||||
use crate::data::transfer_region::Region;
|
||||
|
||||
// Color Palette for the Source Plates, can be changed here
|
||||
use crate::components::plates::util::Palettes;
|
||||
const PALETTE: super::util::ColorPalette = Palettes::RAINBOW;
|
||||
|
||||
use super::super::transfer_menu::{num_to_letters, RegionDisplay};
|
||||
|
||||
#[derive(PartialEq, Properties)]
|
||||
pub struct SourcePlateProps {
|
||||
pub source_plate: PlateInstance,
|
||||
pub destination_plate: PlateInstance,
|
||||
pub cell_height: f64,
|
||||
}
|
||||
|
||||
#[function_component]
|
||||
pub fn SourcePlate(props: &SourcePlateProps) -> Html {
|
||||
let (main_state, _) = use_store::<MainState>();
|
||||
let (ct_state, ct_dispatch) = use_store::<CurrentTransfer>();
|
||||
let m_start_handle: UseStateHandle<Option<(u8, u8)>> = use_state_eq(|| None);
|
||||
let m_end_handle: UseStateHandle<Option<(u8, u8)>> = use_state_eq(|| None);
|
||||
let m_stat_handle: UseStateHandle<bool> = use_state_eq(|| false);
|
||||
|
||||
if !(*m_stat_handle) {
|
||||
let (pt1, pt2) = match ct_state.transfer.transfer_region.source_region {
|
||||
Region::Point((x, y)) => ((x, y), (x, y)),
|
||||
Region::Rect(c1, c2) => (c1, c2),
|
||||
Region::Custom(_) => ((0,0), (0,0)),
|
||||
};
|
||||
m_start_handle.set(Some(pt1));
|
||||
m_end_handle.set(Some(pt2));
|
||||
}
|
||||
|
||||
let transfer_map = {
|
||||
let ts = main_state
|
||||
.transfers
|
||||
.iter()
|
||||
.filter(|t| t.source_id == props.source_plate.get_uuid());
|
||||
let mut tooltip_map: HashMap<(u8, u8), Vec<&Transfer>> = HashMap::new();
|
||||
for t in ts {
|
||||
let sws = t.transfer_region.get_source_wells();
|
||||
for sw in sws {
|
||||
if let Some(val) = tooltip_map.get_mut(&sw) {
|
||||
val.push(t);
|
||||
} else {
|
||||
tooltip_map.insert(sw, vec![t]);
|
||||
}
|
||||
}
|
||||
}
|
||||
tooltip_map
|
||||
};
|
||||
|
||||
let source_wells = ct_state.transfer.transfer_region.get_source_wells();
|
||||
|
||||
let ordered_ids: Vec<uuid::Uuid> = {
|
||||
let mut ids: Vec<uuid::Uuid> = main_state.transfers.clone().iter()
|
||||
.map(|x| x.id)
|
||||
.collect();
|
||||
ids.sort_unstable();
|
||||
ids
|
||||
};
|
||||
|
||||
let mouse_callback = {
|
||||
let m_start_handle = m_start_handle.clone();
|
||||
let m_end_handle = m_end_handle.clone();
|
||||
let m_stat_handle = m_stat_handle.clone();
|
||||
|
||||
Callback::from(move |(i, j, t)| match t {
|
||||
MouseEventType::Mousedown => {
|
||||
m_start_handle.set(Some((i, j)));
|
||||
m_end_handle.set(Some((i, j)));
|
||||
m_stat_handle.set(true);
|
||||
}
|
||||
MouseEventType::Mouseenter => {
|
||||
if *m_stat_handle {
|
||||
m_end_handle.set(Some((i, j)));
|
||||
}
|
||||
}
|
||||
})
|
||||
};
|
||||
|
||||
let mouseup_callback = {
|
||||
let m_start_handle = m_start_handle.clone();
|
||||
let m_end_handle = m_end_handle.clone();
|
||||
|
||||
Callback::from(move |_: MouseEvent| {
|
||||
m_stat_handle.set(false);
|
||||
if let Some(ul) = *m_start_handle {
|
||||
if let Some(br) = *m_end_handle {
|
||||
if let Ok(rd) = RegionDisplay::try_from((ul.0, ul.1, br.0, br.1)) {
|
||||
ct_dispatch.reduce_mut(|state| {
|
||||
state.transfer.transfer_region.source_region = Region::from(&rd);
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
};
|
||||
|
||||
let mouseleave_callback = Callback::clone(&mouseup_callback);
|
||||
|
||||
let screenshot_callback = Callback::from(|_| {
|
||||
let _ = js_sys::eval("copy_screenshot_src()");
|
||||
});
|
||||
|
||||
let column_header = {
|
||||
let headers = (1..=props.source_plate.plate.size().1)
|
||||
.map(|j| {
|
||||
html! {<th>
|
||||
{format!("{:0>2}", j)}
|
||||
</th>}
|
||||
})
|
||||
.collect::<Html>();
|
||||
html! {<tr><th />{ headers }</tr>}
|
||||
};
|
||||
let rows = (1..=props.source_plate.plate.size().0)
|
||||
.map(|i| {
|
||||
let row_header = html! {<th>{num_to_letters(i)}</th>};
|
||||
let row = (1..=props.source_plate.plate.size().1)
|
||||
.map(|j| {
|
||||
html! {
|
||||
<SourcePlateCell i={i} j={j}
|
||||
selected={in_rect(*m_start_handle.clone(), *m_end_handle.clone(), (i,j))}
|
||||
mouse={mouse_callback.clone()}
|
||||
in_transfer={source_wells.contains(&(i,j)) && main_state.preferences.in_transfer_hashes}
|
||||
color={transfer_map.get(&(i,j))
|
||||
.and_then(|t| t.last())
|
||||
.map(|t| PALETTE.get_ordered(t.get_uuid(), &ordered_ids))
|
||||
}
|
||||
cell_height={props.cell_height}
|
||||
title={transfer_map.get(&(i,j)).map(|transfers| format!("Used by: {}", transfers.iter().map(|t| t.name.clone())
|
||||
.collect::<Vec<_>>().join(", ")))}
|
||||
/>
|
||||
}
|
||||
})
|
||||
.collect::<Html>();
|
||||
html! {
|
||||
<tr>
|
||||
{ row_header }{ row }
|
||||
</tr>
|
||||
}
|
||||
})
|
||||
.collect::<Html>();
|
||||
|
||||
html! {
|
||||
<div ondblclick={screenshot_callback}
|
||||
class={classes!{"source_plate",
|
||||
"W".to_owned()+&props.source_plate.plate.plate_format.to_string()}}>
|
||||
<table
|
||||
onmouseup={move |e| {
|
||||
mouseup_callback.emit(e);
|
||||
}}
|
||||
onmouseleave={move |e| {
|
||||
mouseleave_callback.emit(e);
|
||||
}}>
|
||||
{ column_header }
|
||||
{ rows }
|
||||
</table>
|
||||
</div>
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(PartialEq, Properties)]
|
||||
pub struct SourcePlateCellProps {
|
||||
i: u8,
|
||||
j: u8,
|
||||
selected: bool,
|
||||
mouse: Callback<(u8, u8, MouseEventType)>,
|
||||
in_transfer: Option<bool>,
|
||||
color: Option<[f64; 3]>,
|
||||
cell_height: f64,
|
||||
title: Option<String>,
|
||||
}
|
||||
#[derive(Debug)]
|
||||
pub enum MouseEventType {
|
||||
Mousedown,
|
||||
Mouseenter,
|
||||
}
|
||||
|
||||
#[function_component]
|
||||
fn SourcePlateCell(props: &SourcePlateCellProps) -> Html {
|
||||
let selected_class = match props.selected {
|
||||
true => Some("current_select"),
|
||||
false => None,
|
||||
};
|
||||
let in_transfer_class = match props.in_transfer {
|
||||
Some(true) => Some("in_transfer"),
|
||||
_ => None,
|
||||
};
|
||||
let color = props.color.unwrap_or([255.0, 255.0, 255.0]);
|
||||
let mouse = Callback::clone(&props.mouse);
|
||||
let mouse2 = Callback::clone(&props.mouse);
|
||||
let (i, j) = (props.i, props.j);
|
||||
|
||||
html! {
|
||||
<td class={classes!("plate_cell", selected_class, in_transfer_class)}
|
||||
style={format!("height: {}px;", props.cell_height)}
|
||||
id={format!("color={:?}", props.color)}
|
||||
onmousedown={move |_| {
|
||||
mouse.emit((i,j, MouseEventType::Mousedown))
|
||||
}}
|
||||
onmouseenter={move |_| {
|
||||
mouse2.emit((i,j, MouseEventType::Mouseenter))
|
||||
}}>
|
||||
<div class="plate_cell_inner"
|
||||
style={format!("background: rgba({},{},{},1);", color[0], color[1], color[2])}
|
||||
title={if let Some(text) = &props.title {
|
||||
text.clone()
|
||||
} else {"".to_string()}}/>
|
||||
</td>
|
||||
}
|
||||
}
|
||||
|
||||
pub fn in_rect(corner1: Option<(u8, u8)>, corner2: Option<(u8, u8)>, pt: (u8, u8)) -> bool {
|
||||
if let (Some(c1), Some(c2)) = (corner1, corner2) {
|
||||
pt.0 <= u8::max(c1.0, c2.0)
|
||||
&& pt.0 >= u8::min(c1.0, c2.0)
|
||||
&& pt.1 <= u8::max(c1.1, c2.1)
|
||||
&& pt.1 >= u8::min(c1.1, c2.1)
|
||||
} else {
|
||||
false
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use wasm_bindgen_test::*;
|
||||
|
||||
use super::in_rect;
|
||||
|
||||
// in_rect tests
|
||||
#[test]
|
||||
#[wasm_bindgen_test]
|
||||
fn test_in_rect1() {
|
||||
// Test in center of rect
|
||||
let c1 = (1, 1);
|
||||
let c2 = (10, 10);
|
||||
let pt = (5, 5);
|
||||
assert!(in_rect(Some(c1), Some(c2), pt));
|
||||
// Order of the corners should not matter:
|
||||
assert!(in_rect(Some(c2), Some(c1), pt));
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[wasm_bindgen_test]
|
||||
fn test_in_rect2() {
|
||||
// Test on top/bottom edges of rect
|
||||
let c1 = (1, 1);
|
||||
let c2 = (10, 10);
|
||||
let pt1 = (1, 5);
|
||||
let pt2 = (10, 5);
|
||||
assert!(in_rect(Some(c1), Some(c2), pt1));
|
||||
assert!(in_rect(Some(c1), Some(c2), pt2));
|
||||
// Order of the corners should not matter:
|
||||
assert!(in_rect(Some(c2), Some(c1), pt1));
|
||||
assert!(in_rect(Some(c2), Some(c1), pt2));
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[wasm_bindgen_test]
|
||||
fn test_in_rect3() {
|
||||
// Test on left/right edges of rect
|
||||
let c1 = (1, 1);
|
||||
let c2 = (10, 10);
|
||||
let pt1 = (5, 1);
|
||||
let pt2 = (5, 10);
|
||||
assert!(in_rect(Some(c1), Some(c2), pt1));
|
||||
assert!(in_rect(Some(c1), Some(c2), pt2));
|
||||
// Order of the corners should not matter:
|
||||
assert!(in_rect(Some(c2), Some(c1), pt1));
|
||||
assert!(in_rect(Some(c2), Some(c1), pt2));
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[wasm_bindgen_test]
|
||||
fn test_in_rect4() {
|
||||
// Test cases that should fail
|
||||
let c1 = (1, 1);
|
||||
let c2 = (10, 10);
|
||||
let pt1 = (0, 0);
|
||||
let pt2 = (15, 15);
|
||||
assert!(!in_rect(Some(c1), Some(c2), pt1));
|
||||
assert!(!in_rect(Some(c1), Some(c2), pt2));
|
||||
}
|
||||
}
|
|
@ -2,6 +2,10 @@
|
|||
// https://iquilezles.org/articles/palettes/
|
||||
// http://dev.thi.ng/gradients/
|
||||
|
||||
use rand::prelude::*;
|
||||
use rand::rngs::SmallRng;
|
||||
use lazy_static::lazy_static;
|
||||
|
||||
#[derive(Clone, Copy, PartialEq, Debug)]
|
||||
pub struct ColorPalette {
|
||||
a: [f64; 3],
|
||||
|
@ -26,8 +30,7 @@ impl ColorPalette {
|
|||
]
|
||||
}
|
||||
|
||||
#[allow(dead_code)] // Preserve old implementation for reference
|
||||
fn get_u8(&self, t: u8) -> [f64; 3] {
|
||||
pub fn _get_u8(&self, t: u8) -> [f64; 3] {
|
||||
assert!(t > 0, "t must be greater than zero!");
|
||||
self.get((2f64.powi(-(t.ilog2() as i32))) * (t as f64 + 0.5f64) - 1.0f64)
|
||||
}
|
||||
|
@ -38,22 +41,17 @@ impl ColorPalette {
|
|||
// self.get(r.gen_range(0.0..1.0f64))
|
||||
// }
|
||||
|
||||
pub fn get_ordered(&self, t: uuid::Uuid, ordered_uuids: &[uuid::Uuid])
|
||||
pub fn get_ordered(&self, t: uuid::Uuid, ordered_uuids: &Vec<uuid::Uuid>)
|
||||
-> [f64; 3] {
|
||||
let index = ordered_uuids.iter().position(|&x| x == t).expect("uuid must be in list of uuids") + 1;
|
||||
self.get(Self::space_evenly(index))
|
||||
}
|
||||
|
||||
pub fn get_linear(&self, t: f64, max: f64) -> [f64; 3] {
|
||||
let scaled = t / max;
|
||||
self.get(scaled)
|
||||
return self.get(Self::space_evenly(index))
|
||||
}
|
||||
|
||||
fn space_evenly(x: usize) -> f64 {
|
||||
let e: usize = (x.ilog2() + 1) as usize;
|
||||
let d: usize = 2usize.pow(e as u32);
|
||||
let d: usize = (2usize.pow(e as u32)) as usize;
|
||||
let n: usize = (2*x + 1) % d;
|
||||
(n as f64) / (d as f64)
|
||||
return (n as f64) / (d as f64);
|
||||
}
|
||||
}
|
||||
|
|
@ -2,9 +2,9 @@ use serde::{Deserialize, Serialize};
|
|||
use uuid::Uuid;
|
||||
use yewdux::{prelude::*, storage};
|
||||
|
||||
use plate_tool_lib::plate::*;
|
||||
use plate_tool_lib::plate_instances::PlateInstance;
|
||||
use plate_tool_lib::transfer::Transfer;
|
||||
use crate::data::plate::*;
|
||||
use crate::data::plate_instances::PlateInstance;
|
||||
use crate::data::transfer::Transfer;
|
||||
|
||||
#[derive(Debug, Default, Clone, PartialEq, Serialize, Deserialize, Store)]
|
||||
#[store(storage = "session")]
|
||||
|
@ -15,51 +15,12 @@ pub struct CurrentTransfer {
|
|||
|
||||
#[derive(PartialEq, Clone, Copy, Serialize, Deserialize)]
|
||||
pub struct Preferences {
|
||||
#[serde(default)]
|
||||
pub in_transfer_hashes: bool,
|
||||
#[serde(default)]
|
||||
pub volume_heatmap: bool,
|
||||
#[serde(default)]
|
||||
pub csv_export_type: CsvExportType,
|
||||
#[serde(default)]
|
||||
pub show_current_coordinates: bool,
|
||||
}
|
||||
|
||||
impl Default for Preferences {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
in_transfer_hashes: true,
|
||||
volume_heatmap: false,
|
||||
csv_export_type: CsvExportType::Normal,
|
||||
show_current_coordinates: false,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(PartialEq, Clone, Copy, Serialize, Deserialize, Default)]
|
||||
pub enum CsvExportType {
|
||||
#[default]
|
||||
Normal,
|
||||
|
||||
EchoClient,
|
||||
}
|
||||
|
||||
impl std::fmt::Display for CsvExportType {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
match self {
|
||||
CsvExportType::Normal => write!(f, "Normal"),
|
||||
CsvExportType::EchoClient => write!(f, "Echo Client"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<&str> for CsvExportType {
|
||||
fn from(value: &str) -> Self {
|
||||
match value.trim().to_lowercase().as_str() {
|
||||
"normal" => CsvExportType::Normal,
|
||||
"echo client" => CsvExportType::EchoClient,
|
||||
_ => CsvExportType::default(),
|
||||
}
|
||||
Self { in_transfer_hashes: true }
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -78,11 +39,8 @@ pub struct MainState {
|
|||
}
|
||||
|
||||
impl Store for MainState {
|
||||
fn new(context: &yewdux::Context) -> Self {
|
||||
init_listener(
|
||||
storage::StorageListener::<Self>::new(storage::Area::Local),
|
||||
context,
|
||||
);
|
||||
fn new() -> Self {
|
||||
init_listener(storage::StorageListener::<Self>::new(storage::Area::Local));
|
||||
|
||||
storage::load(storage::Area::Local)
|
||||
.expect("Unable to load state")
|
||||
|
@ -150,21 +108,4 @@ impl MainState {
|
|||
self.destination_plates[index].change_name(new_name.to_string());
|
||||
}
|
||||
}
|
||||
|
||||
pub fn change_format(&mut self, id: Uuid, new_format: &PlateFormat) {
|
||||
if let Some(index) = self
|
||||
.source_plates
|
||||
.iter()
|
||||
.position(|spi| spi.get_uuid() == id)
|
||||
{
|
||||
self.source_plates[index].change_format(new_format);
|
||||
}
|
||||
if let Some(index) = self
|
||||
.destination_plates
|
||||
.iter()
|
||||
.position(|dpi| dpi.get_uuid() == id)
|
||||
{
|
||||
self.destination_plates[index].change_format(new_format);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,16 +1,13 @@
|
|||
#![allow(non_snake_case)]
|
||||
|
||||
use lazy_static::lazy_static;
|
||||
use plate_tool_lib::Well;
|
||||
use regex::Regex;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use yew::prelude::*;
|
||||
use yewdux::prelude::*;
|
||||
|
||||
use crate::components::callbacks::transfer_menu_callbacks;
|
||||
use plate_tool_lib::transfer_region::Region;
|
||||
use plate_tool_lib::transfer_volume::TransferVolume;
|
||||
use plate_tool_lib::util::{letters_to_num, num_to_letters};
|
||||
use crate::data::transfer_region::Region;
|
||||
|
||||
use super::states::{CurrentTransfer, MainState};
|
||||
|
||||
|
@ -145,10 +142,7 @@ pub fn TransferMenu() -> Html {
|
|||
<input type="number" name="volume" class="volume_input"
|
||||
min="0" step="0.1"
|
||||
onchange={on_volume_change}
|
||||
value={match ct_state.transfer.volume {
|
||||
TransferVolume::Single(x) => x.to_string(),
|
||||
_ => unreachable!(),
|
||||
}}/>
|
||||
value={ct_state.transfer.volume.to_string()}/>
|
||||
</div>
|
||||
}
|
||||
<div id="controls">
|
||||
|
@ -211,7 +205,7 @@ impl TryFrom<&str> for RegionDisplay {
|
|||
lazy_static! {
|
||||
static ref REGION_REGEX: Regex = Regex::new(r"([A-Z]+)(\d+):([A-Z]+)(\d+)").unwrap();
|
||||
}
|
||||
if let Some(captures) = REGION_REGEX.captures(value) {
|
||||
if let Some(captures) = REGION_REGEX.captures(&value) {
|
||||
if captures.len() != 5 {
|
||||
return Err("Not enough capture groups");
|
||||
}
|
||||
|
@ -238,10 +232,10 @@ impl TryFrom<&str> for RegionDisplay {
|
|||
impl From<&Region> for RegionDisplay {
|
||||
fn from(value: &Region) -> Self {
|
||||
match *value {
|
||||
Region::Point(Well { row, col }) => {
|
||||
Region::Point((col, row)) => {
|
||||
RegionDisplay::try_from((col, row, col, row)).ok().unwrap()
|
||||
}
|
||||
Region::Rect(c1, c2) => RegionDisplay::try_from((c1.row, c1.col, c2.row, c2.col))
|
||||
Region::Rect(c1, c2) => RegionDisplay::try_from((c1.0, c1.1, c2.0, c2.1))
|
||||
.ok()
|
||||
.unwrap(),
|
||||
Region::Custom(_) => RegionDisplay {
|
||||
|
@ -257,11 +251,11 @@ impl From<&Region> for RegionDisplay {
|
|||
impl From<&RegionDisplay> for Region {
|
||||
fn from(value: &RegionDisplay) -> Self {
|
||||
if value.col_start == value.col_end && value.row_start == value.row_end {
|
||||
Region::Point(Well { row: value.row_start, col: value.col_start })
|
||||
Region::Point((value.col_start, value.row_start))
|
||||
} else {
|
||||
Region::Rect(
|
||||
Well { row: value.row_start, col: value.col_start },
|
||||
Well { row: value.row_end, col: value.col_end },
|
||||
(value.col_start, value.row_start),
|
||||
(value.col_end, value.row_end),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
@ -283,12 +277,79 @@ impl TryFrom<(u8, u8, u8, u8)> for RegionDisplay {
|
|||
})
|
||||
}
|
||||
}
|
||||
pub fn letters_to_num(letters: &str) -> Option<u8> {
|
||||
let mut num: u8 = 0;
|
||||
for (i, letter) in letters.to_ascii_uppercase().chars().rev().enumerate() {
|
||||
log::debug!("{}, {}", i, letter);
|
||||
let n = letter as u8;
|
||||
if !(65..=90).contains(&n) {
|
||||
return None;
|
||||
}
|
||||
num = num.checked_add((26_i32.pow(i as u32) * (n as i32 - 64)).try_into().ok()?)?;
|
||||
}
|
||||
Some(num)
|
||||
}
|
||||
pub fn num_to_letters(num: u8) -> Option<String> {
|
||||
if num == 0 {
|
||||
return None;
|
||||
} // Otherwise, we will not return none!
|
||||
// As another note, we can't represent higher than "IV" anyway;
|
||||
// thus there's no reason for a loop (26^n with n>1 will NOT occur).
|
||||
let mut text = "".to_string();
|
||||
let mut digit1 = num.div_euclid(26u8);
|
||||
let mut digit2 = num.rem_euclid(26u8);
|
||||
if digit1 > 0 && digit2 == 0u8 {
|
||||
digit1 -= 1;
|
||||
digit2 = 26;
|
||||
}
|
||||
if digit1 != 0 {
|
||||
text.push((64 + digit1) as char)
|
||||
}
|
||||
text.push((64 + digit2) as char);
|
||||
|
||||
Some(text.to_string())
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use wasm_bindgen_test::*;
|
||||
|
||||
use super::*;
|
||||
use super::{letters_to_num, num_to_letters, RegionDisplay};
|
||||
|
||||
#[test]
|
||||
#[wasm_bindgen_test]
|
||||
fn test_letters_to_num() {
|
||||
assert_eq!(letters_to_num("D"), Some(4));
|
||||
assert_eq!(letters_to_num("d"), None);
|
||||
assert_eq!(letters_to_num("AD"), Some(26 + 4));
|
||||
assert_eq!(letters_to_num("CG"), Some(3 * 26 + 7));
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[wasm_bindgen_test]
|
||||
fn test_num_to_letters() {
|
||||
println!("27 is {:?}", num_to_letters(27));
|
||||
assert_eq!(num_to_letters(1), Some("A".to_string()));
|
||||
assert_eq!(num_to_letters(26), Some("Z".to_string()));
|
||||
assert_eq!(num_to_letters(27), Some("AA".to_string()));
|
||||
assert_eq!(num_to_letters(111), Some("DG".to_string()));
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[wasm_bindgen_test]
|
||||
fn test_l2n_and_n2l() {
|
||||
assert_eq!(
|
||||
num_to_letters(letters_to_num("A").unwrap()),
|
||||
Some("A".to_string())
|
||||
);
|
||||
assert_eq!(
|
||||
num_to_letters(letters_to_num("BJ").unwrap()),
|
||||
Some("BJ".to_string())
|
||||
);
|
||||
for i in 1..=255 {
|
||||
assert_eq!(letters_to_num(&num_to_letters(i).unwrap()), Some(i));
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[wasm_bindgen_test]
|
|
@ -1,19 +1,17 @@
|
|||
#![allow(non_snake_case)]
|
||||
|
||||
use plate_tool_lib::plate::PlateFormat;
|
||||
use uuid::Uuid;
|
||||
|
||||
use web_sys::{HtmlDialogElement};
|
||||
use wasm_bindgen::JsCast;
|
||||
use web_sys::{HtmlDialogElement, HtmlInputElement};
|
||||
use yew::prelude::*;
|
||||
use yewdux::prelude::*;
|
||||
|
||||
use crate::components::callbacks::{tree_callbacks};
|
||||
use crate::components::new_plate_dialog::NewPlateDialogType;
|
||||
use crate::components::states::{CurrentTransfer, MainState};
|
||||
use crate::components::callbacks::tree_callbacks;
|
||||
|
||||
#[derive(PartialEq, Properties)]
|
||||
pub struct TreeProps {
|
||||
pub open_new_plate_callback: Callback<NewPlateDialogType>,
|
||||
pub open_new_plate_callback: Callback<()>,
|
||||
}
|
||||
|
||||
#[function_component]
|
||||
|
@ -99,25 +97,13 @@ pub fn Tree(props: &TreeProps) -> Html {
|
|||
html! {
|
||||
<div class="tree">
|
||||
<div id="source-plates">
|
||||
<div class="tree--header">
|
||||
<h3>{"Source Plates:"}</h3>
|
||||
<button onclick={
|
||||
let open_new_plate_callback = props.open_new_plate_callback.clone();
|
||||
move |_| {open_new_plate_callback.emit(NewPlateDialogType::SourceOnly)}
|
||||
} />
|
||||
</div>
|
||||
<ul>
|
||||
{source_plates}
|
||||
</ul>
|
||||
</div>
|
||||
<div id="destination-plates">
|
||||
<div class="tree--header">
|
||||
<h3>{"Destination Plates:"}</h3>
|
||||
<button onclick={
|
||||
let open_new_plate_callback = props.open_new_plate_callback.clone();
|
||||
move |_| {open_new_plate_callback.emit(NewPlateDialogType::DestinationOnly)}
|
||||
} />
|
||||
</div>
|
||||
<ul>
|
||||
{dest_plates}
|
||||
</ul>
|
||||
|
@ -133,6 +119,14 @@ pub fn Tree(props: &TreeProps) -> Html {
|
|||
delete_button_callback={plate_info_delete_callback}/>
|
||||
}
|
||||
|
||||
<div id="controls">
|
||||
<button type="button"
|
||||
onclick={
|
||||
let open_new_plate_callback = props.open_new_plate_callback.clone();
|
||||
move |_| {open_new_plate_callback.emit(())}
|
||||
}>
|
||||
{"New Plate"}</button>
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
}
|
||||
|
@ -163,36 +157,24 @@ fn PlateInfoModal(props: &PlateInfoModalProps) -> Html {
|
|||
Some(plate) => plate.name.clone(),
|
||||
None => "Not Found".to_string(),
|
||||
};
|
||||
let plate_format = plate.map(|p| p.plate.plate_format);
|
||||
let plate_formats = [PlateFormat::W6,
|
||||
PlateFormat::W12,
|
||||
PlateFormat::W24,
|
||||
PlateFormat::W48,
|
||||
PlateFormat::W96,
|
||||
PlateFormat::W384,
|
||||
PlateFormat::W1536,
|
||||
PlateFormat::W3456];
|
||||
let plate_format_options = plate_formats.iter().map(|v| {
|
||||
let selected = Some(v) == plate_format.as_ref();
|
||||
html! {
|
||||
<option value={v.to_string()} selected={selected}>{ v.to_string() }</option>
|
||||
}
|
||||
});
|
||||
|
||||
let onclose = {
|
||||
let dialog_close_callback = props.dialog_close_callback.clone();
|
||||
move |_| dialog_close_callback.emit(())
|
||||
};
|
||||
|
||||
let onclose_secondary = {
|
||||
let dialog_close_callback = props.dialog_close_callback.clone();
|
||||
move |_| dialog_close_callback.emit(())
|
||||
let rename_onchange = {
|
||||
let id = props.id;
|
||||
Callback::from(move |e: Event| {
|
||||
log::debug!("Changed name");
|
||||
let input = e
|
||||
.target()
|
||||
.expect("Event must have target")
|
||||
.dyn_into::<HtmlInputElement>()
|
||||
.unwrap();
|
||||
main_dispatch.reduce_mut(|state| state.rename_plate(id, &input.value()))
|
||||
})
|
||||
};
|
||||
|
||||
let rename_onchange = tree_callbacks::rename_onchange(props.id, main_dispatch.clone());
|
||||
|
||||
let format_onchange = tree_callbacks::format_onchange(props.id, main_dispatch.clone());
|
||||
|
||||
let delete_onclick = {
|
||||
let delete_button_callback = props.delete_button_callback.clone();
|
||||
let dialog_ref = dialog_ref.clone();
|
||||
|
@ -205,8 +187,7 @@ fn PlateInfoModal(props: &PlateInfoModalProps) -> Html {
|
|||
{
|
||||
let dialog_ref = dialog_ref.clone();
|
||||
|
||||
use_effect_with(
|
||||
dialog_ref,
|
||||
use_effect_with_deps(
|
||||
|dialog_ref| {
|
||||
dialog_ref
|
||||
.cast::<HtmlDialogElement>()
|
||||
|
@ -214,25 +195,15 @@ fn PlateInfoModal(props: &PlateInfoModalProps) -> Html {
|
|||
.show_modal()
|
||||
.ok();
|
||||
},
|
||||
dialog_ref,
|
||||
);
|
||||
}
|
||||
|
||||
let merge_button_callback = {
|
||||
let main_dispatch = main_dispatch.clone();
|
||||
tree_callbacks::merge_button_callback(main_dispatch, props.id)
|
||||
};
|
||||
|
||||
html! {
|
||||
<dialog ref={dialog_ref} class="dialog" onclose={onclose}>
|
||||
<h2>{"Plate Info"}</h2>
|
||||
<h3>{"Name: "}<input type="text" value={plate_name} onchange={rename_onchange}/></h3>
|
||||
<button onclick={delete_onclick}>{"Delete"}</button>
|
||||
if let Some(_) = plate_format {
|
||||
<select name="modal_plate_format" onchange={format_onchange}>
|
||||
{ for plate_format_options }
|
||||
</select>
|
||||
}
|
||||
<button onclick={merge_button_callback} onclick={onclose_secondary}>{"Merge"}</button>
|
||||
<form class="modal_close" method="dialog"><button /></form>
|
||||
</dialog>
|
||||
}
|
|
@ -0,0 +1,81 @@
|
|||
use crate::components::states::MainState;
|
||||
use crate::components::transfer_menu::num_to_letters;
|
||||
use crate::data::transfer::Transfer;
|
||||
|
||||
use serde::{Serialize, Deserialize};
|
||||
use std::error::Error;
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug)]
|
||||
pub struct TransferRecord {
|
||||
#[serde(rename = "Source Plate")]
|
||||
pub source_plate: String,
|
||||
#[serde(rename = "Source Well")]
|
||||
pub source_well: String,
|
||||
#[serde(rename = "Dest Plate")]
|
||||
pub destination_plate: String,
|
||||
#[serde(rename = "Destination Well")]
|
||||
pub destination_well: String,
|
||||
#[serde(rename = "Transfer Volume")]
|
||||
pub volume: f32,
|
||||
#[serde(rename = "Concentration")]
|
||||
pub concentration: Option<f32>,
|
||||
}
|
||||
|
||||
pub fn state_to_csv(state: &MainState) -> Result<String, Box<dyn Error>> {
|
||||
let mut records: Vec<TransferRecord> = Vec::new();
|
||||
for transfer in &state.transfers {
|
||||
let src_barcode = state
|
||||
.source_plates
|
||||
.iter()
|
||||
.find(|spi| spi.get_uuid() == transfer.source_id)
|
||||
.ok_or("Found unpurged transfer")?;
|
||||
let dest_barcode = state
|
||||
.destination_plates
|
||||
.iter()
|
||||
.find(|dpi| dpi.get_uuid() == transfer.dest_id)
|
||||
.ok_or("Found unpurged transfer")?;
|
||||
records.append(&mut transfer_to_records(
|
||||
transfer,
|
||||
&src_barcode.name,
|
||||
&dest_barcode.name,
|
||||
))
|
||||
}
|
||||
return records_to_csv(records);
|
||||
}
|
||||
|
||||
fn transfer_to_records(
|
||||
tr: &Transfer,
|
||||
src_barcode: &str,
|
||||
dest_barcode: &str,
|
||||
) -> Vec<TransferRecord> {
|
||||
let source_wells = tr.transfer_region.get_source_wells();
|
||||
let map = tr.transfer_region.calculate_map();
|
||||
|
||||
let mut records: Vec<TransferRecord> = vec![];
|
||||
|
||||
for s_well in source_wells {
|
||||
let dest_wells = map(s_well);
|
||||
if let Some(dest_wells) = dest_wells {
|
||||
for d_well in dest_wells {
|
||||
records.push(TransferRecord {
|
||||
source_plate: src_barcode.to_string(),
|
||||
source_well: format!("{}{}", num_to_letters(s_well.0).unwrap(), s_well.1),
|
||||
destination_plate: dest_barcode.to_string(),
|
||||
destination_well: format!("{}{}", num_to_letters(d_well.0).unwrap(), d_well.1),
|
||||
volume: tr.volume,
|
||||
concentration: None,
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
records
|
||||
}
|
||||
|
||||
fn records_to_csv(trs: Vec<TransferRecord>) -> Result<String, Box<dyn Error>> {
|
||||
let mut wtr = csv::WriterBuilder::new().from_writer(vec![]);
|
||||
for record in trs {
|
||||
wtr.serialize(record)?
|
||||
}
|
||||
let data = String::from_utf8(wtr.into_inner()?)?;
|
||||
Ok(data)
|
||||
}
|
|
@ -3,8 +3,3 @@ pub mod plate;
|
|||
pub mod plate_instances;
|
||||
pub mod transfer;
|
||||
pub mod transfer_region;
|
||||
pub mod transfer_volume;
|
||||
pub mod util;
|
||||
|
||||
mod well;
|
||||
pub use well::Well;
|
|
@ -60,37 +60,6 @@ impl std::fmt::Display for PlateFormat {
|
|||
}
|
||||
}
|
||||
}
|
||||
impl TryFrom<&str> for PlateFormat {
|
||||
type Error = ();
|
||||
fn try_from(value: &str) -> Result<Self, Self::Error> {
|
||||
let lower = value.to_lowercase();
|
||||
match lower.trim() {
|
||||
"w6" | "6" => Ok(PlateFormat::W6),
|
||||
"w12" | "12" => Ok(PlateFormat::W12),
|
||||
"w24" | "24" => Ok(PlateFormat::W24),
|
||||
"w48" | "48" => Ok(PlateFormat::W48),
|
||||
"w96" | "96" => Ok(PlateFormat::W96),
|
||||
"w384" | "384" => Ok(PlateFormat::W384),
|
||||
"w1536" | "1536" => Ok(PlateFormat::W1536),
|
||||
"w3456" | "3456" => Ok(PlateFormat::W3456),
|
||||
_ => Err(())
|
||||
}
|
||||
}
|
||||
}
|
||||
impl From<&PlateFormat> for u16 {
|
||||
fn from(value: &PlateFormat) -> Self {
|
||||
match value {
|
||||
PlateFormat::W6 => 6,
|
||||
PlateFormat::W12 => 12,
|
||||
PlateFormat::W24 => 24,
|
||||
PlateFormat::W48 => 48,
|
||||
PlateFormat::W96 => 96,
|
||||
PlateFormat::W384 => 384,
|
||||
PlateFormat::W1536 => 1536,
|
||||
PlateFormat::W3456 => 3456,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl PlateFormat {
|
||||
pub fn size(&self) -> (u8, u8) {
|
|
@ -2,7 +2,7 @@ use super::plate::*;
|
|||
use serde::{Deserialize, Serialize};
|
||||
use uuid::Uuid;
|
||||
|
||||
#[derive(PartialEq, Clone, Serialize, Deserialize, Debug)]
|
||||
#[derive(PartialEq, Clone, Serialize, Deserialize)]
|
||||
pub struct PlateInstance {
|
||||
pub plate: Plate,
|
||||
#[serde(rename = "id_v7")]
|
||||
|
@ -30,10 +30,6 @@ impl PlateInstance {
|
|||
pub fn change_name(&mut self, new_name: String) {
|
||||
self.name = new_name;
|
||||
}
|
||||
|
||||
pub fn change_format(&mut self, new_format: &PlateFormat) {
|
||||
self.plate.plate_format = *new_format;
|
||||
}
|
||||
}
|
||||
|
||||
impl From<Plate> for PlateInstance {
|
||||
|
@ -45,10 +41,3 @@ impl From<Plate> for PlateInstance {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<&PlateInstance> for String {
|
||||
fn from(value: &PlateInstance) -> Self {
|
||||
// Could have other formatting here
|
||||
format!("{}, {}", value.name, value.plate.plate_format)
|
||||
}
|
||||
}
|
|
@ -1,8 +1,5 @@
|
|||
use crate::transfer_volume;
|
||||
|
||||
use super::plate_instances::*;
|
||||
use super::transfer_region::*;
|
||||
use super::transfer_volume::*;
|
||||
use serde::Deserialize;
|
||||
use serde::Serialize;
|
||||
use uuid::Uuid;
|
||||
|
@ -17,7 +14,8 @@ pub struct Transfer {
|
|||
#[serde(default = "Uuid::now_v7")]
|
||||
pub id: Uuid,
|
||||
pub transfer_region: TransferRegion,
|
||||
pub volume: TransferVolume,
|
||||
#[serde(default = "default_volume")]
|
||||
pub volume: f32,
|
||||
}
|
||||
|
||||
impl Default for Transfer {
|
||||
|
@ -28,11 +26,15 @@ impl Default for Transfer {
|
|||
name: "New Transfer".to_string(),
|
||||
id: Default::default(),
|
||||
transfer_region: Default::default(),
|
||||
volume: Default::default(),
|
||||
volume: 2.5f32,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn default_volume() -> f32 {
|
||||
2.5f32
|
||||
}
|
||||
|
||||
impl Transfer {
|
||||
pub fn new(
|
||||
source: PlateInstance,
|
||||
|
@ -46,7 +48,7 @@ impl Transfer {
|
|||
name,
|
||||
id: Uuid::now_v7(),
|
||||
transfer_region: tr,
|
||||
volume: transfer_volume::TransferVolume::Single(2.5),
|
||||
volume: 2.5,
|
||||
}
|
||||
}
|
||||
|
|
@ -1,32 +1,27 @@
|
|||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use crate::components::transfer_menu::RegionDisplay;
|
||||
|
||||
use super::plate::Plate;
|
||||
use crate::Well;
|
||||
|
||||
#[derive(Clone, PartialEq, Eq, Serialize, Deserialize, Debug)]
|
||||
pub struct CustomRegion {
|
||||
src: Vec<Well>,
|
||||
dest: Vec<Well>,
|
||||
}
|
||||
|
||||
impl CustomRegion {
|
||||
pub fn new(src: Vec<Well>, dest: Vec<Well>) -> Self {
|
||||
CustomRegion { src, dest }
|
||||
}
|
||||
src: Vec<(u8, u8)>,
|
||||
dest: Vec<(u8, u8)>,
|
||||
}
|
||||
|
||||
#[derive(Clone, PartialEq, Eq, Serialize, Deserialize, Debug)]
|
||||
pub enum Region {
|
||||
Rect(Well, Well),
|
||||
Point(Well),
|
||||
Rect((u8, u8), (u8, u8)),
|
||||
Point((u8, u8)),
|
||||
Custom(CustomRegion),
|
||||
}
|
||||
impl Default for Region {
|
||||
fn default() -> Self {
|
||||
Region::Point(Well { row: 1, col: 1 })
|
||||
Region::Point((1, 1))
|
||||
}
|
||||
}
|
||||
impl TryFrom<Region> for (Well, Well) {
|
||||
impl TryFrom<Region> for ((u8, u8), (u8, u8)) {
|
||||
type Error = &'static str;
|
||||
fn try_from(region: Region) -> Result<Self, Self::Error> {
|
||||
if let Region::Rect(c1, c2) = region {
|
||||
|
@ -37,11 +32,10 @@ impl TryFrom<Region> for (Well, Well) {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Region {
|
||||
pub fn new_custom(transfers: &Vec<(Well, Well)>) -> Self {
|
||||
let mut src_pts: Vec<Well> = Vec::with_capacity(transfers.len());
|
||||
let mut dest_pts: Vec<Well> = Vec::with_capacity(transfers.len());
|
||||
pub fn new_custom(transfers: &Vec<((u8, u8), (u8, u8))>) -> Self {
|
||||
let mut src_pts: Vec<(u8, u8)> = Vec::with_capacity(transfers.len());
|
||||
let mut dest_pts: Vec<(u8, u8)> = Vec::with_capacity(transfers.len());
|
||||
|
||||
for transfer in transfers {
|
||||
src_pts.push(transfer.0);
|
||||
|
@ -79,11 +73,11 @@ impl Default for TransferRegion {
|
|||
}
|
||||
|
||||
impl TransferRegion {
|
||||
pub fn get_source_wells(&self) -> Vec<Well> {
|
||||
pub fn get_source_wells(&self) -> Vec<(u8, u8)> {
|
||||
match &self.source_region {
|
||||
Region::Rect(c1, c2) => {
|
||||
let mut wells = Vec::<Well>::new();
|
||||
let (ul, br) = standardize_rectangle(c1, c2);
|
||||
let mut wells = Vec::<(u8, u8)>::new();
|
||||
let (ul, br) = standardize_rectangle(&c1, &c2);
|
||||
let (interleave_i, interleave_j) = self.interleave_source;
|
||||
// NOTE: This will panic if either is 0!
|
||||
// We'll reassign these values (still not mutable) just in case.
|
||||
|
@ -92,12 +86,12 @@ impl TransferRegion {
|
|||
let (interleave_i, interleave_j) =
|
||||
(i8::max(interleave_i, 1), i8::max(interleave_j, 1));
|
||||
|
||||
for i in (ul.row..=br.row).step_by(i8::abs(interleave_i) as usize) {
|
||||
for j in (ul.col..=br.col).step_by(i8::abs(interleave_j) as usize) {
|
||||
for i in (ul.0..=br.0).step_by(i8::abs(interleave_i) as usize) {
|
||||
for j in (ul.1..=br.1).step_by(i8::abs(interleave_j) as usize) {
|
||||
// NOTE: It looks like we're ignoring negative interleaves,
|
||||
// because it wouldn't make a difference here---the same
|
||||
// wells will still be involved in the transfer.
|
||||
wells.push(Well { row: i, col: j })
|
||||
wells.push((i, j))
|
||||
}
|
||||
}
|
||||
wells
|
||||
|
@ -107,33 +101,33 @@ impl TransferRegion {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn get_destination_wells(&self) -> Vec<Well> {
|
||||
match &self.source_region {
|
||||
Region::Custom(c) => c.dest.clone(),
|
||||
_ => {
|
||||
pub fn get_destination_wells(&self) -> Vec<(u8, u8)> {
|
||||
let map = self.calculate_map();
|
||||
let source_wells = self.get_source_wells();
|
||||
|
||||
let mut wells = Vec::<Well>::new();
|
||||
let mut wells = Vec::<(u8, u8)>::new();
|
||||
|
||||
// log::debug!("GDW:");
|
||||
for well in source_wells {
|
||||
if let Some(mut dest_wells) = map(well) {
|
||||
// log::debug!("Map {:?} to {:?}", well, dest_wells);
|
||||
wells.append(&mut dest_wells);
|
||||
}
|
||||
}
|
||||
// log::debug!("GDW END.");
|
||||
|
||||
wells
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[allow(clippy::type_complexity)] // Resolving gives inherent associated type error
|
||||
pub fn calculate_map(&self) -> Box<dyn Fn(Well) -> Option<Vec<Well>> + '_> {
|
||||
pub fn calculate_map(&self) -> Box<dyn Fn((u8, u8)) -> Option<Vec<(u8, u8)>> + '_> {
|
||||
// By validating first, we have a stronger guarantee that
|
||||
// this function will not panic. :)
|
||||
// log::debug!("Validating: {:?}", self.validate());
|
||||
if let Err(msg) = self.validate() {
|
||||
log::error!("{}\nThis transfer will be empty.", msg);
|
||||
return Box::new(|_| None);
|
||||
eprintln!("{}", msg);
|
||||
eprintln!("This transfer will be empty.");
|
||||
return Box::new(|(_, _)| None);
|
||||
}
|
||||
|
||||
// log::debug!("What is ild? {:?}", self);
|
||||
|
@ -141,10 +135,10 @@ impl TransferRegion {
|
|||
let il_dest = self.interleave_dest;
|
||||
let il_source = self.interleave_source;
|
||||
|
||||
let source_corners: (Well, Well) = match self.source_region {
|
||||
Region::Point(w) => (w, w),
|
||||
let source_corners: ((u8, u8), (u8, u8)) = match self.source_region {
|
||||
Region::Point((x, y)) => ((x, y), (x, y)),
|
||||
Region::Rect(c1, c2) => (c1, c2),
|
||||
Region::Custom(_) => (Well { row: 0, col: 0 }, Well { row: 0, col: 0 }),
|
||||
Region::Custom(_) => ((0, 0), (0, 0)),
|
||||
};
|
||||
let (source_ul, _) = standardize_rectangle(&source_corners.0, &source_corners.1);
|
||||
// This map is not necessarily injective or surjective,
|
||||
|
@ -154,46 +148,45 @@ impl TransferRegion {
|
|||
|
||||
// Non-replicate transfers:
|
||||
match &self.dest_region {
|
||||
Region::Point(Well { row: x, col: y }) => {
|
||||
Box::new(move |Well { row: i, col: j }| {
|
||||
if source_wells.contains(&Well { row: i, col: j }) {
|
||||
Region::Point((x, y)) => {
|
||||
Box::new(move |(i, j)| {
|
||||
if source_wells.contains(&(i, j)) {
|
||||
// Validity here already checked by self.validate()
|
||||
Some(vec![Well {
|
||||
row: x + i
|
||||
.checked_sub(source_ul.row)
|
||||
Some(vec![(
|
||||
x + i
|
||||
.checked_sub(source_ul.0)
|
||||
.expect("Point cannot have been less than UL")
|
||||
.checked_div(il_source.0.unsigned_abs())
|
||||
.expect("Source interleave cannot be 0")
|
||||
.mul(il_dest.0.unsigned_abs()),
|
||||
col: y + j
|
||||
.checked_sub(source_ul.col)
|
||||
y + j
|
||||
.checked_sub(source_ul.1)
|
||||
.expect("Point cannot have been less than UL")
|
||||
.checked_div(il_source.1.unsigned_abs())
|
||||
.expect("Source interleave cannot be 0")
|
||||
.mul(il_dest.1.unsigned_abs()),
|
||||
}])
|
||||
)])
|
||||
} else {
|
||||
None
|
||||
}
|
||||
})
|
||||
}
|
||||
Region::Rect(c1, c2) => {
|
||||
Box::new(move |w| {
|
||||
let Well { row: i, col: j } = w;
|
||||
if source_wells.contains(&w) {
|
||||
let possible_destination_wells = create_dense_rectangle(c1, c2);
|
||||
let (d_ul, d_br) = standardize_rectangle(c1, c2);
|
||||
Box::new(move |(i, j)| {
|
||||
if source_wells.contains(&(i, j)) {
|
||||
let possible_destination_wells = create_dense_rectangle(&c1, &c2);
|
||||
let (d_ul, d_br) = standardize_rectangle(&c1, &c2);
|
||||
let (s_ul, s_br) =
|
||||
standardize_rectangle(&source_corners.0, &source_corners.1);
|
||||
let s_dims = (
|
||||
s_br.row.checked_sub(s_ul.row).unwrap() + 1,
|
||||
s_br.col.checked_sub(s_ul.col).unwrap() + 1,
|
||||
s_br.0.checked_sub(s_ul.0).unwrap() + 1,
|
||||
s_br.1.checked_sub(s_ul.1).unwrap() + 1,
|
||||
);
|
||||
let d_dims = (
|
||||
d_br.row.checked_sub(d_ul.row).unwrap() + 1,
|
||||
d_br.col.checked_sub(d_ul.col).unwrap() + 1,
|
||||
d_br.0.checked_sub(d_ul.0).unwrap() + 1,
|
||||
d_br.1.checked_sub(d_ul.1).unwrap() + 1,
|
||||
);
|
||||
let number_used_src_wells = (
|
||||
let N_s = (
|
||||
// Number of used source wells
|
||||
(s_dims.0 + il_source.0.unsigned_abs() - 1)
|
||||
.div_euclid(il_source.0.unsigned_abs()),
|
||||
|
@ -202,66 +195,54 @@ impl TransferRegion {
|
|||
);
|
||||
let count = (
|
||||
// How many times can we replicate?
|
||||
if il_dest.0.unsigned_abs() == 0 {
|
||||
1
|
||||
} else {
|
||||
(1..)
|
||||
.position(|n| {
|
||||
(n * number_used_src_wells.0 * il_dest.0.unsigned_abs())
|
||||
.saturating_sub(il_dest.0.unsigned_abs())
|
||||
n * N_s.0 * il_dest.0.unsigned_abs() - il_dest.0.unsigned_abs()
|
||||
+ 1
|
||||
> d_dims.0
|
||||
})
|
||||
.unwrap() as u8
|
||||
},
|
||||
if il_dest.1.unsigned_abs() == 0 {
|
||||
1
|
||||
} else {
|
||||
.unwrap() as u8,
|
||||
(1..)
|
||||
.position(|n| {
|
||||
(n * number_used_src_wells.1 * il_dest.1.unsigned_abs())
|
||||
.saturating_sub(il_dest.1.unsigned_abs())
|
||||
n * N_s.1 * il_dest.1.unsigned_abs() - il_dest.1.unsigned_abs()
|
||||
+ 1
|
||||
> d_dims.1
|
||||
})
|
||||
.unwrap() as u8
|
||||
},
|
||||
.unwrap() as u8,
|
||||
);
|
||||
let i = i
|
||||
.saturating_sub(s_ul.row)
|
||||
.saturating_sub(s_ul.0)
|
||||
.saturating_div(il_source.0.unsigned_abs());
|
||||
let j = j
|
||||
.saturating_sub(s_ul.col)
|
||||
.saturating_sub(s_ul.1)
|
||||
.saturating_div(il_source.1.unsigned_abs());
|
||||
let checked_il_dest = (u8::max(il_dest.0.unsigned_abs(), 1u8),
|
||||
u8::max(il_dest.1.unsigned_abs(), 1u8));
|
||||
let row_modulus = number_used_src_wells.0 * checked_il_dest.0;
|
||||
let column_modulus = number_used_src_wells.1 * checked_il_dest.1;
|
||||
|
||||
Some(
|
||||
possible_destination_wells
|
||||
.into_iter()
|
||||
.filter(|Well { row: x, .. }| {
|
||||
x.checked_sub(d_ul.row).unwrap()
|
||||
% row_modulus // Counter along x
|
||||
.filter(|(x, _)| {
|
||||
x.checked_sub(d_ul.0).unwrap()
|
||||
% (N_s.0 * il_dest.0.unsigned_abs()) // Counter along x
|
||||
== (il_dest.0.unsigned_abs() *i)
|
||||
% row_modulus
|
||||
% (N_s.0 * il_dest.0.unsigned_abs())
|
||||
})
|
||||
.filter(|Well { col: y, .. }| {
|
||||
y.checked_sub(d_ul.col).unwrap()
|
||||
% column_modulus // Counter along u
|
||||
.filter(|(_, y)| {
|
||||
y.checked_sub(d_ul.1).unwrap()
|
||||
% (N_s.1 * il_dest.1.unsigned_abs()) // Counter along u
|
||||
== (il_dest.1.unsigned_abs() *j)
|
||||
% column_modulus
|
||||
% (N_s.1 * il_dest.1.unsigned_abs())
|
||||
})
|
||||
.filter(|Well { row: x, col: y }| {
|
||||
.filter(|(x, y)| {
|
||||
// How many times have we replicated? < How many are we allowed
|
||||
// to replicate?
|
||||
x.checked_sub(d_ul.row).unwrap().div_euclid(
|
||||
row_modulus
|
||||
) < count.0
|
||||
&& y.checked_sub(d_ul.col).unwrap().div_euclid(
|
||||
column_modulus
|
||||
) < count.1
|
||||
x.checked_sub(d_ul.0)
|
||||
.unwrap()
|
||||
.div_euclid(N_s.0 * il_dest.0.unsigned_abs())
|
||||
< count.0
|
||||
&& y.checked_sub(d_ul.1)
|
||||
.unwrap()
|
||||
.div_euclid(N_s.1 * il_dest.1.unsigned_abs())
|
||||
< count.1
|
||||
})
|
||||
.collect(),
|
||||
)
|
||||
|
@ -270,14 +251,14 @@ impl TransferRegion {
|
|||
}
|
||||
})
|
||||
}
|
||||
Region::Custom(c) => Box::new(move |Well { row: i, col: j }| {
|
||||
Region::Custom(c) => Box::new(move |(i, j)| {
|
||||
let src = c.src.clone();
|
||||
let dest = c.dest.clone();
|
||||
|
||||
let points: Vec<Well> = src
|
||||
let points: Vec<(u8, u8)> = src
|
||||
.iter()
|
||||
.enumerate()
|
||||
.filter(|(_index, Well { row: x, col: y })| *x == i && *y == j)
|
||||
.filter(|(_index, (x, y))| *x == i && *y == j)
|
||||
.map(|(index, _)| dest[index])
|
||||
.collect();
|
||||
if points.is_empty() {
|
||||
|
@ -306,27 +287,23 @@ impl TransferRegion {
|
|||
// later
|
||||
Region::Rect(s1, s2) => {
|
||||
// Check if all source wells exist:
|
||||
if s1.row == 0 || s1.col == 0 || s2.row == 0 || s2.col == 0 {
|
||||
if s1.0 == 0 || s1.1 == 0 || s2.0 == 0 || s2.1 == 0 {
|
||||
return Err("Source region is out-of-bounds! (Too small)");
|
||||
}
|
||||
// Sufficient to check if the corners are in-bounds
|
||||
let source_max = self.source_plate.size();
|
||||
if s1.row > source_max.0 || s2.row > source_max.0 {
|
||||
if s1.0 > source_max.0 || s2.0 > source_max.0 {
|
||||
return Err("Source region is out-of-bounds! (Too tall)");
|
||||
}
|
||||
if s1.col > source_max.1 || s2.col > source_max.1 {
|
||||
if s1.1 > source_max.1 || s2.1 > source_max.1 {
|
||||
// log::debug!("s1.1: {}, max.1: {}", s1.1, source_max.1);
|
||||
return Err("Source region is out-of-bounds! (Too wide)");
|
||||
}
|
||||
|
||||
if il_dest == (0,0) {
|
||||
return Err("Refusing to pool both dimensions in a rectangular transfer!\nPlease select a point in the destination plate.")
|
||||
}
|
||||
}
|
||||
Region::Custom(_) => return Ok(()),
|
||||
}
|
||||
|
||||
if il_source.0 == 0 || il_source.1 == 0 {
|
||||
if il_source.0 == 0 || il_dest.1 == 0 {
|
||||
return Err("Source interleave cannot be zero!");
|
||||
}
|
||||
|
||||
|
@ -339,34 +316,28 @@ impl TransferRegion {
|
|||
}
|
||||
}
|
||||
|
||||
fn create_dense_rectangle(c1: &Well, c2: &Well) -> Vec<Well> {
|
||||
fn create_dense_rectangle(c1: &(u8, u8), c2: &(u8, u8)) -> Vec<(u8, u8)> {
|
||||
// Creates a vector of every point between two corners
|
||||
let (c1, c2) = standardize_rectangle(c1, c2);
|
||||
|
||||
let mut points = Vec::<Well>::new();
|
||||
for i in c1.row..=c2.row {
|
||||
for j in c1.col..=c2.col {
|
||||
points.push(Well { row: i, col: j });
|
||||
let mut points = Vec::<(u8, u8)>::new();
|
||||
for i in c1.0..=c2.0 {
|
||||
for j in c1.1..=c2.1 {
|
||||
points.push((i, j));
|
||||
}
|
||||
}
|
||||
|
||||
points
|
||||
}
|
||||
|
||||
fn standardize_rectangle(c1: &Well, c2: &Well) -> (Well, Well) {
|
||||
let upper_left_i = u8::min(c1.row, c2.row);
|
||||
let upper_left_j = u8::min(c1.col, c2.col);
|
||||
let bottom_right_i = u8::max(c1.row, c2.row);
|
||||
let bottom_right_j = u8::max(c1.col, c2.col);
|
||||
fn standardize_rectangle(c1: &(u8, u8), c2: &(u8, u8)) -> ((u8, u8), (u8, u8)) {
|
||||
let upper_left_i = u8::min(c1.0, c2.0);
|
||||
let upper_left_j = u8::min(c1.1, c2.1);
|
||||
let bottom_right_i = u8::max(c1.0, c2.0);
|
||||
let bottom_right_j = u8::max(c1.1, c2.1);
|
||||
(
|
||||
Well {
|
||||
row: upper_left_i,
|
||||
col: upper_left_j,
|
||||
},
|
||||
Well {
|
||||
row: bottom_right_i,
|
||||
col: bottom_right_j,
|
||||
},
|
||||
(upper_left_i, upper_left_j),
|
||||
(bottom_right_i, bottom_right_j),
|
||||
)
|
||||
}
|
||||
|
||||
|
@ -383,7 +354,7 @@ impl fmt::Display for TransferRegion {
|
|||
let mut source_string = String::new();
|
||||
for i in 1..=source_dims.0 {
|
||||
for j in 1..=source_dims.1 {
|
||||
if source_wells.contains(&Well { row: i, col: j }) {
|
||||
if source_wells.contains(&(i, j)) {
|
||||
source_string.push('x')
|
||||
} else {
|
||||
source_string.push('.')
|
||||
|
@ -399,7 +370,7 @@ impl fmt::Display for TransferRegion {
|
|||
let mut dest_string = String::new();
|
||||
for i in 1..=dest_dims.0 {
|
||||
for j in 1..=dest_dims.1 {
|
||||
if dest_wells.contains(&Well { row: i, col: j }) {
|
||||
if dest_wells.contains(&(i, j)) {
|
||||
dest_string.push('x')
|
||||
} else {
|
||||
dest_string.push('.')
|
||||
|
@ -413,134 +384,134 @@ impl fmt::Display for TransferRegion {
|
|||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use crate::plate::*;
|
||||
use crate::transfer_region::*;
|
||||
use wasm_bindgen_test::*;
|
||||
|
||||
use crate::data::plate::*;
|
||||
use crate::data::transfer_region::*;
|
||||
|
||||
#[test]
|
||||
#[wasm_bindgen_test]
|
||||
fn test_simple_transfer() {
|
||||
let source = Plate::new(PlateType::Source, PlateFormat::W96);
|
||||
let destination = Plate::new(PlateType::Destination, PlateFormat::W384);
|
||||
|
||||
let transfer1 = TransferRegion {
|
||||
source_plate: source,
|
||||
source_region: Region::Rect(Well { row: 1, col: 1 }, Well { row: 1, col: 1 }),
|
||||
source_region: Region::Rect((1, 1), (3, 3)),
|
||||
dest_plate: destination,
|
||||
dest_region: Region::Point(Well { row: 3, col: 3 }),
|
||||
dest_region: Region::Point((3, 3)),
|
||||
interleave_source: (1, 1),
|
||||
interleave_dest: (1, 1),
|
||||
};
|
||||
let transfer1_map = transfer1.calculate_map();
|
||||
assert_eq!(
|
||||
transfer1_map(Well { row: 1, col: 1 }),
|
||||
Some(vec! {Well {row: 3, col: 3}}),
|
||||
transfer1_map((1, 1)),
|
||||
Some(vec! {(3,3)}),
|
||||
"Failed basic shift transfer 1"
|
||||
);
|
||||
assert_eq!(
|
||||
transfer1_map(Well { row: 1, col: 2 }),
|
||||
Some(vec! {Well{ row: 3, col: 4}}),
|
||||
transfer1_map((1, 2)),
|
||||
Some(vec! {(3,4)}),
|
||||
"Failed basic shift transfer 2"
|
||||
);
|
||||
assert_eq!(
|
||||
transfer1_map(Well { row: 2, col: 2 }),
|
||||
Some(vec! {Well{ row: 4, col: 4}}),
|
||||
transfer1_map((2, 2)),
|
||||
Some(vec! {(4,4)}),
|
||||
"Failed basic shift transfer 3"
|
||||
);
|
||||
|
||||
let transfer2 = TransferRegion {
|
||||
source_plate: source,
|
||||
source_region: Region::Rect(Well { row: 1, col: 1 }, Well { row: 3, col: 3 }),
|
||||
source_region: Region::Rect((1, 1), (3, 3)),
|
||||
dest_plate: destination,
|
||||
dest_region: Region::Point(Well { row: 3, col: 3 }),
|
||||
dest_region: Region::Point((3, 3)),
|
||||
interleave_source: (2, 2),
|
||||
interleave_dest: (1, 1),
|
||||
};
|
||||
let transfer2_map = transfer2.calculate_map();
|
||||
assert_eq!(
|
||||
transfer2_map(Well { row: 1, col: 1 }),
|
||||
Some(vec! {Well{ row: 3, col: 3}}),
|
||||
transfer2_map((1, 1)),
|
||||
Some(vec! {(3,3)}),
|
||||
"Failed source interleave, type simple 1"
|
||||
);
|
||||
assert_eq!(
|
||||
transfer2_map(Well { row: 1, col: 2 }),
|
||||
transfer2_map((1, 2)),
|
||||
None,
|
||||
"Failed source interleave, type simple 2"
|
||||
);
|
||||
assert_eq!(
|
||||
transfer2_map(Well { row: 2, col: 2 }),
|
||||
transfer2_map((2, 2)),
|
||||
None,
|
||||
"Failed source interleave, type simple 3"
|
||||
);
|
||||
assert_eq!(
|
||||
transfer2_map(Well { row: 3, col: 3 }),
|
||||
Some(vec! {Well{ row: 4, col: 4}}),
|
||||
transfer2_map((3, 3)),
|
||||
Some(vec! {(4,4)}),
|
||||
"Failed source interleave, type simple 4"
|
||||
);
|
||||
|
||||
let transfer3 = TransferRegion {
|
||||
source_plate: source,
|
||||
source_region: Region::Rect(Well { row: 1, col: 1 }, Well { row: 3, col: 3 }),
|
||||
source_region: Region::Rect((1, 1), (3, 3)),
|
||||
dest_plate: destination,
|
||||
dest_region: Region::Point(Well { row: 3, col: 3 }),
|
||||
dest_region: Region::Point((3, 3)),
|
||||
interleave_source: (1, 1),
|
||||
interleave_dest: (2, 3),
|
||||
};
|
||||
let transfer3_map = transfer3.calculate_map();
|
||||
assert_eq!(
|
||||
transfer3_map(Well { row: 1, col: 1 }),
|
||||
Some(vec! {Well{ row: 3, col: 3}}),
|
||||
transfer3_map((1, 1)),
|
||||
Some(vec! {(3,3)}),
|
||||
"Failed destination interleave, type simple 1"
|
||||
);
|
||||
assert_eq!(
|
||||
transfer3_map(Well { row: 2, col: 1 }),
|
||||
Some(vec! {Well{ row: 5, col: 3}}),
|
||||
transfer3_map((2, 1)),
|
||||
Some(vec! {(5,3)}),
|
||||
"Failed destination interleave, type simple 2"
|
||||
);
|
||||
assert_eq!(
|
||||
transfer3_map(Well { row: 1, col: 2 }),
|
||||
Some(vec! {Well{ row: 3, col: 6}}),
|
||||
transfer3_map((1, 2)),
|
||||
Some(vec! {(3,6)}),
|
||||
"Failed destination interleave, type simple 3"
|
||||
);
|
||||
assert_eq!(
|
||||
transfer3_map(Well { row: 2, col: 2 }),
|
||||
Some(vec! {Well{ row: 5, col: 6}}),
|
||||
transfer3_map((2, 2)),
|
||||
Some(vec! {(5,6)}),
|
||||
"Failed destination interleave, type simple 4"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[wasm_bindgen_test]
|
||||
fn test_replicate_transfer() {
|
||||
let source = Plate::new(PlateType::Source, PlateFormat::W96);
|
||||
let destination = Plate::new(PlateType::Destination, PlateFormat::W384);
|
||||
|
||||
let transfer1 = TransferRegion {
|
||||
source_plate: source,
|
||||
source_region: Region::Rect(Well { row: 1, col: 1 }, Well { row: 2, col: 2 }),
|
||||
source_region: Region::Rect((1, 1), (2, 2)),
|
||||
dest_plate: destination,
|
||||
dest_region: Region::Rect(Well { row: 2, col: 2 }, Well { row: 11, col: 11 }),
|
||||
dest_region: Region::Rect((2, 2), (11, 11)),
|
||||
interleave_source: (1, 1),
|
||||
interleave_dest: (3, 3),
|
||||
};
|
||||
let transfer1_map = transfer1.calculate_map();
|
||||
assert_eq!(
|
||||
transfer1_map(Well { row: 1, col: 1 }),
|
||||
Some(
|
||||
vec! {Well{ row: 2, col: 2}, Well{ row: 2, col: 8}, Well{ row: 8, col: 2}, Well{ row: 8, col: 8}}
|
||||
),
|
||||
transfer1_map((1, 1)),
|
||||
Some(vec! {(2, 2), (2, 8), (8, 2), (8, 8)}),
|
||||
"Failed type replicate 1"
|
||||
);
|
||||
assert_eq!(
|
||||
transfer1_map(Well { row: 2, col: 1 }),
|
||||
Some(
|
||||
vec! {Well{ row: 5, col: 2}, Well{ row: 5, col: 8}, Well{ row: 11, col: 2}, Well{ row: 11, col: 8}}
|
||||
),
|
||||
transfer1_map((2, 1)),
|
||||
Some(vec! {(5, 2), (5, 8), (11, 2), (11, 8)}),
|
||||
"Failed type replicate 1"
|
||||
);
|
||||
|
||||
let transfer2 = TransferRegion {
|
||||
source_plate: Plate::new(PlateType::Source, PlateFormat::W384),
|
||||
dest_plate: Plate::new(PlateType::Destination, PlateFormat::W384),
|
||||
source_region: Region::Rect(Well { row: 1, col: 1 }, Well { row: 2, col: 3 }),
|
||||
dest_region: Region::Rect(Well { row: 2, col: 2 }, Well { row: 11, col: 16 }),
|
||||
source_region: Region::Rect((1, 1), (2, 3)),
|
||||
dest_region: Region::Rect((2, 2), (11, 16)),
|
||||
interleave_source: (1, 1),
|
||||
interleave_dest: (2, 2),
|
||||
};
|
||||
|
@ -548,83 +519,71 @@ mod tests {
|
|||
let transfer2_dest = transfer2.get_destination_wells();
|
||||
assert_eq!(
|
||||
transfer2_source,
|
||||
vec![
|
||||
Well { row: 1, col: 1 },
|
||||
Well { row: 1, col: 2 },
|
||||
Well { row: 1, col: 3 },
|
||||
Well { row: 2, col: 1 },
|
||||
Well { row: 2, col: 2 },
|
||||
Well { row: 2, col: 3 }
|
||||
],
|
||||
vec![(1, 1), (1, 2), (1, 3), (2, 1), (2, 2), (2, 3)],
|
||||
"Failed type replicate 2 source"
|
||||
);
|
||||
assert_eq!(
|
||||
transfer2_dest,
|
||||
vec![
|
||||
Well { row: 2, col: 2 },
|
||||
Well { row: 2, col: 8 },
|
||||
Well { row: 6, col: 2 },
|
||||
Well { row: 6, col: 8 },
|
||||
Well { row: 2, col: 4 },
|
||||
Well { row: 2, col: 10 },
|
||||
Well { row: 6, col: 4 },
|
||||
Well { row: 6, col: 10 },
|
||||
Well { row: 2, col: 6 },
|
||||
Well { row: 2, col: 12 },
|
||||
Well { row: 6, col: 6 },
|
||||
Well { row: 6, col: 12 },
|
||||
Well { row: 4, col: 2 },
|
||||
Well { row: 4, col: 8 },
|
||||
Well { row: 8, col: 2 },
|
||||
Well { row: 8, col: 8 },
|
||||
Well { row: 4, col: 4 },
|
||||
Well { row: 4, col: 10 },
|
||||
Well { row: 8, col: 4 },
|
||||
Well { row: 8, col: 10 },
|
||||
Well { row: 4, col: 6 },
|
||||
Well { row: 4, col: 12 },
|
||||
Well { row: 8, col: 6 },
|
||||
Well { row: 8, col: 12 }
|
||||
(2, 2),
|
||||
(2, 8),
|
||||
(6, 2),
|
||||
(6, 8),
|
||||
(2, 4),
|
||||
(2, 10),
|
||||
(6, 4),
|
||||
(6, 10),
|
||||
(2, 6),
|
||||
(2, 12),
|
||||
(6, 6),
|
||||
(6, 12),
|
||||
(4, 2),
|
||||
(4, 8),
|
||||
(8, 2),
|
||||
(8, 8),
|
||||
(4, 4),
|
||||
(4, 10),
|
||||
(8, 4),
|
||||
(8, 10),
|
||||
(4, 6),
|
||||
(4, 12),
|
||||
(8, 6),
|
||||
(8, 12)
|
||||
],
|
||||
"Failed type replicate 2 destination"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[wasm_bindgen_test]
|
||||
fn test_pooling_transfer() {
|
||||
use std::collections::HashSet;
|
||||
let transfer1 = TransferRegion {
|
||||
source_plate: Plate::new(PlateType::Source, PlateFormat::W384),
|
||||
dest_plate: Plate::new(PlateType::Destination, PlateFormat::W384),
|
||||
source_region: Region::Rect(Well { row: 1, col: 4 }, Well { row: 3, col: 7 }),
|
||||
dest_region: Region::Point(Well { row: 1, col: 9 }),
|
||||
source_region: Region::Rect((1, 4), (3, 7)),
|
||||
dest_region: Region::Point((1, 9)),
|
||||
interleave_source: (1, 1),
|
||||
interleave_dest: (0, 2),
|
||||
};
|
||||
//let transfer1_source = transfer1.get_source_wells();
|
||||
let transfer1_dest: HashSet<Well> = transfer1.get_destination_wells().into_iter().collect();
|
||||
let mut transfer1_dest = transfer1.get_destination_wells();
|
||||
transfer1_dest.sort();
|
||||
transfer1_dest.dedup(); // Makes our check easier, otherwise we have repeated wells
|
||||
let transfer1_map = transfer1.calculate_map();
|
||||
// Skipping source check---it's just 12 wells.
|
||||
assert_eq!(
|
||||
transfer1_dest,
|
||||
vec![
|
||||
Well { row: 1, col: 9 },
|
||||
Well { row: 1, col: 11 },
|
||||
Well { row: 1, col: 13 },
|
||||
Well { row: 1, col: 15 }
|
||||
]
|
||||
.into_iter()
|
||||
.collect(),
|
||||
vec![(1, 9), (1, 11), (1, 13), (1, 15)],
|
||||
"Failed type pool 1 dest"
|
||||
);
|
||||
assert_eq!(
|
||||
transfer1_map(Well { row: 2, col: 6 }),
|
||||
Some(vec![Well { row: 1, col: 13 }]),
|
||||
transfer1_map((2, 6)),
|
||||
Some(vec![(1, 13)]),
|
||||
"Failed type pool 1 map 1"
|
||||
);
|
||||
assert_eq!(
|
||||
transfer1_map(Well { row: 3, col: 7 }),
|
||||
Some(vec![Well { row: 1, col: 15 }]),
|
||||
transfer1_map((3, 7)),
|
||||
Some(vec![(1, 15)]),
|
||||
"Failed type pool 1 map 2"
|
||||
);
|
||||
}
|
|
@ -0,0 +1,37 @@
|
|||
#![allow(non_snake_case)]
|
||||
mod components;
|
||||
mod data;
|
||||
|
||||
use components::main_window::MainWindow;
|
||||
use yew::prelude::*;
|
||||
|
||||
#[cfg(debug_assertions)]
|
||||
use data::*;
|
||||
|
||||
#[function_component]
|
||||
pub fn App() -> Html {
|
||||
html! {
|
||||
<MainWindow />
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(debug_assertions)]
|
||||
pub fn plate_test() {
|
||||
let source = plate::Plate::new(plate::PlateType::Source, plate::PlateFormat::W96);
|
||||
let destination = plate::Plate::new(plate::PlateType::Destination, plate::PlateFormat::W384);
|
||||
|
||||
let transfer = transfer_region::TransferRegion {
|
||||
source_plate: source,
|
||||
source_region: transfer_region::Region::Rect((1, 1), (2, 2)),
|
||||
dest_plate: destination,
|
||||
dest_region: transfer_region::Region::Rect((2, 2), (11, 11)),
|
||||
interleave_source: (1, 1),
|
||||
interleave_dest: (3, 3),
|
||||
};
|
||||
println!("{}", transfer);
|
||||
let sws = transfer.get_source_wells();
|
||||
let m = transfer.calculate_map();
|
||||
for w in sws {
|
||||
println!("{:?} -> {:?}", w, m(w));
|
||||
}
|
||||
}
|
|
@ -1,4 +1,4 @@
|
|||
use plate_tool_web::App;
|
||||
use plate_tool::App;
|
||||
|
||||
fn main() {
|
||||
wasm_logger::init(wasm_logger::Config::default());
|
Loading…
Reference in New Issue