Search in sources :

Example 1 with ExportWriter

use of com.compomics.util.io.export.ExportWriter in project peptide-shaker by compomics.

the class PSExportFactory method writeExport.

/**
 * Writes the desired export in text format. If an argument is not needed,
 * provide null (at your own risks).
 *
 * @param exportScheme the scheme of the export
 * @param destinationFile the destination file
 * @param exportFormat the format of export to use
 * @param gzip if true export text as gzipped file
 * @param experiment the experiment corresponding to this project (mandatory
 * for the Project section)
 * @param projectDetails the project details (mandatory for the Project
 * section)
 * @param identification the identification (mandatory for the Protein,
 * Peptide and PSM sections)
 * @param identificationFeaturesGenerator the identification features
 * generator (mandatory for the Protein, Peptide and PSM sections)
 * @param geneMaps the gene maps
 * @param proteinKeys the protein keys to export (mandatory for the Protein
 * section)
 * @param peptideKeys the peptide keys to export (mandatory for the Peptide
 * section)
 * @param psmKeys the keys of the PSMs to export (mandatory for the PSM
 * section)
 * @param nSurroundingAA the number of surrounding amino acids to export
 * (mandatory for the Peptide section)
 * @param identificationParameters the identification parameters
 * @param sequenceProvider a provider for the protein sequences
 * @param proteinDetailsProvider the protein details provider
 * @param spectrumProvider the spectrum provider
 * @param spectrumCountingPreferences the spectrum counting preferences
 * (mandatory for the spectrum counting section)
 * @param waitingHandler the waiting handler
 *
 * @throws IOException exception thrown whenever an IO exception occurred
 * while reading or writing to a file
 */
public static void writeExport(ExportScheme exportScheme, File destinationFile, ExportFormat exportFormat, boolean gzip, String experiment, ProjectDetails projectDetails, Identification identification, IdentificationFeaturesGenerator identificationFeaturesGenerator, GeneMaps geneMaps, long[] proteinKeys, long[] peptideKeys, long[] psmKeys, int nSurroundingAA, IdentificationParameters identificationParameters, SequenceProvider sequenceProvider, ProteinDetailsProvider proteinDetailsProvider, SpectrumProvider spectrumProvider, SpectrumCountingParameters spectrumCountingPreferences, WaitingHandler waitingHandler) throws IOException {
    ExportWriter exportWriter = ExportWriter.getExportWriter(exportFormat, destinationFile, exportScheme.getSeparator(), exportScheme.getSeparationLines(), gzip);
    if (exportWriter instanceof ExcelWriter) {
        ExcelWriter excelWriter = (ExcelWriter) exportWriter;
        PsExportStyle exportStyle = PsExportStyle.getReportStyle(excelWriter);
        excelWriter.setWorkbookStyle(exportStyle);
    }
    exportWriter.writeMainTitle(exportScheme.getMainTitle());
    for (String sectionName : exportScheme.getSections()) {
        if (exportScheme.isIncludeSectionTitles()) {
            exportWriter.startNewSection(sectionName);
        } else {
            exportWriter.startNewSection();
        }
        switch(sectionName) {
            case PsAnnotationFeature.type:
                PsAnnotationSection psAnnotationSection = new PsAnnotationSection(exportScheme.getExportFeatures(sectionName), exportScheme.isIndexes(), exportScheme.isHeader(), exportWriter);
                psAnnotationSection.writeSection(identificationParameters.getAnnotationParameters(), waitingHandler);
                break;
            case PsInputFilterFeature.type:
                PsInputFilterSection psInputFilterSection = new PsInputFilterSection(exportScheme.getExportFeatures(sectionName), exportScheme.isIndexes(), exportScheme.isHeader(), exportWriter);
                psInputFilterSection.writeSection(identificationParameters.getPeptideAssumptionFilter(), waitingHandler);
                break;
            case PsPeptideFeature.type:
                PsPeptideSection psPeptideSection = new PsPeptideSection(exportScheme.getExportFeatures(sectionName), exportScheme.isIndexes(), exportScheme.isHeader(), exportWriter);
                psPeptideSection.writeSection(identification, identificationFeaturesGenerator, sequenceProvider, proteinDetailsProvider, spectrumProvider, identificationParameters, peptideKeys, nSurroundingAA, "", exportScheme.isValidatedOnly(), exportScheme.isIncludeDecoy(), waitingHandler);
                break;
            case PsProjectFeature.type:
                PsProjectSection psProjectSection = new PsProjectSection(exportScheme.getExportFeatures(sectionName), exportScheme.isIndexes(), exportScheme.isHeader(), exportWriter);
                psProjectSection.writeSection(experiment, projectDetails, waitingHandler);
                break;
            case PsProteinFeature.type:
                PsProteinSection psProteinSection = new PsProteinSection(exportScheme.getExportFeatures(sectionName), exportScheme.isIndexes(), exportScheme.isHeader(), exportWriter);
                psProteinSection.writeSection(identification, identificationFeaturesGenerator, sequenceProvider, proteinDetailsProvider, spectrumProvider, geneMaps, identificationParameters, proteinKeys, nSurroundingAA, exportScheme.isValidatedOnly(), exportScheme.isIncludeDecoy(), waitingHandler);
                break;
            case PsPsmFeature.type:
                PsPsmSection psPsmSection = new PsPsmSection(exportScheme.getExportFeatures(sectionName), exportScheme.isIndexes(), exportScheme.isHeader(), exportWriter);
                psPsmSection.writeSection(identification, identificationFeaturesGenerator, sequenceProvider, proteinDetailsProvider, spectrumProvider, identificationParameters, psmKeys, "", nSurroundingAA, exportScheme.isValidatedOnly(), exportScheme.isIncludeDecoy(), waitingHandler);
                break;
            case PsIdentificationAlgorithmMatchesFeature.type:
                PsIdentificationAlgorithmMatchesSection psIdentificationAlgorithmMatchesSection = new PsIdentificationAlgorithmMatchesSection(exportScheme.getExportFeatures(sectionName), exportScheme.isIndexes(), exportScheme.isHeader(), exportWriter);
                psIdentificationAlgorithmMatchesSection.writeSection(identification, identificationFeaturesGenerator, sequenceProvider, proteinDetailsProvider, spectrumProvider, identificationParameters, psmKeys, "", nSurroundingAA, waitingHandler);
                break;
            case PsPtmScoringFeature.type:
                PsPtmScoringSection psPtmScoringSection = new PsPtmScoringSection(exportScheme.getExportFeatures(sectionName), exportScheme.isIndexes(), exportScheme.isHeader(), exportWriter);
                psPtmScoringSection.writeSection(identificationParameters.getModificationLocalizationParameters(), waitingHandler);
                break;
            case PsSearchFeature.type:
                PsSearchParametersSection psSearchParametersSection = new PsSearchParametersSection(exportScheme.getExportFeatures(sectionName), exportScheme.isIndexes(), exportScheme.isHeader(), exportWriter);
                psSearchParametersSection.writeSection(identificationParameters.getSearchParameters(), projectDetails, waitingHandler);
                break;
            case PsSpectrumCountingFeature.type:
                PsSpectrumCountingSection psSpectrumCountingSection = new PsSpectrumCountingSection(exportScheme.getExportFeatures(sectionName), exportScheme.isIndexes(), exportScheme.isHeader(), exportWriter);
                psSpectrumCountingSection.writeSection(spectrumCountingPreferences, waitingHandler);
                break;
            case PsValidationFeature.type:
                PsValidationSection psValidationSection = new PsValidationSection(exportScheme.getExportFeatures(sectionName), exportScheme.isIndexes(), exportScheme.isHeader(), exportWriter);
                PSMaps psMaps = new PSMaps();
                psMaps = (PSMaps) identification.getUrParam(psMaps);
                psValidationSection.writeSection(psMaps, identificationParameters, waitingHandler);
                break;
            default:
                throw new UnsupportedOperationException("Section " + sectionName + " not implemented.");
        }
    }
    exportWriter.close();
}
Also used : PSMaps(eu.isas.peptideshaker.scoring.PSMaps) ExcelWriter(com.compomics.util.io.export.writers.ExcelWriter) PsPsmSection(eu.isas.peptideshaker.export.sections.PsPsmSection) PsPtmScoringSection(eu.isas.peptideshaker.export.sections.PsPtmScoringSection) PsProjectSection(eu.isas.peptideshaker.export.sections.PsProjectSection) PsIdentificationAlgorithmMatchesSection(eu.isas.peptideshaker.export.sections.PsIdentificationAlgorithmMatchesSection) PsInputFilterSection(eu.isas.peptideshaker.export.sections.PsInputFilterSection) ExportWriter(com.compomics.util.io.export.ExportWriter) PsPeptideSection(eu.isas.peptideshaker.export.sections.PsPeptideSection) PsSpectrumCountingSection(eu.isas.peptideshaker.export.sections.PsSpectrumCountingSection) PsProteinSection(eu.isas.peptideshaker.export.sections.PsProteinSection) PsValidationSection(eu.isas.peptideshaker.export.sections.PsValidationSection) PsSearchParametersSection(eu.isas.peptideshaker.export.sections.PsSearchParametersSection) PsAnnotationSection(eu.isas.peptideshaker.export.sections.PsAnnotationSection)

Example 2 with ExportWriter

use of com.compomics.util.io.export.ExportWriter in project peptide-shaker by compomics.

the class PSExportFactory method writeDocumentation.

/**
 * Writes the documentation related to a report.
 *
 * @param exportScheme the export scheme of the report
 * @param exportFormat the export format chosen by the user
 * @param destinationFile the destination file where to write the
 * documentation
 *
 * @throws IOException thrown if an IOException occurs
 */
public static void writeDocumentation(ExportScheme exportScheme, ExportFormat exportFormat, File destinationFile) throws IOException {
    ExportWriter exportWriter = ExportWriter.getExportWriter(exportFormat, destinationFile, exportScheme.getSeparator(), exportScheme.getSeparationLines(), false);
    if (exportWriter instanceof ExcelWriter) {
        ExcelWriter excelWriter = (ExcelWriter) exportWriter;
        // @TODO use another style?
        PsExportStyle exportStyle = PsExportStyle.getReportStyle(excelWriter);
        excelWriter.setWorkbookStyle(exportStyle);
    }
    String mainTitle = exportScheme.getMainTitle();
    if (mainTitle != null) {
        exportWriter.writeMainTitle(mainTitle);
    }
    for (String sectionName : exportScheme.getSections()) {
        exportWriter.startNewSection(sectionName);
        if (exportScheme.isIncludeSectionTitles()) {
            exportWriter.write(sectionName);
            exportWriter.newLine();
        }
        for (ExportFeature exportFeature : exportScheme.getExportFeatures(sectionName)) {
            exportWriter.write(exportFeature.getTitle());
            exportWriter.addSeparator();
            exportWriter.write(exportFeature.getDescription());
            exportWriter.newLine();
        }
    }
    exportWriter.close();
}
Also used : ExcelWriter(com.compomics.util.io.export.writers.ExcelWriter) ExportFeature(com.compomics.util.io.export.ExportFeature) ExportWriter(com.compomics.util.io.export.ExportWriter)

Aggregations

ExportWriter (com.compomics.util.io.export.ExportWriter)2 ExcelWriter (com.compomics.util.io.export.writers.ExcelWriter)2 ExportFeature (com.compomics.util.io.export.ExportFeature)1 PsAnnotationSection (eu.isas.peptideshaker.export.sections.PsAnnotationSection)1 PsIdentificationAlgorithmMatchesSection (eu.isas.peptideshaker.export.sections.PsIdentificationAlgorithmMatchesSection)1 PsInputFilterSection (eu.isas.peptideshaker.export.sections.PsInputFilterSection)1 PsPeptideSection (eu.isas.peptideshaker.export.sections.PsPeptideSection)1 PsProjectSection (eu.isas.peptideshaker.export.sections.PsProjectSection)1 PsProteinSection (eu.isas.peptideshaker.export.sections.PsProteinSection)1 PsPsmSection (eu.isas.peptideshaker.export.sections.PsPsmSection)1 PsPtmScoringSection (eu.isas.peptideshaker.export.sections.PsPtmScoringSection)1 PsSearchParametersSection (eu.isas.peptideshaker.export.sections.PsSearchParametersSection)1 PsSpectrumCountingSection (eu.isas.peptideshaker.export.sections.PsSpectrumCountingSection)1 PsValidationSection (eu.isas.peptideshaker.export.sections.PsValidationSection)1 PSMaps (eu.isas.peptideshaker.scoring.PSMaps)1