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++;
}
}
}
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();
}
Aggregations