Ejemplo n.º 1
0
 def __scoring_function_field(selected=None):
     options = {'value': selected or '',
                'options': [(u'frag', u'Min Fragment Length'),
                           (u'cuts', u'Most Cuts')]}
     if h.wowo('show_enzyme_price_bins'):
         options['options'].append((u'cost_bin', u'Cost Tier'))
     else:
         options['options'].append((u'cpu',u'Cuts/Cost'))
     return options
Ejemplo n.º 2
0
 def __multi_scoring_function_field(selected=None):
     options = {'value': selected or '',
                'options': [(u'multi_mean', u'Mean Fragment Length'),
                            (u'cuts', u'Most Cuts'),
                            (u'multi_similar', u'Fragment Length Similarity')]}
     
     if h.wowo('show_enzyme_price_bins'):
         options['options'].insert(2, (u'cost_bin',u'Cost Tier'))
     else:
         options['options'].insert(2, (u'cpu',u'Cuts/Cost'))
     
     return options
Ejemplo n.º 3
0
 def __before__(self):
     if not h.wowo("show_assays"):
         abort(403)
Ejemplo n.º 4
0
    def view(self, id=None, *args, **kwargs):
        file_ok = False
        qlwell = None
        try:
            qlwell = self.__qlwell_from_threshold_form(id)
            file_ok = True
        except IOError:
            path = self.__plate_path()
            session['flash'] = "Could not read file: %s" % path
            session['flash_class'] = 'error'

        
        # this may be easier/more efficient to ascertain via direct SQL, but going ORM route
        well_ids = Session.query(QLBWell.id, QLBWell.well_name).filter(and_(QLBWell.plate_id == c.well.plate_id,
                                                      QLBWell.file_id != None)).\
                                          order_by(QLBWell.id).all()
        
        current_idx = -1
        for idx, (id, well_name) in enumerate(well_ids):
            if c.well.id == id:
                current_idx = idx
                break
        
        if current_idx == 0:
            c.prev_well_id = None
            c.prev_well_name = None
        else:
            c.prev_well_id, c.prev_well_name = well_ids[current_idx-1]
        
        if current_idx == len(well_ids)-1:
            c.next_well_id = None
            c.next_well_name = None
        else:
            c.next_well_id, c.next_well_name = well_ids[current_idx+1]
        
        thresholds = [self.form_result['fam_threshold'], self.form_result['vic_threshold']]
        c.fam_threshold, c.vic_threshold = thresholds
        for i, t in enumerate(thresholds):
            if t == 0:
                thresholds[i] = None
        
        max_amplitudes = [self.form_result['max_fam_amplitude'], self.form_result['max_vic_amplitude']]
        c.max_fam_amplitude, c.max_vic_amplitude = max_amplitudes

        if file_ok and qlwell:
            # get at well first
            statistics, cluster_data = stats_for_qlp_well(qlwell, compute_clusters=True, override_thresholds=thresholds)
            fam_cnv = get_cnv(statistics[0].positives, statistics[0].negatives,
                              statistics[1].positives, statistics[1].negatives,
                              reference_copies=statistics.ref_copy_num)
            vic_cnv = get_cnv(statistics[1].positives, statistics[1].negatives,
                              statistics[0].positives, statistics[0].negatives,
                              reference_copies=statistics.ref_copy_num)

            c.cluster_data = cluster_data
            c.statistics = statistics
            c.fam_cnv = fam_cnv
            c.vic_cnv = vic_cnv
            c.alg_version = statistics.alg_version

            if h.wowo('numpy.well_frag') and hasattr(c, 'cluster_data'):
                from qtools.lib.nstats import frag
                from pyqlb.nstats import chisquare_2d, zscore_2d, linkage_2d, balance_score_2d
                from pyqlb.nstats.well import BSCORE_MINIMUM_CLUSTER_SIZE
                n00 = len(c.cluster_data['negative_peaks']['negative_peaks'])
                n01 = len(c.cluster_data['negative_peaks']['positive_peaks'])
                n10 = len(c.cluster_data['positive_peaks']['negative_peaks'])
                n11 = len(c.cluster_data['positive_peaks']['positive_peaks'])

                frag_stats = frag.prob_of_frag(n10,n11,n00,n01,
                                               statistics[0].positives+statistics[0].negatives)
                c.frag_stats = frag_stats

                chi_stat, chi_p = chisquare_2d(n11,n10,n01,n00,
                                               yates_correction=True)
                c.chi_stat = chi_stat
                c.chi_p = chi_p

                z_fpvn, z_fpvp_vn, z_fpvp_fn, z_fnvp = \
                    zscore_2d(n11,n10,n01,n00)

                c.zscores = (z_fpvn, z_fpvp_vn, z_fpvp_fn, z_fnvp)
                c.linkage = linkage_2d(n11,n10,n01,n00)

                c.bscore =  balance_score_2d(n00,n01,n10,n11)[0]
                #if n00 >= BSCORE_MINIMUM_CLUSTER_SIZE \
                #   and n01 >= BSCORE_MINIMUM_CLUSTER_SIZE \
                #   and n10 >= BSCORE_MINIMUM_CLUSTER_SIZE \
                #   and n11 >= BSCORE_MINIMUM_CLUSTER_SIZE:
               
        return render('/well/view.html')