@@ -0,0 +1,1679 @@
+__author__ = 'olga'%0Aimport pandas as pd%0Aimport re%0Aimport numpy as np%0A%0A%0Adef counts_pair_to_ints(x):%0A    x = x.split(':')%0A    isoforms = tuple(map(int, x%5B0%5D.strip('()').split(',')))%0A    counts = int(x%5B1%5D.rstrip(','))%0A    return isoforms, counts%0A%0A%0Adef counts_col_to_dict(counts):%0A    return dict(map(counts_pair_to_ints, re.findall('%5C(%5Cd,%5Cd%5C):%5Cd+,?', counts)))%0A%0A%0Adef filter_miso_summary(summary, ci_halves_max_thresh=0.2,%0A                        specific_isoform_counts_thresh=10):%0A    %22%22%22Filter a MISO summary dataframe created by gscripts.outputParsers%0A    .parseMiso.read_miso_summary on the maximum confidence interval half%0A    size, and number of %22junction reads%22 (reads that are specific to one%0A    isoform)%0A%0A    Parameters%0A    ----------%0A    summary : pandas.DataFrame%0A        A %22tall%22 dataframe of all samples and splice types%0A%0A    Returns%0A    -------%0A%0A%0A    Raises%0A    ------%0A    %22%22%22%0A    summary = summary.ix%5Bsummary.ci_halves_max %3C= ci_halves_max_thresh%5D%0A    isoform_counts = pd.DataFrame.from_dict(dict(zip(summary.index,%0A                                                     summary.counts.map(%0A                                                         counts_col_to_dict).values)),%0A                                            orient='index')%0A%0A    # Get counts that support only one specific isoform %22junction reads%22%0A    specific_isoform_counts = isoform_counts.ix%5B:, %5B0, 3%5D%5D.sum(axis=1)%0A%0A    # Filter on at least 10 %22junction reads%22%0A    summary = summary.ix%5B%0A        specific_isoform_counts %3E= specific_isoform_counts_thresh%5D%0A%0A    # Set the index as just the range now that we've filtered everything out%0A    summary.index = np.arange(summary.shape%5B0%5D)%0A    return summary%0A%0A

add tools for filtering miso summaries