Skip to content

Commit

Permalink
Phylogenic selection#10 (#23)
Browse files Browse the repository at this point in the history
* ENH@calculate_pss:ignore elements if desired

* UPD@ProfilesTests:Tests for ignore in Profile.calculate_pss
  • Loading branch information
dizak committed May 3, 2018
1 parent d967221 commit 2912077
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 2 deletions.
17 changes: 15 additions & 2 deletions prowler/profiles.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,13 +137,26 @@ def to_series(self,
return pd.Series(self.profile)

def calculate_pss(self,
profile):
profile,
ignore=None):
"""
Calculate Profiles Similarity Score.
"""
if len(self) != len(profile):
raise ProfileError("Different profiles' lengths")
return sum(a == b for a, b in zip(self.profile, profile.profile))
prof_1 = self
prof_2 = profile
if ignore:
for i in ignore:
try:
del prof_1.profile[prof_1.query.index(i)]
except IndexError:
raise ProfileError("Element to ignore not in profile")
try:
del prof_2.profile[prof_2.query.index(i)]
except IndexError:
raise ProfileError("Element to ignore not in profile")
return sum(a == b for a, b in zip(prof_1.profile, prof_2.profile))

def get_present(self):
"""
Expand Down
12 changes: 12 additions & 0 deletions tests/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -383,6 +383,8 @@ def setUp(self):
self.ref_profile = "-+-+++++-+++-"
self.ref_alt_profile = "#$#$$$$$#$$$#"
self.ref_pss = [13, 4, 9]
self.ref_ignore_elements = ["a", "c", "f"]
self.ref_pss_ignore = 10
self.test_profile = profiles.Profile(reference=self.ref_reference,
query=self.ref_query)

Expand Down Expand Up @@ -465,6 +467,16 @@ def test_calculate_pss(self):
query=query)),
pss)

def test_calculate_pss_ignore(self):
"""
Test if Profiles Similarity Score (PSS) is properly calculated with
ignore arg used.
"""
self.assertEqual(self.test_profile.calculate_pss(profiles.Profile(reference=self.ref_reference,
query=self.ref_query),
ignore=self.ref_ignore_elements),
self.ref_pss_ignore)

def test_get_present(self):
"""
Test if get_present returns list of present items in the profile.
Expand Down

0 comments on commit 2912077

Please sign in to comment.