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
8c5a4ca5
Commit
8c5a4ca5
authored
8 years ago
by
Alex Rubinsteyn
Browse files
Options
Downloads
Patches
Plain Diff
faster algorithm for converting Dataset to nested dictionary
parent
180575f6
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
mhcflurry/dataset.py
+19
-14
19 additions, 14 deletions
mhcflurry/dataset.py
with
19 additions
and
14 deletions
mhcflurry/dataset.py
+
19
−
14
View file @
8c5a4ca5
...
...
@@ -238,23 +238,28 @@ class Dataset(object):
How to combine multiple measurements for the same pMHC complex.
Takes affinities and optional `weights` argument.
"""
allele_to_peptide_to_affinity_dict
=
{}
for
allele
,
allele_dataset
in
self
.
groupby_allele
():
allele_to_peptide_to_affinities_dict
=
defaultdict
(
dict
)
allele_to_peptide_to_weights_dict
=
defaultdict
(
dict
)
key_pairs
=
set
([])
for
allele
,
peptide
,
affinity
,
weight
in
zip
(
self
.
alleles
,
self
.
peptides
,
self
.
affinities
,
self
.
sample_weights
):
# dictionary mapping each peptide to a list of affinities
peptide_to_affinity_dict
=
defaultdict
(
list
)
peptide_to_weight_dict
=
defaultdict
(
list
)
for
(
allele
,
peptide
),
row
in
allele_dataset
.
iterrows
():
affinity
=
row
[
"
affinity
"
]
sample_weight
=
row
[
"
sample_weight
"
]
peptide_to_affinity_dict
[
peptide
].
append
(
affinity
)
peptide_to_weight_dict
[
peptide
].
append
(
sample_weight
)
allele_to_peptide_to_affinity_dict
[
allele
]
=
{
if
peptide
not
in
allele_to_peptide_to_affinities_dict
[
allele
]:
allele_to_peptide_to_affinities_dict
[
allele
][
peptide
]
=
[
affinity
]
allele_to_peptide_to_weights_dict
[
allele
][
peptide
]
=
[
weight
]
else
:
allele_to_peptide_to_affinities_dict
[
allele
][
peptide
].
append
(
affinity
)
allele_to_peptide_to_weights_dict
[
allele
][
peptide
].
append
(
weight
)
key_pairs
.
add
((
allele
,
peptide
))
return
{
allele
:
{
peptide
:
combine_fn
(
peptide_to_affinit
y
_dict
[
peptide
],
peptide_to_weight_dict
[
peptide
])
for
peptide
in
peptide_to_affinit
y
_dict
.
keys
()
allele_to_
peptide_to_affinit
ies
_dict
[
allele
][
peptide
],
allele_to_
peptide_to_weight
s
_dict
[
allele
][
peptide
])
for
peptide
in
allele_to_
peptide_to_affinit
ies
_dict
[
allele
]
.
keys
()
}
return
allele_to_peptide_to_affinity_dict
for
allele
in
allele_to_peptide_to_affinities_dict
.
keys
()
}
@classmethod
def
from_sequences
(
...
...
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