Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
LightMotif
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
Martin Larralde
LightMotif
Commits
1b666ede
Commit
1b666ede
authored
1 year ago
by
Martin Larralde
Browse files
Options
Downloads
Patches
Plain Diff
Add method to find the best scoring position from a `StripedScores`
parent
81916263
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
lightmotif/src/abc.rs
+5
-0
5 additions, 0 deletions
lightmotif/src/abc.rs
lightmotif/src/pli.rs
+45
-2
45 additions, 2 deletions
lightmotif/src/pli.rs
lightmotif/src/pwm.rs
+1
-2
1 addition, 2 deletions
lightmotif/src/pwm.rs
with
51 additions
and
4 deletions
lightmotif/src/abc.rs
+
5
−
0
View file @
1b666ede
...
...
@@ -13,6 +13,11 @@ pub trait Symbol: Default + Sized + Copy + TryFrom<char> {
pub
trait
Alphabet
:
Debug
+
Copy
+
Default
+
'static
{
type
Symbol
:
Symbol
;
const
K
:
usize
;
/// Get the default symbol for this alphabet.
fn
default_symbol
()
->
Self
::
Symbol
{
Default
::
default
()
}
}
#[derive(Clone,
Copy,
PartialEq,
Debug)]
...
...
This diff is collapsed.
Click to expand it.
lightmotif/src/pli.rs
+
45
−
2
View file @
1b666ede
...
...
@@ -257,6 +257,7 @@ impl<V: Vector, const C: usize> StripedScores<V, C> {
}
impl
<
const
C
:
usize
>
StripedScores
<
f32
,
C
>
{
/// Convert the striped scores to a vector of scores.
pub
fn
to_vec
(
&
self
)
->
Vec
<
f32
>
{
let
mut
vec
=
Vec
::
with_capacity
(
self
.length
);
for
i
in
0
..
self
.length
{
...
...
@@ -266,18 +267,37 @@ impl<const C: usize> StripedScores<f32, C> {
}
vec
}
/// Get the index of the highest scoring position.
///
/// ## Panic
/// Panics if the data buffer is empty.
pub
fn
argmax
(
&
self
)
->
usize
{
let
mut
best_pos
=
0
;
let
mut
best_score
=
self
.data
[
0
][
0
];
for
i
in
0
..
self
.length
{
let
col
=
i
/
self
.data
.rows
();
let
row
=
i
%
self
.data
.rows
();
if
self
.data
[
row
][
col
]
>
best_score
{
best_pos
=
i
;
best_score
=
self
.data
[
row
][
col
];
}
}
best_pos
}
}
#[cfg(target_feature
=
"avx2"
)]
impl
<
const
C
:
usize
>
StripedScores
<
__m256
,
C
>
{
/// Convert the striped scores to a vector of scores.
pub
fn
to_vec
(
&
self
)
->
Vec
<
f32
>
{
// NOTE(@althonos): Because in AVX2 the __m256 vector is actually
// two independent __m128, the shuffling creates
// intrication in the results.
#[rustfmt::skip]
const
COLS
:
&
[
usize
]
=
&
[
0
,
1
,
2
,
3
,
8
,
9
,
10
,
11
,
16
,
17
,
18
,
19
,
24
,
25
,
26
,
27
,
4
,
5
,
6
,
7
,
12
,
13
,
14
,
15
,
20
,
21
,
22
,
23
,
28
,
29
,
30
,
31
,
0
,
1
,
2
,
3
,
8
,
9
,
10
,
11
,
16
,
17
,
18
,
19
,
24
,
25
,
26
,
27
,
4
,
5
,
6
,
7
,
12
,
13
,
14
,
15
,
20
,
21
,
22
,
23
,
28
,
29
,
30
,
31
,
];
let
mut
col
=
0
;
...
...
@@ -293,4 +313,27 @@ impl<const C: usize> StripedScores<__m256, C> {
}
vec
}
/// Get the index of the highest scoring position.
///
/// ## Panic
/// Panics if the data buffer is empty.
pub
fn
argmax
(
&
self
)
->
usize
{
let
mut
best_pos
=
0
;
let
mut
best_score
=
self
.data
[
0
][
0
];
let
mut
col
=
0
;
let
mut
row
=
0
;
for
i
in
0
..
self
.length
{
if
self
.data
[
row
][
col
]
>
best_score
{
best_pos
=
i
;
best_score
=
self
.data
[
row
][
col
];
}
row
+=
1
;
if
row
==
self
.data
.rows
()
{
row
=
0
;
col
+=
1
;
}
}
best_pos
}
}
This diff is collapsed.
Click to expand it.
lightmotif/src/pwm.rs
+
1
−
2
View file @
1b666ede
...
...
@@ -162,11 +162,10 @@ pub struct Background<A: Alphabet, const K: usize> {
impl
<
A
:
Alphabet
,
const
K
:
usize
>
Background
<
A
,
K
>
{
pub
fn
uniform
()
->
Self
{
let
mut
frequencies
=
[
0.0
;
K
];
for
i
in
0
..
K
{
if
i
!=
A
::
default_symbol
()
.as_index
()
{
frequencies
[
i
]
=
1.0
/
((
K
-
1
)
as
f32
);
frequencies
[
i
]
=
1.0
/
((
K
-
1
)
as
f32
);
}
}
...
...
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