Creates scorefiles for qvality's target and decoy distributions
556863
def set_features(self):
        """"""
        self.scores = {}
        for t_or_d, feats in zip(['target', 'decoy'], [self.target,
                                                       self.decoy]):
            self.scores[t_or_d] = {}
            self.scores[t_or_d]['scores'] = self.score_get_fun(
                feats, self.featuretype, self.prepare_percolator_output)
            self.scores[t_or_d]['fn'] = '{}_qvality_input.txt'.format(t_or_d)
            writers.write_qvality_input(self.scores[t_or_d]['scores'],
                                        self.scores[t_or_d]['fn'])
455339
def add_dummy_scores(iteratable, score=0):
    """"""
    for seq in iteratable:
        seq.letter_annotations["phred_quality"] = (score,)*len(seq)
        yield seq
438596
def _is_good_file_for_multiqc(fpath):
    """"""
    # Use mimetypes to exclude binary files where possible
    (ftype, encoding) = mimetypes.guess_type(fpath)
    if encoding is not None:
        return False
    if ftype is not None and ftype.startswith('image'):
        return False
    return True
209296
def layout(args):
    
    from jcvi.algorithms.ec import GA_setup, GA_run

    p = OptionParser(layout.__doc__)
    p.set_beds()
    p.set_cpus(cpus=32)
    opts, args = p.parse_args(args)

    if len(args) != 3:
        sys.exit(not p.print_help())

    simplefile, qseqids, sseqids = args
    qbed, sbed, qorder, sorder, is_self = check_beds(simplefile, p, opts)

    qseqids = qseqids.strip().split(",")
    sseqids = sseqids.strip().split(",")
    qseqids_ii = dict((s, i) for i, s in enumerate(qseqids))
    sseqids_ii = dict((s, i) for i, s in enumerate(sseqids))

    blocks = SimpleFile(simplefile).blocks
    scores = defaultdict(int)
    for a, b, c, d, score, orientation, hl in blocks:
        qi, q = qorder[a]
        si, s = sorder[c]
        qseqid, sseqid = q.seqid, s.seqid
        if sseqid not in sseqids:
            continue
        scores[sseqids_ii[sseqid], qseqid] += score

    data = []
    for (a, b), score in sorted(scores.items()):
        if b not in qseqids_ii:
            continue
        data.append((qseqids_ii[b], score))

    tour = range(len(qseqids))
    toolbox = GA_setup(tour)
    toolbox.register("evaluate", colinear_evaluate_weights, data=data)
    tour, fitness = GA_run(toolbox, ngen=100, npop=100, cpus=opts.cpus)
    tour = [qseqids[x] for x in tour]

    print(",".join(tour))
326702
def _get_stats_files(data, out_dir=None):
    
    if not out_dir:
        out_dir = utils.safe_makedir(os.path.join(dd.get_work_dir(data),
                                                  "qc", dd.get_sample_name(data), "samtools"))
    stats_file = tz.get_in(["depth", "samtools", "stats"], data)
    idxstats_file = tz.get_in(["depth", "samtools", "idxstats"], data)
    if not stats_file:
        stats_file = os.path.join(out_dir, "%s.txt" % dd.get_sample_name(data))
    if not idxstats_file:
        idxstats_file = os.path.join(out_dir, "%s-idxstats.txt" % dd.get_sample_name(data))
    return stats_file, idxstats_file
777740
def _run_vqsr(in_file, ref_file, vrn_files, sensitivity_cutoff, filter_type, data):
    
    cutoffs = ["100.0", "99.99", "99.98", "99.97", "99.96", "99.95", "99.94", "99.93", "99.92", "99.91",
               "99.9", "99.8", "99.7", "99.6", "99.5", "99.0", "98.0", "90.0"]
    if sensitivity_cutoff not in cutoffs:
        cutoffs.append(sensitivity_cutoff)
        cutoffs.sort()
    broad_runner = broad.runner_from_config(data["config"])
    gatk_type = broad_runner.gatk_type()
    base = utils.splitext_plus(in_file)[0]
    recal_file = ("%s-vqsrrecal.vcf.gz" % base) if gatk_type == "gatk4" else ("%s.recal" % base)
    tranches_file = "%s.tranches" % base
    plot_file = "%s-plots.R" % base
    if not utils.file_exists(recal_file):
        with file_transaction(data, recal_file, tranches_file, plot_file) as (tx_recal, tx_tranches, tx_plot_file):
            params = ["-T", "VariantRecalibrator",
                      "-R", ref_file,
                      "--mode", filter_type]
            if gatk_type == "gatk4":
                params += ["--variant", in_file, "--output", tx_recal,
                           "--tranches-file", tx_tranches, "--rscript-file", tx_plot_file]
            else:
                params += ["--input", in_file, "--recal_file", tx_recal,
                           "--tranches_file", tx_tranches, "--rscript_file", tx_plot_file]
            params += _get_vqsr_training(filter_type, vrn_files, gatk_type)
            resources = config_utils.get_resources("gatk_variant_recalibrator", data["config"])
            opts = resources.get("options", [])
            if not opts:
                for cutoff in cutoffs:
                    opts += ["-tranche", str(cutoff)]
                for a in _get_vqsr_annotations(filter_type, data):
                    opts += ["-an", a]
            params += opts
            cores = dd.get_cores(data)
            memscale = {"magnitude": 0.9 * cores, "direction": "increase"} if cores > 1 else None
            try:
                broad_runner.new_resources("gatk-vqsr")
                broad_runner.run_gatk(params, log_error=False, memscale=memscale, parallel_gc=True)
            except:  # Can fail to run if not enough values are present to train.
                return None, None
    if gatk_type == "gatk4":
        vcfutils.bgzip_and_index(recal_file, data["config"])
    return recal_file, tranches_file
3860
function scoresProvider(publicAPI, model) {
  publicAPI.setScores = (scores) => {
    model.scores = [].concat(scores);
    const scoreMapByValue = {};
    model.scores.forEach((score) => {
      scoreMapByValue[score.value] = score;
    });
    model.scoreMapByValue = scoreMapByValue;
    publicAPI.fireScoresChange(model.scores);
  };

  publicAPI.getScoreColor = (value) => {
    const score = model.scoreMapByValue[value];
    return score ? score.color : undefined;
  };

  publicAPI.getScoreName = (value) => {
    const score = model.scoreMapByValue[value];
    return score ? score.name : undefined;
  };
  publicAPI.getDefaultScore = () => {
    if (model.scores) {
      const index = model.scores.findIndex((score) => !!score.isDefault);
      return index === -1 ? 0 : index;
    }
    return 0;
  };
  publicAPI.setDefaultScore = (value) => {
    if (model.scores) {
      model.scores[publicAPI.getDefaultScore()].isDefault = false;
      model.scores[value].isDefault = true;
    }
  };
}
746151
def createfastq(self):
        """"""
        # If the fastq destination folder is not provided, make the default value of :path/:miseqfoldername
        self.fastqdestination = self.fastqdestination if self.fastqdestination else \
            os.path.join(self.path, self.miseqfoldername)
        # Make the path
        make_path(self.fastqdestination)
        # Create a new sample sheet using self.project name instead of the provided Sample_Project. This ensures
        # that all the FASTQ files are stored in the same output folder
        projectsamplesheet = os.path.join(self.fastqdestination, 'SampleSheet_modified.csv')
        with open(projectsamplesheet, "w") as modifiedsamplesheet:
            # Use the 'original' sample sheet as the template for the new sheet
            with open(self.customsamplesheet) as samplesheet:
                # Iterate through the template sheet, and write lines until the header for the data portion of the sheet
                for line in samplesheet:
                    modifiedsamplesheet.write(line)
                    if 'Sample_ID' in line:
                        # Create a list of the header values
                        header = line.split(',')
                        for subline in samplesheet:
                            # Split the line on commas
                            data = subline.split(',')
                            # Initialise a list to store the values for each sample
                            updateddata = list()
                            # Iterate through the entries in the header, and extract the corresponding value
                            for i, value in enumerate(header):
                                # Find the Sample_Project value, and update it to be self.projectname
                                if data[i] in self.projectlist:
                                    data[i] = self.projectname
                                # If demultiplexing is disabled, don't add the samples to the SampleSheet
                                if self.demultiplex:
                                    # Add the (modified) data to the list
                                    updateddata.append(data[i])
                            # Write the updated string to the new sheet
                            modifiedsamplesheet.write(','.join(updateddata))
        # Set :forward/reverse length to :header.forward/reverse length if the argument is not provided, or it's 'full',
        # otherwise  use the supplied argument
        self.forwardlength = self.header.forwardlength if self.forwardlength.lower()\
            == 'full' else self.forwardlength
        # Set :reverselength to :header.reverselength
        self.reverselength = self.header.reverselength if self.reverselength.lower() \
            == 'full' else self.reverselength
        # As the number of cycles required is the number of forward reads + the index(8) + the second index(8)
        # Also set the basemask variable as required
        if self.reverselength != '0':
            self.readsneeded = int(self.forwardlength) + int(self.reverselength) + self.indexlength
            basemask = "Y{}n*,{},Y{}n*".format(self.forwardlength, self.index, self.reverselength)
        else:
            self.readsneeded = int(self.forwardlength) + self.indexlength
            basemask = "Y{}n*,{},n*".format(self.forwardlength, self.index)
        # Handle plurality appropriately
        samples = 'samples' if self.samplecount != 1 else 'sample'
        number = 'are' if self.samplecount != 1 else 'is'
        logging.info('There {num} {num_samples} {plural} in this run.\n'
                     'MiSeqPath: {miseqpath},\n'
                     'MiSeqFolder: {miseqfolder},\n'
                     'FASTQ destination: {destination},\n'
                     'SampleSheet: {sample_sheet}'
                     .format(num=number,
                             num_samples=self.samplecount,
                             plural=samples,
                             miseqpath=self.miseqpath,
                             miseqfolder=self.miseqfolder,
                             destination=self.fastqdestination,
                             sample_sheet=projectsamplesheet))
        # Count the number of completed cycles in the run of interest
        cycles = glob(os.path.join(self.miseqpath, self.miseqfolder, 'Data', 'Intensities', 'BaseCalls', 'L001', 'C*'))
        while len(cycles) < self.readsneeded:
            logging.info('Currently at {num_cycles} cycles. Waiting until the MiSeq reaches cycle {target_cycle}'
                         .format(num_cycles=len(cycles),
                                 target_cycle=self.readsneeded))
            sleep(300)
            cycles = glob(os.path.join(self.miseqpath, self.miseqfolder,
                                       'Data', 'Intensities', 'BaseCalls', 'L001', 'C*'))
        # configureBClToFastq requires :self.miseqfolder/Data/Intensities/BaseCalls/config.xml in order to work
        # When you download runs from BaseSpace, this file is not provided. There is an empty config.xml file that
        # can be populated with run-specific values and moved to the appropriate folder
        if not os.path.isfile(os.path.join(self.miseqfolder, 'Data', 'Intensities', 'BaseCalls', 'config.xml')):
            self.configfilepopulator()
        if self.debug:
            # Define the bcl2fastq system call for the unit test
            bclcall = "bcl2fastq --input-dir {basecalls} " \
                      "--output-dir {outdir} --sample-sheet {samplesheet} " \
                      "--barcode-mismatches 0 -r 1 -p 1 -w 1 -R {runfolder} --use-bases-mask {mask} " \
                      "--tiles s_1_1101 --minimum-trimmed-read-length 1" \
                .format(basecalls=os.path.join(self.miseqfolder, 'Data', 'Intensities', 'BaseCalls'),
                        outdir=self.fastqdestination,
                        samplesheet=projectsamplesheet,
                        runfolder=self.miseqfolder,
                        mask=basemask)
        # elif not self.demultiplex:
        #     bclcall = "bcl2fastq --input-dir {basecalls} " \
        #               "--output-dir {outdir} --sample-sheet {samplesheet} --no-lane-splitting " \
        #               "-r 1 -p 1 -w 1 -R {runfolder} --use-bases-mask {mask}"\
        #         .format(basecalls=os.path.join(self.miseqfolder, 'Data', 'Intensities', 'BaseCalls'),
        #                 outdir=self.fastqdestination,
        #                 samplesheet=projectsamplesheet,
        #                 runfolder=self.miseqfolder,
        #                 mask=basemask)
        else:
            bclcall = "bcl2fastq --input-dir {basecalls} " \
                      "--output-dir {outdir} --sample-sheet {samplesheet} " \
                      "--barcode-mismatches 1 -r 1 -p 1 -w 1 -R {runfolder} --use-bases-mask {mask}"\
                .format(basecalls=os.path.join(self.miseqfolder, 'Data', 'Intensities', 'BaseCalls'),
                        outdir=self.fastqdestination,
                        samplesheet=projectsamplesheet,
                        runfolder=self.miseqfolder,
                        mask=basemask)
        process = False
        if self.demultiplex:
            if not os.path.isdir(self.projectpath):
                process = True
        else:
            if not os.path.isfile(os.path.join(self.fastqdestination, 'Undetermined_S0_R1_001.fastq.gz')):
                process = True
        if process:
            # Call bcl2fastq
            logging.info('Running bcl2fastq')
            # Run the command
            out, err = run_subprocess(bclcall)
            write_to_logfile(bclcall,
                             bclcall,
                             self.logfile)
            write_to_logfile(out,
                             err,
                             self.logfile)
        # Populate the metadata
        for sample in self.metadata.samples:
            sample.commands = GenObject()
            sample.commands.bcl = bclcall
            sample.run.forwardlength = self.forwardlength
            sample.run.reverselength = self.reverselength
        # Copy the fastq files to a central folder so they can be processed
        self.fastqmover()
1286569
def create_quantiles(items: Sequence, lower_bound, upper_bound):
    """"""

    interval = (upper_bound - lower_bound) / len(items)

    quantiles = ((g, (x - interval, x)) for g, x in
                 zip(items, accumulate(repeat(interval, len(items)))))

    return quantiles
1088534
def create_tasks(self, wfk_file, scr_input):
        
        assert len(self) == 0
        wfk_file = self.wfk_file = os.path.abspath(wfk_file)

        # Build a temporary work in the tmpdir that will use a shell manager
        # to run ABINIT in order to get the list of q-points for the screening.
        shell_manager = self.manager.to_shell_manager(mpi_procs=1)

        w = Work(workdir=self.tmpdir.path_join("_qptdm_run"), manager=shell_manager)

        fake_input = scr_input.deepcopy()
        fake_task = w.register(fake_input)
        w.allocate()
        w.build()

        # Create the symbolic link and add the magic value
        # nqpdm = -1 to the input to get the list of q-points.
        fake_task.inlink_file(wfk_file)
        fake_task.set_vars({"nqptdm": -1})
        fake_task.start_and_wait()

        # Parse the section with the q-points
        with NetcdfReader(fake_task.outdir.has_abiext("qptdms.nc")) as reader:
            qpoints = reader.read_value("reduced_coordinates_of_kpoints")
        #print("qpoints)

        # Now we can register the task for the different q-points
        for qpoint in qpoints:
            qptdm_input = scr_input.deepcopy()
            qptdm_input.set_vars(nqptdm=1, qptdm=qpoint)
            new_task = self.register_scr_task(qptdm_input, manager=self.manager)
            # Add the garbage collector.
            if self.flow.gc is not None:
                new_task.set_gc(self.flow.gc)

        self.allocate()
1138417
def main(command_line_arguments=None):
  """"""

  args = command_line_options(command_line_arguments)

  # get some colors for plotting
  cmap = mpl.cm.get_cmap(name='hsv')
  count = len(args.files) + (len(args.baselines) if args.baselines else 0)
  colors = [cmap(i) for i in numpy.linspace(0, 1.0, count+1)]

  # First, read the score files
  logger.info("Loading %d score files" % len(args.files))

  scores = [read_score_file(os.path.join(args.directory, f)) for f in args.files]

  false_alarms = []
  detection_rate = []
  logger.info("Computing FROC curves")
  for score in scores:
    # compute some thresholds
    tmin = min(score[2])
    tmax = max(score[2])
    count = 100
    thresholds = [tmin + float(x)/count * (tmax - tmin) for x in range(count+2)]
    false_alarms.append([])
    detection_rate.append([])
    for threshold in thresholds:
      detection_rate[-1].append(numpy.count_nonzero(numpy.array(score[1]) >= threshold) / float(score[0]))
      false_alarms[-1].append(numpy.count_nonzero(numpy.array(score[2]) >= threshold))
    # to display 0 in a semilogx plot, we have to add a little
#    false_alarms[-1][-1] += 1e-8

  # also read baselines
  if args.baselines is not None:
    for baseline in args.baselines:
      dr = []
      fa = []
      with open(os.path.join(args.baseline_directory, baseline)) as f:
        for line in f:
          splits = line.rstrip().split()
          dr.append(float(splits[0]))
          fa.append(int(splits[1]))
      false_alarms.append(fa)
      detection_rate.append(dr)

  logger.info("Plotting FROC curves to file '%s'", args.output)
  # create a multi-page PDF for the ROC curve
  pdf = PdfPages(args.output)
  figure = _plot_froc(false_alarms, detection_rate, colors, args.legends, args.title, args.max)
  mpl.xlabel('False Alarm (of %d pruned)' % len(scores[0][2]))
  mpl.ylabel('Detection Rate in \%% (total %d faces)' % scores[0][0])
  pdf.savefig(figure)
  pdf.close()

  if args.count_detections:
    for i, f in enumerate(args.files):
      det, all = count_detections(f)
      print("The number of detected faces for %s is %d out of %d" % (args.legends[i], det, all))
1322978
def _create_config_file(out_dir, samples):
    
    out_file = os.path.join(out_dir, "multiqc_config.yaml")
    out = {"table_columns_visible": dict()}

    # Avoid duplicated bcbio columns with qualimap
    if any(("qualimap" in dd.get_tools_on(d) or "qualimap_full" in dd.get_tools_on(d)) for d in samples):
        # Hiding metrics duplicated by Qualimap
        out["table_columns_visible"]["bcbio"] = {"Average_insert_size": False}
        out["table_columns_visible"]["FastQC"] = {"percent_gc": False}

        # Setting up thresholds for Qualimap depth cutoff calculations, based on sample avg depths
        avg_depths = [tz.get_in(["summary", "metrics", "Avg_coverage"], s) for s in samples]
        avg_depths = [x for x in avg_depths if x]
        # Picking all thresholds up to the highest sample average depth
        thresholds = [t for t in coverage.DEPTH_THRESHOLDS if not avg_depths or t <= max(avg_depths)]
        # ...plus one more
        if len(thresholds) < len(coverage.DEPTH_THRESHOLDS):
            thresholds.append(coverage.DEPTH_THRESHOLDS[len(thresholds)])

        # Showing only thresholds surrounding any of average depths
        thresholds_hidden = []
        for i, t in enumerate(thresholds):
            if t > 20:  # Not hiding anything below 20x
                if any(thresholds[i-1] <= c < thresholds[i] for c in avg_depths if c and i-1 >= 0) or \
                   any(thresholds[i] <= c < thresholds[i+1] for c in avg_depths if c and i+1 < len(thresholds)):
                    pass
                else:
                    thresholds_hidden.append(t)

        # Hide coverage unless running full qualimap, downsampled inputs are confusing
        if not any(("qualimap_full" in dd.get_tools_on(d)) for d in samples):
            thresholds_hidden = thresholds + thresholds_hidden
            thresholds_hidden.sort()
            thresholds = []
        out['qualimap_config'] = {
            'general_stats_coverage': [str(t) for t in thresholds],
            'general_stats_coverage_hidden': [str(t) for t in thresholds_hidden]}

    # Avoid confusing peddy outputs, sticking to ancestry and sex prediction
    out["table_columns_visible"]["Peddy"] = {"family_id": False, "sex_het_ratio": False,
                                             "error_sex_check": False}

    # Setting the module order
    module_order = []
    module_order.extend([
        "bcbio",
        "samtools",
        "goleft_indexcov",
        "peddy"
    ])
    out['bcftools'] = {'write_separate_table': True}
    # if germline calling was performed:
    if any("germline" in (get_active_vcinfo(s) or {}) or  # tumor-only somatic with germline extraction
           dd.get_phenotype(s) == "germline" or           # or paired somatic with germline calling for normal
           _has_bcftools_germline_stats(s)                # CWL organized statistics
           for s in samples):
        # Split somatic and germline variant stats into separate multiqc submodules,
        # with somatic going into General Stats, and germline going into a separate table:
        module_order.extend([{
            'bcftools': {
                'name': 'Bcftools (somatic)',
                'info': 'Bcftools stats for somatic variant calls only.',
                'path_filters': ['*_bcftools_stats.txt'],
                'write_general_stats': True,
            }},
            {'bcftools': {
                'name': 'Bcftools (germline)',
                'info': 'Bcftools stats for germline variant calls only.',
                'path_filters': ['*_bcftools_stats_germline.txt'],
                'write_general_stats': False
            }},
        ])
    else:
        module_order.append("bcftools")
    module_order.extend([
        "salmon",
        "picard",
        "qualimap",
        "snpeff",
        "fastqc",
        "preseq",
    ])
    out["module_order"] = module_order

    preseq_samples = [s for s in samples if tz.get_in(["config", "algorithm", "preseq"], s)]
    if preseq_samples:
        out["preseq"] = _make_preseq_multiqc_config(preseq_samples)

    with open(out_file, "w") as out_handle:
        yaml.safe_dump(out, out_handle, default_flow_style=False, allow_unicode=False)
    return out_file
421834
def createqtconf():
    """"""

    template = """[Paths]
Prefix = {path}
Binaries = {path}
"""

    import PyQt5

    exedir = os.path.dirname(sys.executable)
    qtpath = os.path.join(exedir, "qt.conf")
    pyqt5path = os.path.abspath(PyQt5.__file__)
    binpath = os.path.dirname(pyqt5path).replace("\\", "/")

    try:
        with open(qtpath, "w") as f:
            f.write(template.format(path=binpath))
    except:
        pass
168700
def createExperimentArgs():
  """"""
  experimentArguments = []
  # for n in [300, 500, 700, 900, 1100, 1300, 1500, 1700, 1900, 2100, 2300,
  #           2500, 2700, 2900, 3100, 3300, 3500, 3700, 3900]:
  for n in [1500, 1700, 1900, 2100]:
    for a in [128]:
      # Some parameter combinations are just not worth running!
      if ( a==64 and n<=1500 ) or ( a==128 and n<= 1900 ) or ( a==256 ):
        experimentArguments.append(
          ("./sdr_calculations2", "results_errorbars/temp_"+str(n)+"_"+str(a)+".csv",
           "200000", str(n), str(a), "0"),
        )
  return experimentArguments
372677
def setup_file_list(self, filter_text, current_path):
        """"""
        short_paths = shorten_paths(self.paths, self.save_status)
        paths = self.paths
        icons = self.icons
        results = []
        trying_for_line_number = ':' in filter_text

        # Get optional line number
        if trying_for_line_number:
            filter_text, line_number = filter_text.split(':')
            if line_number == '':
                line_number = None
            # Get all the available filenames
            scores = get_search_scores('', self.filenames,
                                       template="<b>{0}</b>")
        else:
            line_number = None
            # Get all available filenames and get the scores for
            # "fuzzy" matching
            scores = get_search_scores(filter_text, self.filenames,
                                       template="<b>{0}</b>")

        # Get max width to determine if shortpaths should be used
        max_width = self.get_item_size(paths)[0]
        self.fix_size(paths)

        # Build the text that will appear on the list widget
        rich_font = CONF.get('appearance', 'rich_font/size', 10)
        if sys.platform == 'darwin':
            path_text_font_size = rich_font
            filename_text_font_size = path_text_font_size + 2
        elif os.name == 'nt':
            path_text_font_size = rich_font
            filename_text_font_size = path_text_font_size + 1
        elif is_ubuntu():
            path_text_font_size = rich_font - 2
            filename_text_font_size = path_text_font_size + 1
        else:
            path_text_font_size = rich_font
            filename_text_font_size = path_text_font_size + 1

        for index, score in enumerate(scores):
            text, rich_text, score_value = score
            if score_value != -1:
                text_item = ("<span style='color:{0:}; font-size:{1:}pt'>{2:}"
                             "</span>").format(ima.MAIN_FG_COLOR,
                                               filename_text_font_size,
                                               rich_text.replace('&', ''))
                if trying_for_line_number:
                    text_item += " [{0:} {1:}]".format(self.line_count[index],
                                                       _("lines"))
                if max_width > self.list.width():
                    text_item += (u" &nbsp; <span style='color:{0:};"
                                  "font-size:{1:}pt'>{2:}"
                                  "</span>").format(self.PATH_FG_COLOR,
                                                    path_text_font_size,
                                                    short_paths[index])
                else:
                    text_item += (u" &nbsp; <span style='color:{0:};"
                                  "font-size:{1:}pt'>{2:}"
                                  "</span>").format(self.PATH_FG_COLOR,
                                                    path_text_font_size,
                                                    paths[index])
                if (trying_for_line_number and self.line_count[index] != 0 or
                        not trying_for_line_number):
                    results.append((score_value, index, text_item))

        # Sort the obtained scores and populate the list widget
        self.filtered_path = []
        plugin = None
        for result in sorted(results):
            index = result[1]
            path = paths[index]
            if sys.platform == 'darwin':
                scale_factor = 0.9
            elif os.name == 'nt':
                scale_factor = 0.8
            elif is_ubuntu():
                scale_factor = 0.6
            else:
                scale_factor = 0.9
            icon = ima.get_icon_by_extension(path, scale_factor)
            text = ''
            try:
                title = self.widgets[index][1].get_plugin_title().split(' - ')
                if plugin != title[0]:
                    plugin = title[0]
                    text += ("<br><big style='color:{0:}'>"
                             "<b>{1:}</b></big><br>").format(ima.MAIN_FG_COLOR,
                                                             plugin)
                    item = QListWidgetItem(text)
                    item.setToolTip(path)
                    item.setSizeHint(QSize(0, 25))
                    item.setFlags(Qt.ItemIsEditable)
                    self.list.addItem(item)
                    self.filtered_path.append(path)
            except:
                # The widget using the fileswitcher is not a plugin
                pass
            text = ''
            text += result[-1]
            item = QListWidgetItem(icon, text)
            item.setToolTip(path)
            item.setSizeHint(QSize(0, 25))
            self.list.addItem(item)
            self.filtered_path.append(path)

        # To adjust the delegate layout for KDE themes
        self.list.files_list = True

        # Move selected item in list accordingly and update list size
        if current_path in self.filtered_path:
            self.set_current_row(self.filtered_path.index(current_path))
        elif self.filtered_path:
            self.set_current_row(0)

        # If a line number is searched look for it
        self.line_number = line_number
        self.goto_line(line_number)
456843
def _organize_qc_files(program, qc_dir):
    
    base_files = {"fastqc": "fastqc_report.html",
                  "qualimap_rnaseq": "qualimapReport.html",
                  "qualimap": "qualimapReport.html"}
    if os.path.exists(qc_dir):
        out_files = []
        for fname in [os.path.join(qc_dir, x) for x in os.listdir(qc_dir)]:
            if os.path.isfile(fname) and not fname.endswith(".bcbiotmp"):
                out_files.append(fname)
            elif os.path.isdir(fname) and not fname.endswith("tx"):
                for root, dirs, files in os.walk(fname):
                    for f in files:
                        if not f.endswith(".bcbiotmp"):
                            out_files.append(os.path.join(root, f))
        if len(out_files) > 0 and all([not f.endswith("-failed.log") for f in out_files]):
            if len(out_files) == 1:
                base = out_files[0]
                secondary = []
            else:
                base = None
                if program in base_files:
                    base_choices = [x for x in out_files if x.endswith("/%s" % base_files[program])]
                    if len(base_choices) == 1:
                        base = base_choices[0]
                if not base:
                    base = out_files[0]
                secondary = [x for x in out_files if x != base]
            return {"base": base, "secondary": secondary}
18769
def _evaluate_model_single_file(target_folder, test_file):
    
    logging.info("Create running model...")
    model_src = get_latest_model(target_folder, "model")
    model_file_pointer = tempfile.NamedTemporaryFile(delete=False)
    model_use = model_file_pointer.name
    model_file_pointer.close()
    logging.info("Adjusted model is in %s.", model_use)
    create_adjusted_model_for_percentages(model_src, model_use)

    # Run evaluation
    project_root = get_project_root()
    time_prefix = time.strftime("%Y-%m-%d-%H-%M")
    logging.info("Evaluate '%s' with '%s'...", model_src, test_file)
    logfilefolder = os.path.join(project_root, "logs/")
    if not os.path.exists(logfilefolder):
        os.makedirs(logfilefolder)
    logfile = os.path.join(project_root,
                           "logs/%s-error-evaluation.log" %
                           time_prefix)
    with open(logfile, "w") as log, open(model_use, "r") as modl_src_p:
        p = subprocess.Popen([get_nntoolkit(), 'run',
                              '--batch-size', '1',
                              '-f%0.4f', test_file],
                             stdin=modl_src_p,
                             stdout=log)
        ret = p.wait()
        if ret != 0:
            logging.error("nntoolkit finished with ret code %s",
                          str(ret))
            sys.exit()
    return (logfile, model_use)