Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
M
mhc_rank
Manage
Activity
Members
Labels
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Model registry
Operate
Environments
Terraform modules
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
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Patrick Skillman-Lawrence
mhc_rank
Commits
6a292951
Commit
6a292951
authored
6 years ago
by
Tim O'Donnell
Browse files
Options
Downloads
Patches
Plain Diff
more efficient allele encoding
parent
70c28425
Loading
Loading
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
mhcflurry/allele_encoding.py
+8
-9
8 additions, 9 deletions
mhcflurry/allele_encoding.py
test/test_allele_encoding.py
+1
-1
1 addition, 1 deletion
test/test_allele_encoding.py
with
9 additions
and
10 deletions
mhcflurry/allele_encoding.py
+
8
−
9
View file @
6a292951
...
...
@@ -54,8 +54,13 @@ class AlleleEncoding(object):
Returns
-------
numpy.array with shape (num sequences, sequence length, m) where m is
list of numpy arrays. Pass it to numpy.array to get an array with shape
(num sequences, sequence length, m) where m is
vector_encoding_length(vector_encoding_name)
The reason to return a list instead of an array is that the list can
use much less memory in the common case where many of the rows are
the same.
"""
cache_key
=
(
"
fixed_length_vector_encoding
"
,
...
...
@@ -79,16 +84,10 @@ class AlleleEncoding(object):
vector_encoded
=
amino_acid
.
fixed_vectors_encoding
(
index_encoded_matrix
,
amino_acid
.
ENCODING_DATA_FRAMES
[
vector_encoding_name
])
flattened
=
pandas
.
DataFrame
(
vector_encoded
.
reshape
(
(
len
(
allele_to_fixed_length_sequence
),
-
1
)))
encoding_shape
=
vector_encoded
.
shape
[
1
:]
else
:
# Raw values
flattened
=
allele_to_fixed_length_sequence
encoding_shape
=
(
allele_to_fixed_length_sequence
.
shape
[
1
],)
result
=
flattened
.
iloc
[
indices
].
values
.
reshape
(
(
len
(
self
.
alleles
),)
+
encoding_shape
)
vector_encoded
=
allele_to_fixed_length_sequence
.
values
result
=
[
vector_encoded
[
i
]
for
i
in
indices
]
self
.
encoding_cache
[
cache_key
]
=
result
return
self
.
encoding_cache
[
cache_key
]
...
...
This diff is collapsed.
Click to expand it.
test/test_allele_encoding.py
+
1
−
1
View file @
6a292951
...
...
@@ -55,4 +55,4 @@ def test_allele_encoding_raw_values():
[
0
,
1
,
-
1
],
[
10
,
11
,
12
],
[
0
,
1
,
-
1
],
],
encoding1
)
],
numpy
.
array
(
encoding1
)
)
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