<commit_before>package jobs

import org.transmartproject.core.dataquery.TabularResult

class MarkerSelection extends AnalysisJob {

    @Override
    protected void runAnalysis() {
        updateStatus('Running marker selection analysis')
        // set path to markerselection processor
        String sourceMarkerSelection = 'source(\'$pluginDirectory/MarkerSelection/MarkerSelection.R\')'
        // call for analysis for marker selection
        // TODO number of permutations is not set? numberOfPermutations = as.integer(\'$txtNumberOfPermutations\'),
        String markerSelectionLoad = '''MS.loader(
                            input.filename = \'outputfile\',
                            numberOfMarkers = as.integer(\'$txtNumberOfMarkers\'))'''
        // set path to heatmap png file generator
        String sourceHeatmap = 'source(\'$pluginDirectory/Heatmap/HeatmapLoader.R\')'
        // generate the actual heatmap png picture
        String createHeatmap = '''Heatmap.loader(
                            input.filename = \'heatmapdata\',
                            meltData       = FALSE,
                            imageWidth     = as.integer(\'$txtImageWidth\'),
                            imageHeight    = as.integer(\'$txtImageHeight\'),
                            pointsize      = as.integer(\'$txtImagePointsize\'))'''

        runRCommandList([sourceMarkerSelection, markerSelectionLoad, sourceHeatmap, createHeatmap])
    }

    @Override
    protected void writeData(Map<String, TabularResult> results) {
        withDefaultCsvWriter(results) { csvWriter ->
            csvWriter.writeNext(['PATIENT.ID','VALUE','PROBE.ID','GENE_SYMBOL','SUBSET'] as String[])

            [AnalysisJob.SUBSET1, AnalysisJob.SUBSET2].each { subset ->
                results[subset].rows.each { row ->
                    row.assayIndexMap.each { assay, index ->
                        csvWriter.writeNext(
                                [
                                        "${AnalysisJob.SHORT_NAME[subset]}_${assay.patientInTrialId}",
                                        row[index],
                                        row.probe,
                                        row.geneSymbol,
                                        assay.trialName
                                ] as String[]
                        )
                    }
                }
            }
        }
    }

    @Override
    protected Map<String, TabularResult> fetchResults() {
        updateStatus('Gathering Data')

        [
                (AnalysisJob.SUBSET1) : fetchSubset(AnalysisJob.RESULT_INSTANCE_IDS[AnalysisJob.SUBSET1]),
                (AnalysisJob.SUBSET2) : fetchSubset(AnalysisJob.RESULT_INSTANCE_IDS[AnalysisJob.SUBSET2])
        ]
    }

    @Override
    protected void renderOutput() {
        updateStatus('Completed', "/markerSelection/markerSelectionOut?jobName=${name}")
    }
}
<commit_msg>use new core db api (bioMarker) for marker selection heatmap<commit_after>package jobs

import org.transmartproject.core.dataquery.TabularResult

class MarkerSelection extends AnalysisJob {

    @Override
    protected void runAnalysis() {
        updateStatus('Running marker selection analysis')
        // set path to markerselection processor
        String sourceMarkerSelection = 'source(\'$pluginDirectory/MarkerSelection/MarkerSelection.R\')'
        // call for analysis for marker selection
        // TODO number of permutations is not set? numberOfPermutations = as.integer(\'$txtNumberOfPermutations\'),
        String markerSelectionLoad = '''MS.loader(
                            input.filename = \'outputfile\',
                            numberOfMarkers = as.integer(\'$txtNumberOfMarkers\'))'''
        // set path to heatmap png file generator
        String sourceHeatmap = 'source(\'$pluginDirectory/Heatmap/HeatmapLoader.R\')'
        // generate the actual heatmap png picture
        String createHeatmap = '''Heatmap.loader(
                            input.filename = \'heatmapdata\',
                            meltData       = FALSE,
                            imageWidth     = as.integer(\'$txtImageWidth\'),
                            imageHeight    = as.integer(\'$txtImageHeight\'),
                            pointsize      = as.integer(\'$txtImagePointsize\'))'''

        runRCommandList([sourceMarkerSelection, markerSelectionLoad, sourceHeatmap, createHeatmap])
    }

    @Override
    protected void writeData(Map<String, TabularResult> results) {
        withDefaultCsvWriter(results) { csvWriter ->
            csvWriter.writeNext(['PATIENT.ID','VALUE','PROBE.ID','GENE_SYMBOL','SUBSET'] as String[])

            [AnalysisJob.SUBSET1, AnalysisJob.SUBSET2].each { subset ->
                results[subset].rows.each { row ->
                    row.assayIndexMap.each { assay, index ->
                        csvWriter.writeNext(
                                [
                                        "${AnalysisJob.SHORT_NAME[subset]}_${assay.patientInTrialId}",
                                        row[index],
                                        row.label,
                                        row.bioMarker,
                                        assay.trialName
                                ] as String[]
                        )
                    }
                }
            }
        }
    }

    @Override
    protected Map<String, TabularResult> fetchResults() {
        updateStatus('Gathering Data')

        [
                (AnalysisJob.SUBSET1) : fetchSubset(AnalysisJob.RESULT_INSTANCE_IDS[AnalysisJob.SUBSET1]),
                (AnalysisJob.SUBSET2) : fetchSubset(AnalysisJob.RESULT_INSTANCE_IDS[AnalysisJob.SUBSET2])
        ]
    }

    @Override
    protected void renderOutput() {
        updateStatus('Completed', "/markerSelection/markerSelectionOut?jobName=${name}")
    }
}

{'fraction_non_alphanumeric': 0.09867751780264497, 'fraction_numerical': 0.002034587995930824, 'mean_word_length': 1.6620036101083033, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 12, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2478029', 'n_tokens_mistral': 1431, 'n_tokens_neox': 1361, 'n_words': 255}