Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
R
rusty-needle
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Bakker, Sibbe
rusty-needle
Commits
3d0d74cc
Commit
3d0d74cc
authored
2 years ago
by
Bakker, Sibbe
Browse files
Options
Downloads
Patches
Plain Diff
Wrapping function.
parent
5863ba94
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/needle.rs
+47
-8
47 additions, 8 deletions
src/needle.rs
with
47 additions
and
8 deletions
src/needle.rs
+
47
−
8
View file @
3d0d74cc
...
...
@@ -9,6 +9,12 @@
///
/// In this module, the Needleman-Wunch algorithm is implemented.
pub
mod
algo
{
#[cfg(windows)]
/// Windows line ending
const
LINE_ENDING
:
&
'static
str
=
"
\r\n
"
;
#[cfg(not(windows))]
/// The unix line ending.
const
LINE_ENDING
:
&
'static
str
=
"
\n
"
;
use
std
::{
fmt
,
ops
::
Add
};
...
...
@@ -18,7 +24,7 @@ pub mod algo {
///
/// eg: `(a + b).modulo(c)`
/// ## Reference
/// Written b
io
[Ideaman42](https://stackoverflow.com/a/41422009).
/// Written b
y
[Ideaman42](https://stackoverflow.com/a/41422009).
pub
trait
ModuloSignedExt
{
fn
modulo
(
&
self
,
...
...
@@ -85,19 +91,29 @@ pub mod algo {
pub
(
super
)
end_gap
:
i64
,
}
/// # Converts a string to a `Vec` where each item is a wrapped string.
fn
wrap_string
(
x
:
&
String
,
n
:
usize
,
)
->
Vec
<
String
>
{
dbg!
(
x
);
let
mut
res
:
Vec
<
String
>
=
Vec
::
new
();
let
mut
res_part
=
String
::
new
();
for
(
i
,
ch
)
in
x
.chars
()
.enumerate
()
{
if
i
.modulo
(
n
)
==
n
{
let
mut
i
:
usize
=
0
;
for
ch
in
x
.chars
()
{
dbg!
(
ch
,
i
);
if
i
==
n
{
res_part
.push
(
ch
);
}
else
{
res
.push
(
res_part
.clone
());
res_part
.clear
();
i
=
0
;
}
else
{
res_part
.push
(
ch
);
}
i
+=
1
;
}
if
res
.is_empty
()
{
res
.push
(
res_part
.clone
());
}
res
}
...
...
@@ -108,8 +124,10 @@ pub mod algo {
&
self
,
f
:
&
mut
fmt
::
Formatter
,
)
->
fmt
::
Result
{
dbg!
(
"Display"
);
let
line_number
:
usize
=
79
;
write!
(
f
,
"{:?}"
,
wrap_string
(
&
self
.x
,
line_number
))
let
out
=
wrap_string
(
&
self
.x
,
line_number
);
write!
(
f
,
"{:?}"
,
out
)
}
}
...
...
@@ -542,9 +560,30 @@ mod test_algo {
let
res
=
alignment
.get_traceback
();
alignment
.construct_alignment
(
res
.0
,
res
.1
);
}
// let result = alignment.get_traceback();
// let alignment = alignment.construct_alignment(result.0, result.1);
// println!("{}", alignment);
}
// let result = alignment.get_traceback();
// let alignment = alignment.construct_alignment(result.0, result.1);
// println!("{}", alignment);
#[test]
fn
test_alignmnent_print
()
{
let
x
:
String
=
"MGLLCSRSRH"
.to_string
();
let
y
:
String
=
"MGLLCSRSRHHTEDTD"
.to_string
();
let
file
:
&
Path
=
Path
::
new
(
"assets/blosum_62.txt"
);
let
blosum
=
import_protein_substitution_matrix
(
file
);
let
end_gap
=
-
8
;
let
gap_score
=
end_gap
;
let
mut
alignment
=
NeedlemanWunch
::
new
(
x
.clone
(),
y
.clone
(),
end_gap
,
gap_score
,
blosum
.clone
(),
);
alignment
.set_traceback
();
let
res
=
alignment
.get_traceback
();
let
alg
=
alignment
.construct_alignment
(
res
.0
,
res
.1
);
println!
(
"{}"
,
alg
);
}
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment