-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
190 additions
and
87 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,5 @@ | ||
""" | ||
This module contains a class for describing read identity distributions (described by the beta | ||
distribution) and related functions. | ||
This module contains a class for describing read identity distributions and related functions. | ||
Copyright 2018 Ryan Wick ([email protected]) | ||
https://github.com/rrwick/Badread | ||
|
@@ -23,19 +22,34 @@ | |
class Identities(object): | ||
|
||
def __init__(self, mean, stdev, max_identity, output=sys.stderr): | ||
self.mean, self.stdev, self.max_identity = None, None, None | ||
self.beta_a, self.beta_b = None, None | ||
|
||
print('', file=output) | ||
|
||
# There are two possible types of identity distributions: a three-parameter beta | ||
# distribution that describes read identities, or a two-parameter normal distribution that | ||
# describes read qscores. | ||
if max_identity is None: | ||
self.type = "normal" | ||
self.set_up_normal(mean, stdev, output) | ||
else: | ||
self.type = "beta" | ||
self.set_up_beta(mean, stdev, max_identity, output) | ||
|
||
def set_up_beta(self, mean, stdev, max_identity, output): | ||
# Divide by 100 to convert from percentage to fraction | ||
self.mean = mean / 100.0 | ||
self.stdev = stdev / 100.0 | ||
self.max_identity = max_identity / 100.0 | ||
print('', file=output) | ||
|
||
if self.mean == self.max_identity: | ||
self.beta_a, self.beta_b = None, None | ||
print(f'Using a constant read identity of {self.mean * 100}%', file=output) | ||
elif self.stdev == 0.0: | ||
self.max_identity = self.mean | ||
print(f'Using a constant read identity of {self.mean * 100}%', file=output) | ||
else: # beta distribution | ||
else: | ||
print('Generating read identities from a beta distribution:', file=output) | ||
self.beta_a, self.beta_b = beta_parameters(mean, stdev, max_identity) | ||
print_in_two_columns(f' mean = {float_to_str(self.mean * 100):>3}%', | ||
|
@@ -47,12 +61,37 @@ def __init__(self, mean, stdev, max_identity, output=sys.stderr): | |
output=output) | ||
quickhist_beta(self.beta_a, self.beta_b, self.max_identity, 8, output=output) | ||
|
||
def set_up_normal(self, mean, stdev, output): | ||
self.mean = mean | ||
self.stdev = stdev | ||
|
||
if self.stdev == 0.0: | ||
self.max_identity = self.mean | ||
print(f'Using a constant read qscore of {self.mean}', file=output) | ||
else: | ||
print('Generating read qscores from a normal distribution:', file=output) | ||
print(f' mean = {float_to_str(self.mean):>3}', file=output) | ||
print(f' stdev = {float_to_str(self.stdev):>3}', file=output) | ||
|
||
def get_identity(self): | ||
while True: | ||
if self.type == "beta": | ||
identity = self.get_beta_identity() | ||
else: | ||
identity = self.get_normal_identity() | ||
if 0 <= identity <= 100: | ||
return identity | ||
|
||
def get_beta_identity(self): | ||
if self.mean == self.max_identity: | ||
return self.mean | ||
else: # beta distribution | ||
return self.max_identity * np.random.beta(self.beta_a, self.beta_b) | ||
|
||
def get_normal_identity(self): | ||
qscore = np.random.normal(self.mean, self.stdev) | ||
return 1.0 - 10**(-qscore / 10) | ||
|
||
|
||
def beta_parameters(beta_mean, beta_stdev, beta_max): | ||
u, s, m = beta_mean, beta_stdev, beta_max | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,4 +14,4 @@ | |
If not, see <http://www.gnu.org/licenses/>. | ||
""" | ||
|
||
__version__ = '0.3.0' | ||
__version__ = '0.4.0' |
Oops, something went wrong.