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
c158d71d
Commit
c158d71d
authored
6 years ago
by
Tim O'Donnell
Browse files
Options
Downloads
Patches
Plain Diff
fixes
parent
11632aad
Loading
Loading
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
.travis.yml
+5
-1
5 additions, 1 deletion
.travis.yml
mhcflurry/allele_encoding_transforms.py
+6
-10
6 additions, 10 deletions
mhcflurry/allele_encoding_transforms.py
mhcflurry/class1_affinity_predictor.py
+13
-21
13 additions, 21 deletions
mhcflurry/class1_affinity_predictor.py
with
24 additions
and
32 deletions
.travis.yml
+
5
−
1
View file @
c158d71d
...
...
@@ -9,8 +9,10 @@ before_install:
# version is the same.
-
if [[ "$TRAVIS_PYTHON_VERSION" == "2.7" ]]; then
wget https://repo.continuum.io/miniconda/Miniconda-latest-Linux-x86_64.sh -O miniconda.sh;
export TF_PACKAGE=https://storage.googleapis.com/tensorflow/linux/cpu/tensorflow-1.10.1-cp27-none-linux_x86_64.whl
else
wget https://repo.continuum.io/miniconda/Miniconda3-latest-Linux-x86_64.sh -O miniconda.sh;
export TF_PACKAGE=https://storage.googleapis.com/tensorflow/linux/cpu/tensorflow-1.10.1-cp35-cp35m-linux_x86_64.whl
fi
-
bash miniconda.sh -b -p $HOME/miniconda
-
export PATH="$HOME/miniconda/bin:$PATH"
...
...
@@ -29,9 +31,11 @@ addons:
install
:
-
>
conda create -q -n test-environment python=$TRAVIS_PYTHON_VERSION
numpy scipy nose pandas matplotlib mkl-service
numpy scipy nose pandas matplotlib mkl-service
theano
-
source activate test-environment
-
pip install tensorflow pypandoc pylint 'theano>=1.0.4'
-
pip install pypandoc pylint
-
pip install --ignore-installed --upgrade $TF_PACKAGE
-
pip install -r requirements.txt
-
pip install .
-
pip freeze
...
...
This diff is collapsed.
Click to expand it.
mhcflurry/allele_encoding_transforms.py
+
6
−
10
View file @
c158d71d
...
...
@@ -25,13 +25,13 @@ class AlleleEncodingTransform(object):
Parameters
----------
fit : string to
DataFrame
fit : string to
array
"""
class
PCATransform
(
AlleleEncodingTransform
):
name
=
'
pca
'
serialization_keys
=
[
'
data
'
]
serialization_keys
=
[
'
mean
'
,
'
components
'
]
def
__init__
(
self
):
self
.
model
=
None
...
...
@@ -51,19 +51,15 @@ class PCATransform(AlleleEncodingTransform):
print
(
"
Fit complete in %0.3f sec.
"
%
(
time
.
time
()
-
start
))
def
get_fit
(
self
):
df
=
pandas
.
DataFrame
(
self
.
model
.
components_
)
df
.
columns
=
[
"
pca_%s
"
%
c
for
c
in
df
.
columns
]
df
[
"
mean
"
]
=
self
.
model
.
mean_
return
{
'
data
'
:
df
'
mean
'
:
self
.
model
.
mean_
,
'
components
'
:
self
.
model
.
components_
,
}
def
restore_fit
(
self
,
fit
):
assert
list
(
fit
)
==
[
'
data
'
]
data
=
fit
[
"
data
"
]
self
.
model
=
sklearn
.
decomposition
.
PCA
()
self
.
model
.
mean_
=
data
[
"
mean
"
]
.
values
self
.
model
.
components_
=
data
.
drop
(
columns
=
"
mean
"
).
values
self
.
model
.
mean_
=
fit
[
"
mean
"
]
self
.
model
.
components_
=
fit
[
"
components
"
]
def
transform
(
self
,
allele_representations
):
if
not
self
.
is_fit
():
...
...
This diff is collapsed.
Click to expand it.
mhcflurry/class1_affinity_predictor.py
+
13
−
21
View file @
c158d71d
...
...
@@ -368,12 +368,9 @@ class Class1AffinityPredictor(object):
if
transform
.
is_fit
():
fit_data
=
transform
.
get_fit
()
assert
set
(
fit_data
)
==
set
(
transform
.
serialization_keys
)
for
(
serialization_key
,
fit_df
)
in
fit_data
.
items
():
csv_path
=
join
(
models_dir
,
"
%s.%s.csv
"
%
(
transform
.
name
,
serialization_key
))
fit_df
.
to_csv
(
csv_path
)
logging
.
info
(
"
Wrote: %s
"
%
csv_path
)
target_path
=
join
(
models_dir
,
"
%s.npz
"
%
transform
.
name
)
numpy
.
savez
(
target_path
,
**
fit_data
)
logging
.
info
(
"
Wrote: %s
"
%
target_path
)
if
self
.
allele_to_percent_rank_transform
:
percent_ranks_df
=
None
...
...
@@ -447,15 +444,11 @@ class Class1AffinityPredictor(object):
for
transform_name
in
ALLELE_ENCODING_TRANSFORMS
:
klass
=
ALLELE_ENCODING_TRANSFORMS
[
transform_name
]
transform
=
klass
()
restored_fit
=
{}
for
serialization_key
in
klass
.
serialization_keys
:
csv_path
=
join
(
models_dir
,
"
%s.%s.csv
"
%
(
transform_name
,
serialization_key
))
if
exists
(
csv_path
):
restored_fit
[
serialization_key
]
=
pandas
.
read_csv
(
csv_path
,
index_col
=
0
)
if
restored_fit
:
target_path
=
join
(
models_dir
,
"
%s.npz
"
%
transform_name
)
if
exists
(
target_path
):
with
numpy
.
load
(
target_path
)
as
loaded
:
restored_fit
=
dict
(
(
key
,
loaded
[
key
])
for
key
in
loaded
.
keys
())
if
set
(
restored_fit
)
!=
set
(
klass
.
serialization_keys
):
logging
.
warning
(
"
Missing some allele encoding transform serialization
"
...
...
@@ -1116,12 +1109,11 @@ class Class1AffinityPredictor(object):
----------
list of array
"""
loaded
=
numpy
.
load
(
filename
)
weights
=
[
loaded
[
"
array_%d
"
%
i
]
for
i
in
range
(
len
(
loaded
.
keys
()))
]
loaded
.
close
()
with
numpy
.
load
(
filename
)
as
loaded
:
weights
=
[
loaded
[
"
array_%d
"
%
i
]
for
i
in
range
(
len
(
loaded
.
keys
()))
]
return
weights
def
calibrate_percentile_ranks
(
...
...
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