Search in sources :

Example 1 with PsProteinFeature

use of com.compomics.util.io.export.features.peptideshaker.PsProteinFeature in project peptide-shaker by compomics.

the class PsProteinSection method writeSection.

/**
 * Writes the desired section.
 *
 * @param identification The identification of the project.
 * @param identificationFeaturesGenerator The identification features
 * generator of the project.
 * @param sequenceProvider The sequence provider.
 * @param proteinDetailsProvider The protein details provider.
 * @param spectrumProvider The spectrum provider.
 * @param geneMaps The gene maps.
 * @param identificationParameters The identification parameters.
 * @param keys The keys of the PSM matches to output.
 * @param nSurroundingAa The number of surrounding amino acids to export.
 * @param validatedOnly Whether only validated matches should be exported.
 * @param decoys Whether decoy matches should be exported as well.
 * @param waitingHandler The waiting handler.
 *
 * @throws IOException exception thrown whenever an error occurred while
 * writing to the file
 */
public void writeSection(Identification identification, IdentificationFeaturesGenerator identificationFeaturesGenerator, SequenceProvider sequenceProvider, ProteinDetailsProvider proteinDetailsProvider, SpectrumProvider spectrumProvider, GeneMaps geneMaps, IdentificationParameters identificationParameters, long[] keys, int nSurroundingAa, boolean validatedOnly, boolean decoys, WaitingHandler waitingHandler) throws IOException {
    if (waitingHandler != null) {
        waitingHandler.setSecondaryProgressCounterIndeterminate(true);
    }
    if (header) {
        writeHeader(identification.getFractions());
    }
    if (keys == null) {
        keys = identification.getProteinIdentification().stream().mapToLong(Long::longValue).toArray();
    }
    int line = 1;
    if (waitingHandler != null) {
        waitingHandler.setWaitingText("Exporting. Please Wait...");
        waitingHandler.resetSecondaryProgressCounter();
        waitingHandler.setMaxSecondaryProgressCounter(keys.length);
    }
    for (long key : keys) {
        ProteinMatch proteinMatch = identification.getProteinMatch(key);
        if (waitingHandler != null) {
            if (waitingHandler.isRunCanceled()) {
                return;
            }
            waitingHandler.increaseSecondaryProgressCounter();
        }
        if (decoys || !proteinMatch.isDecoy()) {
            PSParameter psParameter = (PSParameter) proteinMatch.getUrParam(PSParameter.dummy);
            if (!validatedOnly || psParameter.getMatchValidationLevel().isValidated()) {
                boolean first = true;
                if (indexes) {
                    writer.write(Integer.toString(line));
                    first = false;
                }
                for (ExportFeature exportFeature : proteinFeatures) {
                    if (!first) {
                        writer.addSeparator();
                    } else {
                        first = false;
                    }
                    PsProteinFeature tempProteinFeature = (PsProteinFeature) exportFeature;
                    if (tempProteinFeature.isPerFraction()) {
                        for (int fractionsCount = 0; fractionsCount < identification.getFractions().size(); fractionsCount++) {
                            String fractionName = identification.getFractions().get(fractionsCount);
                            if (fractionsCount > 0) {
                                writer.addSeparator();
                            }
                            writer.write(getFeature(identificationFeaturesGenerator, sequenceProvider, proteinDetailsProvider, geneMaps, identificationParameters, nSurroundingAa, key, proteinMatch, fractionName, psParameter, tempProteinFeature, waitingHandler));
                        }
                    } else {
                        writer.write(getFeature(identificationFeaturesGenerator, sequenceProvider, proteinDetailsProvider, geneMaps, identificationParameters, nSurroundingAa, key, proteinMatch, psParameter, tempProteinFeature, waitingHandler));
                    }
                }
                writer.newLine();
                if (peptideSection != null) {
                    writer.increaseDepth();
                    if (waitingHandler != null) {
                        waitingHandler.setDisplayProgress(false);
                    }
                    peptideSection.writeSection(identification, identificationFeaturesGenerator, sequenceProvider, proteinDetailsProvider, spectrumProvider, identificationParameters, proteinMatch.getPeptideMatchesKeys(), nSurroundingAa, line + ".", validatedOnly, decoys, waitingHandler);
                    if (waitingHandler != null) {
                        waitingHandler.setDisplayProgress(true);
                    }
                    writer.decreseDepth();
                }
                line++;
            }
        }
    }
}
Also used : ProteinMatch(com.compomics.util.experiment.identification.matches.ProteinMatch) ExportFeature(com.compomics.util.io.export.ExportFeature) PsProteinFeature(com.compomics.util.io.export.features.peptideshaker.PsProteinFeature) XYDataPoint(no.uib.jsparklines.data.XYDataPoint) PSParameter(com.compomics.util.experiment.identification.peptide_shaker.PSParameter)

Example 2 with PsProteinFeature

use of com.compomics.util.io.export.features.peptideshaker.PsProteinFeature in project peptide-shaker by compomics.

the class PsProteinSection method writeHeader.

/**
 * Writes the header of the protein section.
 *
 * @param fractions the fraction names
 *
 * @throws IOException exception thrown whenever an error occurred while
 * writing the file
 */
public void writeHeader(ArrayList<String> fractions) throws IOException {
    if (indexes) {
        writer.writeHeaderText("");
        writer.addSeparator();
    }
    boolean firstColumn = true;
    for (PsProteinFeature exportFeature : proteinFeatures) {
        if (firstColumn) {
            firstColumn = false;
        } else {
            writer.addSeparator();
        }
        if (exportFeature.isPerFraction()) {
            for (int i = 0; i < fractions.size(); i++) {
                if (i > 0) {
                    writer.addSeparator();
                }
                writer.writeHeaderText(exportFeature.getTitle() + " " + fractions.get(i));
            }
        } else {
            writer.writeHeaderText(exportFeature.getTitle());
        }
    }
    writer.newLine();
}
Also used : PsProteinFeature(com.compomics.util.io.export.features.peptideshaker.PsProteinFeature) XYDataPoint(no.uib.jsparklines.data.XYDataPoint)

Aggregations

PsProteinFeature (com.compomics.util.io.export.features.peptideshaker.PsProteinFeature)2 XYDataPoint (no.uib.jsparklines.data.XYDataPoint)2 ProteinMatch (com.compomics.util.experiment.identification.matches.ProteinMatch)1 PSParameter (com.compomics.util.experiment.identification.peptide_shaker.PSParameter)1 ExportFeature (com.compomics.util.io.export.ExportFeature)1