def test_compare_profiles_not_shared(self): '''Normalizing with a profile containing not_shared and one without''' result = compare_profiles(self.not_shared_profiles) exresult = {'taxa1': 0.10, 'taxa2': 0.30, 'taxa3': 0.15, 'taxa4': 0.25, 'not_shared': 0.20} #make sure the keys in each are the same self.assertEquals(set(result.keys()), set(exresult.keys())) #make sure the values are correct-ish for key in result: self.assertAlmostEquals(result[key], exresult[key])
def bootstrap_profiles(profiles, alpha=0.05, repetitions=1000, randfunc=randint): """Performs bootstrapping over the sample 'profiles' Inputs: profiles: list of profiles alpha: defines the confidence interval as 1 - alpha repetitions: number of bootstrap iterations randfunc: random function for generate the bootstrap samples Returns: profile: the bootstrapped profile of the profiles list sample_mean: the bootstrap mean of the amount shared sample_stdev: the bootstrap standard deviation of the amount shared ci: the confidence interval for the bootstrap mean """ length = len(profiles) normalize_profiles(profiles) boot_shared = [] boot_profiles = [] for i in range(repetitions): # Construct the bootstrap sample resample = [profiles[randfunc(0, length)] for j in range(length)] profile = compare_profiles(resample) # Store the amount shared boot_shared.append(1.0 - profile['not_shared']) # Store the result profile boot_profiles.append(profile) # Convert data to a numpy array boot_shared = array(boot_shared) # Get the mean and the standard deviation of the shared data sample_mean = mean(boot_shared) sample_stdev = std(boot_shared) # Compute the confidence interval for the bootstrapped data # using bootstrap percentile interval ci = quantile(boot_shared, [alpha / 2, 1 - (alpha / 2)]) # Compute the bootstrapped profile of the profiles list profile = compare_profiles(profiles) return profile, 1.0 - profile['not_shared'], sample_stdev, ci
def test_compare_profiles(self): '''Comparing three profiles, testing when each are the min and when\ one taxa is equal ''' result = compare_profiles(self.many_profiles) exresult = {'taxa1': 0.10, 'taxa2': 0.22, 'taxa3': 0.15, 'taxa4': 0.25, 'not_shared': 0.28} #make sure the keys in each are the same self.assertEquals(set(result.keys()), set(exresult.keys())) #make sure the values are correct-ish for key in result: self.assertAlmostEquals(result[key], exresult[key])
def bootstrap_profiles(profiles, alpha=0.05, repetitions=1000, randfunc=randint): """Performs bootstrapping over the sample 'profiles' Inputs: profiles: list of profiles alpha: defines the confidence interval as 1 - alpha repetitions: number of bootstrap iterations randfunc: random function for generate the bootstrap samples Returns: profile: the bootstrapped profile of the profiles list sample_mean: the bootstrap mean of the amount shared sample_stdev: the bootstrap standard deviation of the amount shared ci: the confidence interval for the bootstrap mean """ length = len(profiles) normalize_profiles(profiles) boot_shared = [] boot_profiles = [] for i in range(repetitions): # Construct the bootstrap sample resample = [profiles[randfunc(0, length)] for j in range(length)] profile = compare_profiles(resample) # Store the amount shared boot_shared.append(1.0 - profile['not_shared']) # Store the result profile boot_profiles.append(profile) # Convert data to a numpy array boot_shared = array(boot_shared) # Get the mean and the standard deviation of the shared data sample_mean = mean(boot_shared) sample_stdev = std(boot_shared) # Compute the confidence interval for the bootstrapped data # using bootstrap percentile interval ci = quantile(boot_shared, [alpha/2, 1-(alpha/2)]) # Compute the bootstrapped profile of the profiles list profile = compare_profiles(profiles) return profile, 1.0-profile['not_shared'], sample_stdev, ci
def test_compare_profiles_not_shared(self): '''Normalizing with one profile containing not_shared and one without''' result = compare_profiles(self.not_shared_profiles) exresult = { 'taxa1': 0.10, 'taxa2': 0.30, 'taxa3': 0.15, 'taxa4': 0.25, 'not_shared': 0.20 } #make sure the keys in each are the same self.assertEquals(set(result.keys()), set(exresult.keys())) #make sure the values are correct-ish for key in result: self.assertAlmostEquals(result[key], exresult[key])
def test_compare_profiles(self): '''Comparing three profiles, testing when each are the min and when\ one taxa is equal ''' result = compare_profiles(self.many_profiles) exresult = { 'taxa1': 0.10, 'taxa2': 0.22, 'taxa3': 0.15, 'taxa4': 0.25, 'not_shared': 0.28 } #make sure the keys in each are the same self.assertEquals(set(result.keys()), set(exresult.keys())) #make sure the values are correct-ish for key in result: self.assertAlmostEquals(result[key], exresult[key])