Search in sources :

Example 1 with PsFragmentFeature

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

the class PsFragmentSection method writeSection.

/**
 * Writes the desired section.
 *
 * @param spectrumFile The file name of the spectrum.
 * @param spectrumTitle The title of the spectrum.
 * @param spectrumIdentificationAssumption The spectrum identification of
 * interest.
 * @param sequenceProvider The sequence provider.
 * @param spectrumProvider The spectrum provider.
 * @param identificationParameters The identification parameters.
 * @param linePrefix The line prefix.
 * @param waitingHandler The waiting handler.
 *
 * @throws IOException exception thrown whenever an error occurred while
 * writing the file
 */
public void writeSection(String spectrumFile, String spectrumTitle, SpectrumIdentificationAssumption spectrumIdentificationAssumption, SequenceProvider sequenceProvider, SpectrumProvider spectrumProvider, IdentificationParameters identificationParameters, String linePrefix, WaitingHandler waitingHandler) throws IOException {
    if (waitingHandler != null) {
        waitingHandler.setSecondaryProgressCounterIndeterminate(true);
    }
    if (header) {
        writeHeader();
    }
    IonMatch[] annotations;
    Spectrum spectrum = spectrumProvider.getSpectrum(spectrumFile, spectrumTitle);
    AnnotationParameters annotationParameters = identificationParameters.getAnnotationParameters();
    ModificationParameters modificationParameters = identificationParameters.getSearchParameters().getModificationParameters();
    SequenceMatchingParameters modificationSequenceMatchingParameters = identificationParameters.getModificationLocalizationParameters().getSequenceMatchingParameters();
    if (spectrumIdentificationAssumption instanceof PeptideAssumption) {
        PeptideAssumption peptideAssumption = (PeptideAssumption) spectrumIdentificationAssumption;
        PeptideSpectrumAnnotator spectrumAnnotator = new PeptideSpectrumAnnotator();
        SpecificAnnotationParameters specificAnnotationParameters = annotationParameters.getSpecificAnnotationParameters(spectrumFile, spectrumTitle, spectrumIdentificationAssumption, modificationParameters, sequenceProvider, modificationSequenceMatchingParameters, spectrumAnnotator);
        annotations = spectrumAnnotator.getSpectrumAnnotation(annotationParameters, specificAnnotationParameters, spectrumFile, spectrumTitle, spectrum, peptideAssumption.getPeptide(), modificationParameters, sequenceProvider, modificationSequenceMatchingParameters);
    } else if (spectrumIdentificationAssumption instanceof TagAssumption) {
        TagAssumption tagAssumption = (TagAssumption) spectrumIdentificationAssumption;
        TagSpectrumAnnotator spectrumAnnotator = new TagSpectrumAnnotator();
        SpecificAnnotationParameters specificAnnotationParameters = annotationParameters.getSpecificAnnotationParameters(spectrumFile, spectrumTitle, spectrumIdentificationAssumption, modificationParameters, sequenceProvider, modificationSequenceMatchingParameters, spectrumAnnotator);
        annotations = spectrumAnnotator.getSpectrumAnnotation(annotationParameters, modificationParameters, modificationSequenceMatchingParameters, specificAnnotationParameters, spectrumFile, spectrumTitle, spectrum, tagAssumption.getTag());
    } else {
        throw new UnsupportedOperationException("Export not implemented for spectrum identification of type " + spectrumIdentificationAssumption.getClass() + ".");
    }
    TreeMap<Double, ArrayList<IonMatch>> sortedAnnotation = new TreeMap<>();
    for (IonMatch ionMatch : annotations) {
        double mz = ionMatch.peakMz;
        if (!sortedAnnotation.containsKey(mz)) {
            sortedAnnotation.put(mz, new ArrayList<>(1));
        }
        sortedAnnotation.get(mz).add(ionMatch);
    }
    int line = 1;
    if (waitingHandler != null) {
        waitingHandler.setWaitingText("Exporting. Please Wait...");
        waitingHandler.resetSecondaryProgressCounter();
        waitingHandler.setMaxSecondaryProgressCounter(annotations.length);
    }
    for (Entry<Double, ArrayList<IonMatch>> entry : sortedAnnotation.entrySet()) {
        for (IonMatch ionMatch : entry.getValue()) {
            if (waitingHandler != null) {
                if (waitingHandler.isRunCanceled()) {
                    return;
                }
                waitingHandler.increaseSecondaryProgressCounter();
            }
            if (indexes) {
                if (linePrefix != null) {
                    writer.write(linePrefix);
                }
                writer.write(Integer.toString(line));
                writer.addSeparator();
            }
            for (PsFragmentFeature fragmentFeature : fragmentFeatures) {
                switch(fragmentFeature) {
                    case annotation:
                        writer.write(ionMatch.getPeakAnnotation());
                        break;
                    case fragment_type:
                        writer.write(Ion.getTypeAsString(ionMatch.ion.getType()));
                        break;
                    case fragment_subType:
                        writer.write(ionMatch.ion.getSubTypeAsString());
                        break;
                    case fragment_number:
                        Ion ion = ionMatch.ion;
                        if (ion.getType() == Ion.IonType.PEPTIDE_FRAGMENT_ION) {
                            writer.write(Integer.toString(((PeptideFragmentIon) ion).getNumber()));
                        }
                        break;
                    case fragment_losses:
                        writer.write(ionMatch.ion.getNeutralLossesAsString());
                        break;
                    case fragment_name:
                        ion = ionMatch.ion;
                        String name = ion.getType() == Ion.IonType.PEPTIDE_FRAGMENT_ION ? ((PeptideFragmentIon) ion).getNameWithNumber() : ion.getName();
                        writer.write(name);
                        break;
                    case fragment_charge:
                        writer.write(Integer.toString(ionMatch.charge));
                        break;
                    case theoretic_mz:
                        writer.write(Double.toString(ionMatch.ion.getTheoreticMz(ionMatch.charge)));
                        break;
                    case mz:
                        writer.write(Double.toString(ionMatch.peakMz));
                        break;
                    case intensity:
                        writer.write(Double.toString(ionMatch.peakIntensity));
                        break;
                    case error_Da:
                        writer.write(Double.toString(ionMatch.getAbsoluteError()));
                        break;
                    case error_ppm:
                        writer.write(Double.toString(ionMatch.getRelativeError()));
                        break;
                    default:
                        writer.write("Not implemented");
                }
                writer.addSeparator();
            }
            writer.newLine();
            line++;
        }
    }
}
Also used : PsFragmentFeature(com.compomics.util.io.export.features.peptideshaker.PsFragmentFeature) SpecificAnnotationParameters(com.compomics.util.experiment.identification.spectrum_annotation.SpecificAnnotationParameters) AnnotationParameters(com.compomics.util.experiment.identification.spectrum_annotation.AnnotationParameters) ArrayList(java.util.ArrayList) ModificationParameters(com.compomics.util.parameters.identification.search.ModificationParameters) Ion(com.compomics.util.experiment.biology.ions.Ion) PeptideFragmentIon(com.compomics.util.experiment.biology.ions.impl.PeptideFragmentIon) SpecificAnnotationParameters(com.compomics.util.experiment.identification.spectrum_annotation.SpecificAnnotationParameters) TreeMap(java.util.TreeMap) Spectrum(com.compomics.util.experiment.mass_spectrometry.spectra.Spectrum) TagAssumption(com.compomics.util.experiment.identification.spectrum_assumptions.TagAssumption) IonMatch(com.compomics.util.experiment.identification.matches.IonMatch) TagSpectrumAnnotator(com.compomics.util.experiment.identification.spectrum_annotation.spectrum_annotators.TagSpectrumAnnotator) PeptideFragmentIon(com.compomics.util.experiment.biology.ions.impl.PeptideFragmentIon) SequenceMatchingParameters(com.compomics.util.parameters.identification.advanced.SequenceMatchingParameters) PeptideAssumption(com.compomics.util.experiment.identification.spectrum_assumptions.PeptideAssumption) PeptideSpectrumAnnotator(com.compomics.util.experiment.identification.spectrum_annotation.spectrum_annotators.PeptideSpectrumAnnotator)

Example 2 with PsFragmentFeature

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

the class PsFragmentSection method writeHeader.

/**
 * Writes the header of this section.
 *
 * @throws IOException exception thrown whenever an error occurred while
 * writing the file
 */
public void writeHeader() throws IOException {
    if (indexes) {
        writer.writeHeaderText("");
        writer.addSeparator();
    }
    boolean firstColumn = true;
    for (PsFragmentFeature fragmentFeature : fragmentFeatures) {
        if (firstColumn) {
            firstColumn = false;
        } else {
            writer.addSeparator();
        }
        writer.writeHeaderText(fragmentFeature.getTitle());
    }
    writer.newLine();
}
Also used : PsFragmentFeature(com.compomics.util.io.export.features.peptideshaker.PsFragmentFeature)

Aggregations

PsFragmentFeature (com.compomics.util.io.export.features.peptideshaker.PsFragmentFeature)2 Ion (com.compomics.util.experiment.biology.ions.Ion)1 PeptideFragmentIon (com.compomics.util.experiment.biology.ions.impl.PeptideFragmentIon)1 IonMatch (com.compomics.util.experiment.identification.matches.IonMatch)1 AnnotationParameters (com.compomics.util.experiment.identification.spectrum_annotation.AnnotationParameters)1 SpecificAnnotationParameters (com.compomics.util.experiment.identification.spectrum_annotation.SpecificAnnotationParameters)1 PeptideSpectrumAnnotator (com.compomics.util.experiment.identification.spectrum_annotation.spectrum_annotators.PeptideSpectrumAnnotator)1 TagSpectrumAnnotator (com.compomics.util.experiment.identification.spectrum_annotation.spectrum_annotators.TagSpectrumAnnotator)1 PeptideAssumption (com.compomics.util.experiment.identification.spectrum_assumptions.PeptideAssumption)1 TagAssumption (com.compomics.util.experiment.identification.spectrum_assumptions.TagAssumption)1 Spectrum (com.compomics.util.experiment.mass_spectrometry.spectra.Spectrum)1 SequenceMatchingParameters (com.compomics.util.parameters.identification.advanced.SequenceMatchingParameters)1 ModificationParameters (com.compomics.util.parameters.identification.search.ModificationParameters)1 ArrayList (java.util.ArrayList)1 TreeMap (java.util.TreeMap)1