Calculate the segmentation of the strain data for analysis from
        the command line options.
518512
def from_cli_single_ifo(cls, opt, strain, ifo):
        
        return cls(strain, segment_length=opt.segment_length[ifo],
                   segment_start_pad=opt.segment_start_pad[ifo],
                   segment_end_pad=opt.segment_end_pad[ifo],
                   trigger_start=opt.trig_start_time[ifo],
                   trigger_end=opt.trig_end_time[ifo],
                   filter_inj_only=opt.filter_inj_only,
                   allow_zero_padding=opt.allow_zero_padding)
1291735
private static List<Segmentation> getSegmentations(String str, int begin, int end, int nbMaxComponents, int minComponentSize, List<CuttingPoint> cuttingPoints) {
		List<Segmentation> s = new ArrayList<Segmentation>(nbMaxComponents);
		for(CuttingPoint cp:getPossibleCuttingPoints(str, begin, end, nbMaxComponents, minComponentSize)) {
			s.add(new Segmentation(str, addToDuplicate(cuttingPoints, cp, nbMaxComponents - 1)));
			if(nbMaxComponents > 2) {
				if(cp.isHypen())
					// recursivity on the left part only if the cp was an hypen
					if((cp.getIndex() - begin) >= 2*minComponentSize)
						s.addAll(getSegmentations(str, begin, cp.getIndex(), nbMaxComponents -1, minComponentSize, addToDuplicate(cuttingPoints, cp, nbMaxComponents - 1)));
				
				if((end - (cp.getIndex() + cp.getOffset())) >= 2*minComponentSize)
					s.addAll(getSegmentations(str, cp.getIndex() + cp.getOffset(), end, nbMaxComponents -1, minComponentSize, addToDuplicate(cuttingPoints, cp, nbMaxComponents - 1)));
			}
		}
		return s;
	}
296718
def main():
    
    parser = argparse.ArgumentParser(
        description='Performs classification/regression from the command-line. Calls JVM start/stop automatically.')
    parser.add_argument("-j", metavar="classpath", dest="classpath", help="additional classpath, jars/directories")
    parser.add_argument("-X", metavar="heap", dest="heap", help="max heap size for jvm, e.g., 512m")
    parser.add_argument("-t", metavar="train", dest="train", required=True, help="Training set file")
    parser.add_argument("-T", metavar="test", dest="test", help="Test set file")
    parser.add_argument("-c", metavar="class index", dest="classindex", help="1-based class attribute index")
    parser.add_argument("-d", metavar="outmodel", dest="outmodel", help="model output file name")
    parser.add_argument("-l", metavar="inmodel", dest="inmodel", help="model input file name")
    parser.add_argument("-x", metavar="num folds", dest="numfolds", help="number of folds for cross-validation")
    parser.add_argument("-s", metavar="seed", dest="seed", help="seed value for randomization")
    parser.add_argument("-v", action="store_true", dest="notrainstats", help="no statistics for training")
    parser.add_argument("-o", action="store_true", dest="onlystats", help="only statistics, don't output model")
    parser.add_argument("-i", action="store_true", dest="irstats", help="output information retrieval statistics")
    parser.add_argument("-k", action="store_true", dest="itstats", help="output information theoretic statistics")
    parser.add_argument("-m", metavar="costmatrix", dest="costmatrix", help="cost matrix file")
    parser.add_argument("-g", metavar="graph", dest="graph", help="output file for graph (if supported)")
    parser.add_argument("classifier", help="classifier classname, e.g., weka.classifiers.trees.J48")
    parser.add_argument("option", nargs=argparse.REMAINDER, help="additional classifier options")
    parsed = parser.parse_args()
    jars = []
    if parsed.classpath is not None:
        jars = parsed.classpath.split(os.pathsep)
    params = []
    if parsed.train is not None:
        params.extend(["-t", parsed.train])
    if parsed.test is not None:
        params.extend(["-T", parsed.test])
    if parsed.classindex is not None:
        params.extend(["-c", parsed.classindex])
    if parsed.outmodel is not None:
        params.extend(["-d", parsed.outmodel])
    if parsed.inmodel is not None:
        params.extend(["-l", parsed.inmodel])
    if parsed.numfolds is not None:
        params.extend(["-x", parsed.numfolds])
    if parsed.seed is not None:
        params.extend(["-s", parsed.seed])
    if parsed.notrainstats:
        params.append("-v")
    if parsed.onlystats:
        params.append("-o")
    if parsed.irstats:
        params.append("-i")
    if parsed.itstats:
        params.append("-k")
    if parsed.costmatrix is not None:
        params.extend(["-m", parsed.costmatrix])
    if parsed.graph is not None:
        params.extend(["-g", parsed.graph])

    jvm.start(jars, max_heap_size=parsed.heap, packages=True)

    logger.debug("Commandline: " + join_options(sys.argv[1:]))

    try:
        classifier = Classifier(classname=parsed.classifier)
        if len(parsed.option) > 0:
            classifier.options = parsed.option
        print(Evaluation.evaluate_model(classifier, params))
    except Exception, e:
        print(e)
    finally:
        jvm.stop()
335417
def segment(f, output, target_duration, mpegts):
    """"""
    try:
        target_duration = int(target_duration)
    except ValueError:
        exit('Error: Invalid target duration.')

    try:
        mpegts = int(mpegts)
    except ValueError:
        exit('Error: Invalid MPEGTS value.')

    WebVTTSegmenter().segment(f, output, target_duration, mpegts)
531030
def _calc_strain(self, loc_input, loc_layer, motion, *args):
        """"""
        strain_max = self._calc_strain_max(loc_input, loc_layer, motion, *args)
        return self.strain_ratio * strain_max
831249
def segmentation_images(self,*args,**kwargs):
        
        if not self.db: raise ValueError("Need to set db")
        segs = SegmentationImages.read_cellframe(self,*args,**kwargs)
        segs.microns_per_pixel = segs.microns_per_pixel
        return segs
1337966
def run_analysis(self, argv):
        """"""
        args = self._parser.parse_args(argv)
        obs = BinnedAnalysis.BinnedObs(irfs=args.irfs,
                                       expCube=args.expcube,
                                       srcMaps=args.cmap,
                                       binnedExpMap=args.bexpmap)

        like = BinnedAnalysis.BinnedAnalysis(obs,
                                             optimizer='MINUIT',
                                             srcModel=GtSrcmapsCatalog.NULL_MODEL,
                                             wmap=None)

        source_factory = pyLike.SourceFactory(obs.observation)
        source_factory.readXml(args.srcmdl, BinnedAnalysis._funcFactory,
                               False, True, True)

        srcNames = pyLike.StringVector()
        source_factory.fetchSrcNames(srcNames)

        min_idx = args.srcmin
        max_idx = args.srcmax
        if max_idx < 0:
            max_idx = srcNames.size()

        for i in xrange(min_idx, max_idx):
            if i == min_idx:
                like.logLike.saveSourceMaps(args.outfile)
                pyLike.CountsMapBase.copyAndUpdateDssKeywords(args.cmap,
                                                              args.outfile,
                                                              None,
                                                              args.irfs)

            srcName = srcNames[i]
            source = source_factory.releaseSource(srcName)
            like.logLike.addSource(source, False)
            like.logLike.saveSourceMap_partial(args.outfile, source)
            like.logLike.deleteSource(srcName)

        if args.gzip:
            os.system("gzip -9 %s" % args.outfile)
951569
def SegmentMean(a, ids):
    
    func = lambda idxs: np.mean(a[idxs], axis=0)
    return seg_map(func, a, ids),
398444
def set_segmentation_context(self, apdu):
        """"""
        if _debug: SSM._debug("set_segmentation_context %s", repr(apdu))

        # set the context
        self.segmentAPDU = apdu
712521
def main(args=None):
    """"""
    if args is None:
        args = sys.argv[1:]

    parser = argparse.ArgumentParser(
        description='Makes UCL PHAS results better')
    parser.add_argument('--input', '-i',
                        type=str, help="csv file to import")
    parser.add_argument('--format', '-f', type=str,
                        help="reformats results by module and exports it to file specified")
    parser.add_argument('--plot', '-p', action='store_true',
                        help="plot the module results")
    parser.add_argument('--exportplots', '-ep', type=str,
                        help="export all plots to /path/you/want/")
    parser.add_argument('--showplots', '-sp',
                        action='store_true', help="show all plots")
    parser.add_argument(
        '--my', '-m', action="store_true", help="returns your weighted average for the year")
    parser.add_argument('--year', '-y', help="specify your year")
    parser.add_argument('--rank', '-r', action='store_true',
                        help="returns your rank in the year")
    parser.add_argument('--candidate', '-c',
                        help="specify your candidate number")
    args = parser.parse_args()

    #########################
    #                       #
    #         end           #
    #       argparse        #
    #                       #
    #                       #
    #########################
    resultr.main(args)
267803
def _calc_strain_max(self, loc_input, loc_layer, motion, *args):
        """"""
        return motion.calc_peak(
            self.calc_strain_tf(loc_input, loc_layer))
872814
def main(argString=None):
    
    # Getting and checking the options
    args = parseArgs(argString)
    checkArgs(args)

    logger.info("Options used:")
    for key, value in vars(args).iteritems():
        logger.info("  --{} {}".format(key.replace("_", "-"), value))

    # Checks the sample raw data
    logger.info("Checking the raw data files")
    sample_files = check_sample_files(args.bfile + ".fam", args.raw_dir)

    # Finds the markers to extract
    logger.info("Creating extraction list (autosome only)")
    create_extraction_file(args.bfile + ".bim", args.out)

    # Run plink
    logger.info("Computing frequency using Plink")
    run_plink(args.bfile, args.out, args.out + ".to_extract")

    # Run bafRegress
    logger.info("Running bafRegress")
    if args.sge:
        run_bafRegress_sge(sample_files, args.out, args.out + ".to_extract",
                           args.out + ".frq", args)
    else:
        run_bafRegress(sample_files, args.out, args.out + ".to_extract",
                       args.out + ".frq", args)
818286
def calculate_metrics(self, analysis_set = '', analysis_directory = None, drop_missing = True, case_n_cutoff = 5, verbose = True):
        ''''''

        dataframe = self.dataframe
        if drop_missing:
            dataframe = dataframe.dropna(subset=['Predicted'])

        if self.calculate_scalar_adjustments:
            scalar_adjustment = self.scalar_adjustments[analysis_set]
        experimental_field = BenchmarkRun.get_analysis_set_fieldname('Experimental', analysis_set)

        self.metric_latex_objects.append( lr.LatexPageSection('Data tables', None, True) )
        intro_text = lr.LatexText( text = self.ddg_analysis_type_description )
        header_row = ['Statistic name', '{Value}', 'p-value']
        stats_column_format = ['l', 'S[table-format=3.2]', 'l']

        if self.include_derived_mutations:
            running_analysis_str = '\nDerived mutations in analysis are included):'
        else:
            running_analysis_str = '\nDerived mutations in analysis are omitted):'
        intro_text.add_text(running_analysis_str)
        if verbose:
            self.report(running_analysis_str, fn = colortext.message)

        classification_cutoffs_str = 'The stability classification cutoffs are: Experimental=%0.2f kcal/mol, Predicted=%0.2f energy units.' % (self.stability_classication_x_cutoff, self.stability_classication_y_cutoff)
        intro_text.add_text( classification_cutoffs_str )
        if verbose:
            self.report(classification_cutoffs_str, fn = colortext.warning)

        self.metric_latex_objects.append( intro_text )

        amino_acid_details, CAA, PAA, HAA = self.amino_acid_details, self.CAA, self.PAA, self.HAA

        # This dict is used for the print-statement below
        volume_groups = {}
        for aa_code, aa_details in amino_acid_details.iteritems():
            v = int(aa_details['van der Waals volume']) # Note: I only convert to int here to match the old script behavior and because all volumes are integer values so it does not do any harm
            volume_groups[v] = volume_groups.get(v, [])
            volume_groups[v].append(aa_code)

        section_latex_objs = []
        section_latex_objs.append( lr.LatexSubSection(
            'Breakdown by volume',
            'A case is considered a small-to-large (resp. large-to-small) mutation if all of the wildtype residues have a smaller (resp. larger) van der Waals volume than the corresponding mutant residue. The order is defined as %s so some cases are considered to have no change in volume e.g. MET -> LEU.' % (' < '.join([''.join(sorted(v)) for k, v in sorted(volume_groups.iteritems())]))
        ) )
        for subcase in ('XX', 'SL', 'LS'):
            subcase_dataframe = dataframe[dataframe['VolumeChange'] == subcase]
            table_header = 'Statistics - %s (%d cases)' % (BenchmarkRun.by_volume_descriptions[subcase], len(subcase_dataframe))
            if len(subcase_dataframe) >= 8:
                list_stats = format_stats(get_xy_dataset_statistics_pandas(subcase_dataframe, experimental_field, 'Predicted', fcorrect_x_cutoff = self.stability_classication_x_cutoff, fcorrect_y_cutoff = self.stability_classication_y_cutoff, ignore_null_values = True, run_standardized_analysis = False), return_string = False)
                section_latex_objs.append( lr.LatexTable(
                    header_row,
                    list_stats,
                    column_format = stats_column_format,
                    header_text = table_header
                ))
                self.add_stored_metric_to_df(BenchmarkRun.by_volume_descriptions[subcase], len(subcase_dataframe), list_stats)
            else:
                section_latex_objs.append( lr.LatexText(
                    'Not enough data for analysis of mutations ''%s'' (at least 8 cases are required).' % BenchmarkRun.by_volume_descriptions[subcase]
                ))
        if verbose:
            self.report('\n'.join([x.generate_plaintext() for x in section_latex_objs]), fn = colortext.sprint)
        self.metric_latex_objects.extend( section_latex_objs )


        section_latex_objs = []
        section_latex_objs.append( lr.LatexSubSection(
            'Mutations to alanine',
            'And mutations not to alanine'
        ))
        subcase_dataframe = dataframe[dataframe['MutantAA'] == 'A']
        if len(subcase_dataframe) > 0:
            table_header = 'Statistics - all mutations to alanine (including multiple mutations, if they are all to alanine) (%d cases)' % len(subcase_dataframe)
            list_stats = format_stats(get_xy_dataset_statistics_pandas(subcase_dataframe, experimental_field, 'Predicted', fcorrect_x_cutoff = self.stability_classication_x_cutoff, fcorrect_y_cutoff = self.stability_classication_y_cutoff, ignore_null_values = True, run_standardized_analysis = False), return_string = False)
            section_latex_objs.append( lr.LatexTable(
                header_row,
                list_stats,
                column_format = stats_column_format,
                header_text = table_header
            ))
            self.add_stored_metric_to_df('all mutations to alanine', len(subcase_dataframe), list_stats)

        subcase_dataframe = dataframe[(dataframe['MutantAA'] == 'A') & (dataframe['NumberOfMutations'] == 1)]
        if len(subcase_dataframe) > 0:
            table_header = 'Statistics - single mutations to alanine (%d cases)' % len(subcase_dataframe)
            list_stats = format_stats(get_xy_dataset_statistics_pandas(subcase_dataframe, experimental_field, 'Predicted', fcorrect_x_cutoff = self.stability_classication_x_cutoff, fcorrect_y_cutoff = self.stability_classication_y_cutoff, ignore_null_values = True, run_standardized_analysis = False), return_string = False)
            section_latex_objs.append( lr.LatexTable(
                header_row,
                list_stats,
                column_format = stats_column_format,
                header_text = table_header
            ))
            self.add_stored_metric_to_df('single mutations to alanine', len(subcase_dataframe), list_stats)

        subcase_dataframe = dataframe[(dataframe['MutantAA'] == 'A') & (dataframe['NumberOfMutations'] != 1)]
        if len(subcase_dataframe) > 0:
            table_header = 'Statistics - multiple mutations to alanine (%d cases)' % len(subcase_dataframe)
            list_stats = format_stats(get_xy_dataset_statistics_pandas(subcase_dataframe, experimental_field, 'Predicted', fcorrect_x_cutoff = self.stability_classication_x_cutoff, fcorrect_y_cutoff = self.stability_classication_y_cutoff, ignore_null_values = True, run_standardized_analysis = False), return_string = False)
            section_latex_objs.append( lr.LatexTable(
                header_row,
                list_stats,
                column_format = stats_column_format,
                header_text = table_header
            ))
            self.add_stored_metric_to_df('multiple mutations to alanine', len(subcase_dataframe), list_stats)

        subcase_dataframe = dataframe[dataframe['MutantAA'] != 'A']
        if len(subcase_dataframe) > 0:
            table_header = 'Statistics - mutations to anything other than alanine (including multiple mutations that include a non-alanine mutation) (%d cases)' % len(subcase_dataframe)
            list_stats = format_stats(get_xy_dataset_statistics_pandas(subcase_dataframe, experimental_field, 'Predicted', fcorrect_x_cutoff = self.stability_classication_x_cutoff, fcorrect_y_cutoff = self.stability_classication_y_cutoff, ignore_null_values = True, run_standardized_analysis = False), return_string = False)
            section_latex_objs.append( lr.LatexTable(
                header_row,
                list_stats,
                column_format = stats_column_format,
                header_text = table_header
            ))
            self.add_stored_metric_to_df('mutations not to alanine', len(subcase_dataframe), list_stats)
        if verbose and len(section_latex_objs) > 0:
            self.report('\n'.join([x.generate_plaintext() for x in section_latex_objs]), fn = colortext.sprint)
        self.metric_latex_objects.extend( section_latex_objs )


        section_latex_objs = []
        subcase_dataframe = dataframe[dataframe['HasGPMutation'] == 1]
        if len(subcase_dataframe) > 0:
            table_header = 'Statistics - cases with G or P (%d cases)' % len(subcase_dataframe)
            list_stats = format_stats(get_xy_dataset_statistics_pandas(subcase_dataframe, experimental_field, 'Predicted', fcorrect_x_cutoff = self.stability_classication_x_cutoff, fcorrect_y_cutoff = self.stability_classication_y_cutoff, ignore_null_values = True, run_standardized_analysis = False), return_string = False)
            section_latex_objs.append( lr.LatexTable(
                header_row,
                list_stats,
                column_format = stats_column_format,
                header_text = table_header
            ))
            self.add_stored_metric_to_df('cases with G or P', len(subcase_dataframe), list_stats)

        subcase_dataframe = dataframe[dataframe['HasGPMutation'] == 0]
        if len(subcase_dataframe) > 0:
            table_header = 'Statistics - cases without G or P (%d cases)' % len(subcase_dataframe)
            list_stats = format_stats(get_xy_dataset_statistics_pandas(subcase_dataframe, experimental_field, 'Predicted', fcorrect_x_cutoff = self.stability_classication_x_cutoff, fcorrect_y_cutoff = self.stability_classication_y_cutoff, ignore_null_values = True, run_standardized_analysis = False), return_string = False)
            section_latex_objs.append( lr.LatexTable(
                header_row,
                list_stats,
                column_format = stats_column_format,
                header_text = table_header
            ))
            self.add_stored_metric_to_df('cases without G or P', len(subcase_dataframe), list_stats)

        if len(section_latex_objs) > 0:
            section_latex_objs.insert( 0, lr.LatexSubSection(
                'Separating out mutations involving glycine or proline.',
                'This cases may involve changes to secondary structure so we separate them out here.'
            ))

        if verbose and len(section_latex_objs) > 0:
            self.report('\n'.join([x.generate_plaintext() for x in section_latex_objs]), fn = colortext.sprint)
        self.metric_latex_objects.extend( section_latex_objs )

        #### Single mutations
        section_latex_objs = []
        section_latex_objs.append( lr.LatexSubSection(
            'Number of mutations',
        ))
        subcase_dataframe = dataframe[dataframe['NumberOfMutations'] == 1]
        if len(subcase_dataframe) >= case_n_cutoff:
            table_header = 'Statistics - single mutations (%d cases)' % len(subcase_dataframe)
            list_stats = format_stats(get_xy_dataset_statistics_pandas(subcase_dataframe, experimental_field, 'Predicted', fcorrect_x_cutoff = self.stability_classication_x_cutoff, fcorrect_y_cutoff = self.stability_classication_x_cutoff, ignore_null_values = True, run_standardized_analysis = False), return_string = False)
            section_latex_objs.append( lr.LatexTable(
                header_row,
                list_stats,
                column_format = stats_column_format,
                header_text = table_header
            ))
            self.add_stored_metric_to_df('single mutations', len(subcase_dataframe), list_stats)
        subcase_dataframe = dataframe[dataframe['NumberOfMutations'] > 1]
        if len(subcase_dataframe) >= case_n_cutoff:
            table_header = 'Statistics - multiple mutations (%d cases)' % len(subcase_dataframe)
            list_stats = format_stats(get_xy_dataset_statistics_pandas(subcase_dataframe, experimental_field, 'Predicted', fcorrect_x_cutoff = self.stability_classication_x_cutoff, fcorrect_y_cutoff = self.stability_classication_x_cutoff, ignore_null_values = True, run_standardized_analysis = False), return_string = False)
            section_latex_objs.append( lr.LatexTable(
                header_row,
                list_stats,
                column_format = stats_column_format,
                header_text = table_header
            ))
            self.add_stored_metric_to_df('multiple mutations', len(subcase_dataframe), list_stats)
        # subcase_dataframe = dataframe[(dataframe.NumberOfMutations >= 2) & (dataframe.NumberOfMutations <= 5)]
        # if len(subcase_dataframe) >= case_n_cutoff:
        #     table_header = 'Statistics - 2-4 mutations (%d cases)' % len(subcase_dataframe)
        #     list_stats = format_stats(get_xy_dataset_statistics_pandas(subcase_dataframe, experimental_field, 'Predicted', fcorrect_x_cutoff = self.stability_classication_x_cutoff, fcorrect_y_cutoff = self.stability_classication_x_cutoff, ignore_null_values = True, run_standardized_analysis = False), return_string = False)
        #     section_latex_objs.append( LatexTable(
        #         header_row,
        #         list_stats,
        #         column_format = stats_column_format,
        #         header_text = table_header
        #     ))
        #     self.add_stored_metric_to_df('2-4 mutations', len(subcase_dataframe), list_stats)
        # mutation_cutoffs = [5, 10, 20, 50, 100, 200]
        # for i, mutation_cutoff in enumerate(mutation_cutoffs):
        #     if len(mutation_cutoffs) - 1 == i:
        #         break
        #     next_cutoff = mutation_cutoffs[i+1]
        #     subcase_dataframe = dataframe[(dataframe.NumberOfMutations >= mutation_cutoff) & (dataframe.NumberOfMutations <= next_cutoff)]
        #     if len(subcase_dataframe) >= case_n_cutoff:
        #         table_header = 'Statistics - %d $<=$ number of mutations $<=$ %d (%d cases)' % (mutation_cutoff, next_cutoff, len(subcase_dataframe))
        #         list_stats = format_stats(get_xy_dataset_statistics_pandas(subcase_dataframe, experimental_field, 'Predicted', fcorrect_x_cutoff = self.stability_classication_x_cutoff, fcorrect_y_cutoff = self.stability_classication_x_cutoff, ignore_null_values = True, run_standardized_analysis = False), return_string = False)
        #         section_latex_objs.append( LatexTable(
        #             header_row,
        #             list_stats,
        #             column_format = stats_column_format,
        #             header_text = table_header
        #         ))
        #         self.add_stored_metric_to_df('%d <= mutations<= %d' % (mutation_cutoff, next_cutoff), len(subcase_dataframe), list_stats)
        if verbose:
            self.report('\n'.join([x.generate_plaintext() for x in section_latex_objs]), fn = colortext.sprint)
        self.metric_latex_objects.extend( section_latex_objs )
        ####

        #### Complete dataset (scaled)
        if self.calculate_scalar_adjustments:
            section_latex_objs = []
            section_latex_objs.append( lr.LatexSubSection(
                'Entire dataset using a scaling factor of 1/%.03f to improve the fraction correct metric.' % scalar_adjustment,
                'Warning: Results in this section use an averaged scaling factor to improve the value for the fraction correct metric. This scalar will vary over benchmark runs so these results should not be interpreted as performance results; they should be considered as what could be obtained if the predicted values were scaled by a "magic" value.'
            ))
            table_header = 'Statistics - complete dataset (scaled) (%d cases)' % len(dataframe)
            # For these statistics, we assume that we have reduced any scaling issues and use the same cutoff for the Y-axis as the user specified for the X-axis
            list_stats = format_stats(get_xy_dataset_statistics_pandas(dataframe, experimental_field, BenchmarkRun.get_analysis_set_fieldname('Predicted_adj', analysis_set), fcorrect_x_cutoff = self.stability_classication_x_cutoff, fcorrect_y_cutoff = self.stability_classication_x_cutoff, ignore_null_values = True, run_standardized_analysis = False), return_string = False)
            section_latex_objs.append( lr.LatexTable(
                header_row,
                list_stats,
                column_format = stats_column_format,
                header_text = table_header
            ))
            self.add_stored_metric_to_df('complete dataset (scaled)', len(dataframe), list_stats)
            if verbose:
                self.report('\n'.join([x.generate_plaintext() for x in section_latex_objs]), fn = colortext.sprint)
            self.metric_latex_objects.extend( section_latex_objs )
        ####

        section_latex_objs = []
        section_latex_objs.append( lr.LatexSubSection(
            'Entire dataset',
            'Overall statistics'
        ))
        table_header = 'Statistics - complete dataset (%d cases)' % len(dataframe)
        # For these statistics, we assume that we have reduced any scaling issues and use the same cutoff for the Y-axis as the user specified for the X-axis
        list_stats = format_stats(get_xy_dataset_statistics_pandas(dataframe, experimental_field, 'Predicted', fcorrect_x_cutoff = self.stability_classication_x_cutoff, fcorrect_y_cutoff = self.stability_classication_x_cutoff, ignore_null_values = True, run_standardized_analysis = False), return_string = False)
        section_latex_objs.append( lr.LatexTable(
            header_row,
            list_stats,
            column_format = stats_column_format,
            header_text = table_header
        ))
        self.add_stored_metric_to_df('complete dataset', len(dataframe), list_stats)
        if verbose:
            self.report('\n'.join([x.generate_plaintext() for x in section_latex_objs]), fn = colortext.sprint)
        self.metric_latex_objects.extend( section_latex_objs )

        # There is probably a better way of writing the pandas code here
        record_with_most_errors = (dataframe[['PDBFileID', 'NumberOfDerivativeErrors', 'Mutations']].sort_values(by = 'NumberOfDerivativeErrors')).tail(1)
        record_index = record_with_most_errors.index.tolist()[0]
        pdb_id, num_errors, mutation_str = dataframe.loc[record_index, 'PDBFileID'], dataframe.loc[record_index, 'NumberOfDerivativeErrors'], dataframe.loc[record_index, 'Mutations']
        if num_errors > 0:
            error_detection_text = '\n\nDerivative errors were found in the run. Record #{0} - {1}, {2} - has the most amount ({3}) of derivative errors.'.format(record_index, pdb_id, mutation_str, num_errors)
            self.metric_latex_objects.append( lr.LatexText(error_detection_text, color = 'red') )
            if verbose:
                self.report(error_detection_text, fn = colortext.warning)

        # Write the analysis to file
        self.create_analysis_directory(analysis_directory)
        self.metrics_filepath = os.path.join(self.analysis_directory, '{0}_metrics.txt'.format(self.benchmark_run_name))
        write_file(self.metrics_filepath, '\n'.join([x.generate_plaintext() for x in self.metric_latex_objects]))
63622
def decide_slices(self, data_shapes):
        
        assert len(data_shapes) > 0
        major_axis = [DataDesc.get_batch_axis(x.layout) for x in data_shapes]

        for (name, shape), axis in zip(data_shapes, major_axis):
            if axis == -1:
                continue

            batch_size = shape[axis]
            if self.batch_size is not None:
                assert batch_size == self.batch_size, ("all data must have the same batch size: "
                                                       + ("batch_size = %d, but " % self.batch_size)
                                                       + ("%s has shape %s" % (name, shape)))
            else:
                self.batch_size = batch_size
                self.slices = _split_input_slice(self.batch_size, self.workload)

        return major_axis
1244009
def run_analysis(self, argv):
        """"""
        args = self._parser.parse_args(argv)

        exttype = splitext(args.infile)[-1]
        if exttype in ['.fits', '.npy']:
            castro_data = CastroData.create_from_sedfile(args.infile)
        elif exttype in ['.yaml']:
            castro_data = CastroData.create_from_yamlfile(args.infile)
        else:
            raise ValueError("Can not read file type %s for SED" % extype)

        ylims = [1e-8, 1e-5]

        plot = plotCastro(castro_data, ylims)
        if args.outfile:
            plot[0].savefig(args.outfile)
8163
def strains(self):
        
        with open(os.path.join(self.path, 'strains.csv')) as strains:
            next(strains)
            for line in strains:
                oln, seqid = line.split(',')
                self.straindict[oln] = seqid.rstrip()
                self.strainset.add(oln)
                logging.debug(oln)
                if self.debug:
                    break
746404
def _process_batch(self):
        """"""
        if self.block_id == len(self.tgroups):
            return None, None

        tgroup = self.tgroups[self.block_id]
        psize = self.chunk_tsamples[self.block_id]
        mid = self.mids[self.block_id]
        stilde = self.data.overwhitened_data(tgroup[0].delta_f)
        psd = stilde.psd

        valid_end = int(psize - self.data.trim_padding)
        valid_start = int(valid_end - self.data.blocksize * self.data.sample_rate)

        seg = slice(valid_start, valid_end)

        self.corr[self.block_id].execute(stilde)
        self.ifts[mid].execute()

        self.block_id += 1

        snr = numpy.zeros(len(tgroup), dtype=numpy.complex64)
        time = numpy.zeros(len(tgroup), dtype=numpy.float64)
        templates = numpy.zeros(len(tgroup), dtype=numpy.uint64)
        sigmasq = numpy.zeros(len(tgroup), dtype=numpy.float32)

        time[:] = self.data.start_time

        result = {}
        tkeys = tgroup[0].params.dtype.names
        for key in tkeys:
            result[key] = []

        veto_info = []

        # Find the peaks in our SNR times series from the various templates
        i = 0
        for htilde in tgroup:
            l = htilde.out[seg].abs_arg_max()

            sgm = htilde.sigmasq(psd)
            norm = 4.0 * htilde.delta_f / (sgm ** 0.5)

            l += valid_start
            snrv = numpy.array([htilde.out[l]])

            # If nothing is above threshold we can exit this template
            s = abs(snrv[0]) * norm
            if s < self.snr_threshold:
                continue

            time[i] += float(l - valid_start) / self.data.sample_rate

            # We have an SNR so high that we will drop the entire analysis
            # of this chunk of time!
            if self.snr_abort_threshold is not None and s > self.snr_abort_threshold:
                logging.info("We are seeing some *really* high SNRs, lets"
                             " assume they aren't signals and just give up")
                return False, []

            veto_info.append((snrv, norm, l, htilde, stilde))

            snr[i] = snrv[0] * norm
            sigmasq[i] = sgm
            templates[i] = htilde.id
            if not hasattr(htilde, 'dict_params'):
                htilde.dict_params = {}
                for key in tkeys:
                    htilde.dict_params[key] = htilde.params[key]

            for key in tkeys:
                result[key].append(htilde.dict_params[key])
            i += 1


        result['snr'] = abs(snr[0:i])
        result['coa_phase'] = numpy.angle(snr[0:i])
        result['end_time'] = time[0:i]
        result['template_id'] = templates[0:i]
        result['sigmasq'] = sigmasq[0:i]

        for key in tkeys:
            result[key] = numpy.array(result[key])

        return result, veto_info