Skip to content

Commit

Permalink
WiP - Expanding uses of attributes for scoring
Browse files Browse the repository at this point in the history
This is a tentative approach at expanding the uses of attributes as part of the scoring, includes a minimal test case but is still missing other categories for these could be present (not_fragmentary and the main requirements), currently these are only tested for the scoring section and minimally with this commit for the as_requirements section.
  • Loading branch information
ljyanesm committed Mar 30, 2021
1 parent 9a6575a commit 9818359
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 4 deletions.
10 changes: 7 additions & 3 deletions Mikado/loci/locus.py
Original file line number Diff line number Diff line change
Expand Up @@ -580,9 +580,13 @@ def _check_as_requirements(self, transcript: Transcript, is_reference=False) ->
evaluated = dict()
for key in section.parameters:
name = section.parameters[key].name
value = operator.attrgetter(name)(transcript)
if "external" in key:
value = value[0]
if 'attributes' in name:
name_parts = name.split('.')
value = transcript.attributes[name_parts[1]]
else:
value = operator.attrgetter(name)(transcript)
if "external" in key:
value = value[0]

evaluated[key] = self.evaluate(value, section.parameters[key])
# pylint: disable=eval-used
Expand Down
15 changes: 14 additions & 1 deletion Mikado/tests/test_external_scores.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import unittest

from .. import create_default_logger
from .._transcripts.scoring_configuration import ScoringFile, MinMaxScore
from .._transcripts.scoring_configuration import ScoringFile, MinMaxScore, SizeFilter
from ..loci import Transcript, Superlocus
import pkg_resources
import os
Expand Down Expand Up @@ -185,3 +185,16 @@ def test_attribute_use_raw_percentage(self):
sup.get_metrics()
self.assertIn("attributes.tpm", sup._metrics[self.transcript.id])
self.assertEqual(sup._metrics[self.transcript.id]["attributes.tpm"], 0.1)
sup.define_loci()

def test_attribute_use_as_alternative_splicing(self):
from Mikado.loci import Locus
checked_conf = self.conf.copy()
self.transcript.attributes['cov'] = 10
loci = Locus(self.transcript, configuration=checked_conf)
loci.configuration.scoring.as_requirements.parameters['attributes.cov'] = SizeFilter(operator='ge', value=3,
metric=None,
name='attributes.cov')
loci.configuration.scoring.as_requirements.expression = [
loci.configuration.scoring.as_requirements.expression[0] + ' and attributes.cov']
loci._check_as_requirements(self.transcript)

1 comment on commit 9818359

@ljyanesm
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @lucventurini,

Maybe we can continue development of this feature in this branch? How do you find this approach?

Please sign in to comment.