Пример #1
0
            i = same_subject_idxs[0][sample_pair_idx]
            j = same_subject_idxs[1][sample_pair_idx]

            sample_i = snp_samples[i]
            sample_j = snp_samples[j]
            sample_pair = (sample_i, sample_j)

            perr = diversity_utils.calculate_fixation_error_rate(
                sfs_map, sample_i, sample_j)[0]

            snp_perrs[sample_pair] = perr
            tracked_private_snp_perrs[sample_pair] = perr

            gene_changes[sample_pair].extend(
                gene_diversity_utils.calculate_gene_differences_between(
                    i, j, gene_reads_matrix, gene_depth_matrix,
                    marker_coverages))

            gene_perr = gene_diversity_utils.calculate_gene_error_rate(
                i, j, gene_reads_matrix, gene_depth_matrix,
                marker_coverages)[0]

            gene_opportunities[sample_pair] = gene_depth_matrix.shape[0]

            gene_perrs[sample_pair] = gene_perr

        sys.stderr.write("Done!\n")

        for sample_i, sample_j in snp_changes.keys():

            # First output SNPs
    if not ((snp_samples[snp_i] in haploid_samples) and
            (snp_samples[snp_j] in haploid_samples)):
        # both have to be haploids
        continue

    plower = snp_difference_matrix[snp_i, snp_j]
    pupper = plower * 1.1

    #plower,pupper = stats_utils.calculate_poisson_rate_interval(snp_difference_matrix[snp_i,snp_j], snp_opportunity_matrix[snp_i, snp_j])

    diff_subject_snp_plowers.append(plower)
    diff_subject_snp_puppers.append(pupper)

    i = diff_subject_gene_idxs[0][sample_pair_idx]
    j = diff_subject_gene_idxs[1][sample_pair_idx]
    gene_differences = gene_diversity_utils.calculate_gene_differences_between(
        i, j, gene_depth_matrix, marker_coverages, include_high_copynum=False)

    if snp_substitution_rate[snp_i, snp_j] < clade_divergence_threshold:

        for gene_idx, depth_tuple_1, depth_tuple_2 in gene_differences:
            if gene_idx not in between_host_gene_idx_map:
                between_host_gene_idx_map[gene_idx] = 0

            between_host_gene_idxs.append(gene_idx)

            between_host_gene_idx_map[gene_idx] += 1

    if snp_substitution_rate[snp_i, snp_j] < modification_divergence_threshold:
        # A modification, not a replacement!
        for gene_idx, depth_tuple_1, depth_tuple_2 in gene_differences:
            if gene_idx not in low_divergence_between_host_gene_idx_map:
    i = same_subject_snp_idxs[0][sample_pair_idx]
    j = same_subject_snp_idxs[1][sample_pair_idx]

    plower, pupper = stats_utils.calculate_poisson_rate_interval(
        snp_difference_matrix[i, j], snp_opportunity_matrix[i, j], alpha)

    same_subject_snp_plowers.append(plower)
    same_subject_snp_puppers.append(pupper)

    snp_differences = diversity_utils.calculate_snp_differences_between(
        i, j, allele_counts_map, passed_sites_map, min_change=min_change)

    i = same_subject_gene_idxs[0][sample_pair_idx]
    j = same_subject_gene_idxs[1][sample_pair_idx]
    gene_differences = gene_diversity_utils.calculate_gene_differences_between(
        i, j, gene_depth_matrix, marker_coverages, min_log2_fold_change=4)

    plower, pupper = stats_utils.calculate_poisson_rate_interval(
        gene_difference_matrix[i, j], gene_opportunity_matrix[i, j])

    same_subject_gene_plowers.append(plower)
    same_subject_gene_puppers.append(pupper)

    if (len(snp_differences) > 0) or (len(gene_differences) > 0):
        # Print them out!
        print "Changes between pair", sample_pair_idx
        print "SNPs:"
        if len(snp_differences) > 0:
            for snp_diff_idx in xrange(0, len(snp_differences)):
                print snp_differences[snp_diff_idx]
        print "Genes:"