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
92b825d7
Commit
92b825d7
authored
2 years ago
by
Bakker, Sibbe
Browse files
Options
Downloads
Patches
Plain Diff
Completed optimisation.
parent
98082836
No related branches found
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
+35
-23
35 additions, 23 deletions
src/needle.rs
with
35 additions
and
23 deletions
src/needle.rs
+
35
−
23
View file @
92b825d7
...
...
@@ -142,8 +142,10 @@ pub mod algo {
///
/// The self parameter end gap cost is taken into account.
pub
fn
initialise
(
&
mut
self
)
{
for
i
in
(
0
..
self
.trace
.len
())
.rev
()
{
for
j
in
(
0
..
self
.trace
[
i
]
.len
())
.rev
()
{
let
trace_range
=
(
0
..
self
.trace
.len
())
.rev
();
for
i
in
trace_range
{
let
trace_i_range
=
(
0
..
self
.trace
[
i
]
.len
())
.rev
();
for
j
in
trace_i_range
{
let
val
=
self
.trace
[
i
][
j
];
let
i_n
=
(
i
as
i64
)
*
self
.end_gap
;
let
j_n
=
(
j
as
i64
)
*
self
.end_gap
;
...
...
@@ -219,9 +221,12 @@ pub mod algo {
&
self
)
->
(
Vec
<
(
usize
,
usize
)
>
,
Vec
<&
Directions
>
)
{
// Here be the traceback
let
mut
coord
=
(
self
.x
.len
(),
self
.y
.len
());
let
mut
directions
:
Vec
<&
Directions
>
=
Vec
::
new
();
let
mut
indeces
:
Vec
<
(
usize
,
usize
)
>
=
Vec
::
new
();
let
xlen
=
self
.x
.len
();
let
ylen
=
self
.y
.len
();
let
mut
coord
=
(
xlen
,
ylen
);
let
max_len
=
ylen
.max
(
xlen
);
let
mut
directions
:
Vec
<&
Directions
>
=
Vec
::
with_capacity
(
max_len
);
let
mut
indeces
:
Vec
<
(
usize
,
usize
)
>
=
Vec
::
with_capacity
(
max_len
);
while
coord
!=
(
0_usize
,
0_usize
)
{
let
(
i
,
j
)
=
coord
;
let
current_direction
=
&
self
.direction
[
i
][
j
];
...
...
@@ -247,24 +252,26 @@ pub mod algo {
indices
:
Vec
<
(
usize
,
usize
)
>
,
directions
:
Vec
<&
Directions
>
,
)
->
NeedlemanWunchAlignment
{
let
mut
x
:
Vec
<
String
>
=
Vec
::
with_capacity
(
directions
.len
());
let
mut
y
:
Vec
<
String
>
=
Vec
::
with_capacity
(
directions
.len
());
let
mut
x
:
Vec
<
char
>
=
Vec
::
with_capacity
(
directions
.len
());
let
mut
y
:
Vec
<
char
>
=
Vec
::
with_capacity
(
directions
.len
());
let
x_chars
:
Vec
<
char
>
=
self
.x
.chars
()
.collect
();
let
y_chars
:
Vec
<
char
>
=
self
.y
.chars
()
.collect
();
let
indices
:
Vec
<&
(
usize
,
usize
)
>
=
indices
.iter
()
.collect
();
for
(
index
,
direction
)
in
directions
.iter
()
.enumerate
()
{
let
(
i
,
j
)
=
(
indices
[
index
]
.0
,
indices
[
index
]
.1
);
let
x_ch
=
self
.x
.chars
()
.nth
(
i
-
1
)
.unwrap
()
.to_string
()
;
let
y_ch
=
self
.y
.chars
()
.nth
(
j
-
1
)
.unwrap
()
.to_string
()
;
let
x_ch
=
x_chars
[
i
-
1
]
;
let
y_ch
=
y_chars
[
j
-
1
]
;
match
direction
{
Directions
::
Diagonal
=>
{
x
.push
(
x_ch
);
y
.push
(
y_ch
);
}
Directions
::
Up
=>
{
y
.push
(
"-"
.to_string
()
);
y
.push
(
'-'
);
x
.push
(
x_ch
);
}
Directions
::
Left
=>
{
x
.push
(
"-"
.to_string
()
);
x
.push
(
'-'
);
y
.push
(
y_ch
);
}
Directions
::
Unknown
=>
{
...
...
@@ -274,10 +281,10 @@ pub mod algo {
}
x
.reverse
();
y
.reverse
();
//
let x: Vec<String> =
//
x.into_iter().map(|x_i| x_i.to_
owned
()).collect();
//
let y: Vec<String> =
//
y.into_iter().map(|y_i| y_i.to_
owned
()).collect();
let
x
:
Vec
<
String
>
=
x
.into_iter
()
.map
(|
x_i
|
x_i
.to_
string
())
.collect
();
let
y
:
Vec
<
String
>
=
y
.into_iter
()
.map
(|
y_i
|
y_i
.to_
string
())
.collect
();
NeedlemanWunchAlignment
{
x
:
x
.join
(
""
),
y
:
y
.join
(
""
),
...
...
@@ -476,16 +483,21 @@ mod test_algo {
#[test]
fn
test_long_output
()
{
for
i
in
1
..
500
{
let
x
:
String
=
"MGLLCSRSRHHTEDTDENAQAAEIERRIEQEAKAEKHIRKLLLLGAGESGKSTIFKQASSDKRKIIKLLFQTGFDEGELKSYVPVIHANVYQTIKLLHDGTKEFAQNETDPAKYTLSSENMAIGEKLSEIGARLDYPRLTKDLAEGIETLWNDPAIQETCSRGNELQVPDCTKYLMENLKRLSDVNYIPTKEDVLYARVRTTGVVEIQFSPVGENKKSGEVYRLFDVGGQRNERRKWIHLFEGVTAVIFCAAISEYDQTLFEDEQKNRMMETKELFDWVLKQPCFEKTSIMLFLNKFDIFEKKVLDVPLNVCEWFRDYQPVSSGKQEIEHAYEFVKKKFEELYYQNTAPDRVDRVFKIYRTTALDQKLVKKTFKLVDETLRRRNLLEAGLL"
.to_string
();
let
y
:
String
=
"MGLLCSRSRHHTEDTDENTQAAEIERRIEQEAKAEKHIRKLLLLGAGESGKSTIFKQIKLLFQTGFDEGELKSYVPVIHANVYQTIKLLHDGTKEFAQNETDSAKYMLSSESIAIGEKLSEIGGRLDYPRLTKDIAEGIETLWKDPAIQETCARGNELQVPDCTKYLMENLKRLSDINYIPTKEDVLYARVRTTGVVEIQFSPVGENKKSGEVYRLFDVGGQRNERRKWIHLFEGVTAVIFCAAISEYDQTLFEDEQKNRMMETKELFDWVLKQPCFEKTSFMLFLNKFDIFEKKVLDVPLNVCEWFRDYQPVSSGKQEIEHAYEFVKKKFEELYYQNTAPDRVDRVFKIYRTTALDQKLVKKTFKLVDETLRRRNLLEA"
.to_string
();
let
x
:
String
=
"MGLLCSRSRHHTEDTDENAQAAEIERRIEQEAKAEKHIRKLLLLGAGESGKSTIFKQASSDKRKIIKLLFQTGFDEGELKSYVPVIHANVYQTIKLLHDGTKEFAQNETDPAKYTLSSENMAIGEKLSEIGARLDYPRLTKDLAEGIETLWNDPAIQETCSRGNELQVPDCTKYLMENLKRLSDVNYIPTKEDVLYARVRTTGVVEIQFSPVGENKKSGEVYRLFDVGGQRNERRKWIHLFEGVTAVIFCAAISEYDQTLFEDEQKNRMMETKELFDWVLKQPCFEKTSIMLFLNKFDIFEKKVLDVPLNVCEWFRDYQPVSSGKQEIEHAYEFVKKKFEELYYQNTAPDRVDRVFKIYRTTALDQKLVKKTFKLVDETLRRRNLLEAGLL"
.to_string
();
let
y
:
String
=
"MGLLCSRSRHHTEDTDENTQAAEIERRIEQEAKAEKHIRKLLLLGAGESGKSTIFKQIKLLFQTGFDEGELKSYVPVIHANVYQTIKLLHDGTKEFAQNETDSAKYMLSSESIAIGEKLSEIGGRLDYPRLTKDIAEGIETLWKDPAIQETCARGNELQVPDCTKYLMENLKRLSDINYIPTKEDVLYARVRTTGVVEIQFSPVGENKKSGEVYRLFDVGGQRNERRKWIHLFEGVTAVIFCAAISEYDQTLFEDEQKNRMMETKELFDWVLKQPCFEKTSFMLFLNKFDIFEKKVLDVPLNVCEWFRDYQPVSSGKQEIEHAYEFVKKKFEELYYQNTAPDRVDRVFKIYRTTALDQKLVKKTFKLVDETLRRRNLLEA"
.to_string
();
let
file
:
&
Path
=
Path
::
new
(
"data/blosum_62.txt"
);
let
blosum
=
import_protein_substitution_matrix
(
file
);
for
i
in
1
..
20
{
let
end_gap
=
-
1
*
i
;
let
gap_score
=
end_gap
;
let
file
:
&
Path
=
Path
::
new
(
"data/blosum_62.txt"
);
let
blosum
=
import_protein_substitution_matrix
(
file
);
let
mut
alignment
=
NeedlemanWunch
::
new
(
x
,
y
,
end_gap
,
gap_score
,
blosum
);
let
mut
alignment
=
NeedlemanWunch
::
new
(
x
.clone
(),
y
.clone
(),
end_gap
,
gap_score
,
blosum
.clone
(),
);
alignment
.set_traceback
();
let
res
=
alignment
.get_traceback
();
alignment
.construct_alignment
(
res
.0
,
res
.1
);
...
...
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