def build_cytoplasmic_statistics(analysis_repo, statistics_type, molecule_type, genes, keyorder): gene2stat, gene2median, gene2error, gene2confidence_interval = {}, {}, {}, {} for gene in genes: logger.info("Running {} cytoplasmic {} analysis for {}", molecule_type, statistics_type, gene) image_set = ImageSet(analysis_repo, ['{0}/{1}/'.format(molecule_type, gene)]) if statistics_type == 'centrality': if molecule_type == 'mrna': gene2stat[ gene] = image_set.compute_cytoplasmic_spots_centrality() else: gene2stat[ gene] = image_set.compute_cytoplasmic_intensities_centrality( ) if statistics_type == 'spread': if molecule_type == 'mrna': gene2stat[gene] = image_set.compute_cytoplasmic_spots_spread() else: gene2stat[ gene] = image_set.compute_intensities_cytoplasmic_spread() if statistics_type == 'centrality': gene2median[gene] = np.mean(gene2stat[gene]) gene2error[gene] = helpers.sem(gene2stat[gene], factor=0) lower, higher = helpers.median_confidence_interval(gene2stat[gene]) gene2confidence_interval[gene] = [lower, higher] if statistics_type == 'spread': max_entropy = np.max([np.max(gene2stat[k]) for k in gene2stat.keys()]) for gene in gene2stat.keys(): gene2stat[gene] = gene2stat[gene] / max_entropy gene2median[gene] = np.median(gene2stat[gene]) gene2error[gene] = helpers.sem(gene2stat[gene], factor=0) lower, higher = helpers.median_confidence_interval(gene2stat[gene]) gene2confidence_interval[gene] = [lower, higher] gene2stat = collections.OrderedDict( sorted(gene2stat.items(), key=lambda i: keyorder.index(i[0]))) gene2median = collections.OrderedDict( sorted(gene2median.items(), key=lambda i: keyorder.index(i[0]))) gene2error = collections.OrderedDict( sorted(gene2error.items(), key=lambda i: keyorder.index(i[0]))) gene2confidence_interval = collections.OrderedDict( sorted(gene2confidence_interval.items(), key=lambda i: keyorder.index(i[0]))) return gene2median, gene2stat, gene2error, gene2confidence_interval
def test_compute_intensities_cytoplasmic_spread(self): image_set = ImageSet(self.repo, path_list=['protein/arhgdia/2h/']) result = np.sort(image_set.compute_intensities_cytoplasmic_spread()) self.assertAlmostEqual(result.sum(), 3.0812597654, places=5) self.assertAlmostEqual(result[1], 0.611584381, places=5)