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
41113b90
Commit
41113b90
authored
1 year ago
by
Martin Larralde
Browse files
Options
Downloads
Patches
Plain Diff
Add method to wrap a striped sequence
parent
475c9d0d
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/seq.rs
+56
-1
56 additions, 1 deletion
src/seq.rs
with
56 additions
and
1 deletion
src/seq.rs
+
56
−
1
View file @
41113b90
...
...
@@ -32,7 +32,7 @@ impl<A: Alphabet> EncodedSequence<A> {
/// Convert the encoded sequence to a striped matrix.
pub
fn
to_striped
<
const
C
:
usize
>
(
&
self
)
->
StripedSequence
<
A
,
C
>
{
let
length
=
self
.data
.len
();
let
n
=
(
length
+
C
)
/
C
;
let
n
=
length
/
C
+
((
length
%
C
)
!=
0
)
as
usize
;
let
mut
data
=
DenseMatrix
::
new
(
n
);
for
(
i
,
&
x
)
in
self
.data
.iter
()
.enumerate
()
{
data
[
i
%
n
][
i
/
n
]
=
x
;
...
...
@@ -41,6 +41,7 @@ impl<A: Alphabet> EncodedSequence<A> {
alphabet
:
self
.alphabet
,
data
,
length
,
wrap
:
0
,
}
}
}
...
...
@@ -55,11 +56,65 @@ impl<A: Alphabet> AsRef<EncodedSequence<A>> for EncodedSequence<A> {
pub
struct
StripedSequence
<
A
:
Alphabet
,
const
C
:
usize
=
32
>
{
pub
alphabet
:
A
,
pub
length
:
usize
,
pub
wrap
:
usize
,
pub
data
:
DenseMatrix
<
A
::
Symbol
,
C
>
,
}
impl
<
A
:
Alphabet
,
const
C
:
usize
>
StripedSequence
<
A
,
C
>
{
/// Add wrap-around rows for a motif of length `m`.
pub
fn
configure_wrap
(
&
mut
self
,
m
:
usize
)
{
if
m
>
self
.wrap
{
let
rows
=
self
.data
.rows
()
-
self
.wrap
;
self
.data
.resize
(
self
.data
.rows
()
+
m
-
self
.wrap
);
for
i
in
0
..
m
{
for
j
in
0
..
C
-
1
{
self
.data
[
rows
+
i
][
j
]
=
self
.data
[
i
][
j
+
1
];
}
}
self
.wrap
=
m
;
}
}
}
impl
<
A
:
Alphabet
,
const
C
:
usize
>
From
<
EncodedSequence
<
A
>>
for
StripedSequence
<
A
,
C
>
{
fn
from
(
encoded
:
EncodedSequence
<
A
>
)
->
Self
{
encoded
.to_striped
()
}
}
#[cfg(test)]
mod
test
{
use
super
::
*
;
use
crate
::
DnaAlphabet
;
use
crate
::
DnaSymbol
::
*
;
#[test]
fn
test_stripe
()
{
let
seq
=
EncodedSequence
::
<
DnaAlphabet
>
::
from_text
(
"ATGCA"
)
.unwrap
();
let
striped
=
seq
.to_striped
::
<
4
>
();
assert_eq!
(
striped
.data
.rows
(),
2
);
assert_eq!
(
&
striped
.data
[
0
],
&
[
A
,
G
,
A
,
N
]);
assert_eq!
(
&
striped
.data
[
1
],
&
[
T
,
C
,
N
,
N
]);
let
striped
=
seq
.to_striped
::
<
2
>
();
assert_eq!
(
striped
.data
.rows
(),
3
);
assert_eq!
(
&
striped
.data
[
0
],
&
[
A
,
C
,
]);
assert_eq!
(
&
striped
.data
[
1
],
&
[
T
,
A
,
]);
assert_eq!
(
&
striped
.data
[
2
],
&
[
G
,
N
,
]);
}
#[test]
fn
test_configure_wrap
()
{
let
seq
=
EncodedSequence
::
<
DnaAlphabet
>
::
from_text
(
"ATGCA"
)
.unwrap
();
let
mut
striped
=
seq
.to_striped
::
<
4
>
();
striped
.configure_wrap
(
2
);
assert_eq!
(
striped
.data
.rows
(),
4
);
assert_eq!
(
&
striped
.data
[
0
],
&
[
A
,
G
,
A
,
N
]);
assert_eq!
(
&
striped
.data
[
1
],
&
[
T
,
C
,
N
,
N
]);
assert_eq!
(
&
striped
.data
[
2
],
&
[
G
,
A
,
N
,
N
]);
assert_eq!
(
&
striped
.data
[
3
],
&
[
C
,
N
,
N
,
N
]);
}
}
\ No newline at end of file
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