compomics / compomics-utilities

Open source Java library for computational proteomics
http://compomics.github.io/projects/compomics-utilities.html
29 stars 17 forks source link

getSpectrumTitle function #40

Closed wenbostar closed 3 years ago

wenbostar commented 3 years ago

Hi,

The function getSpectrumTitle in Spectrum class is no longer supported in version 5.0.9?

Bo

hbarsnes commented 3 years ago

Hi Bo,

No changes for this method in version 5.0.9, but we did refactor the spectrum handling code in order to also support mzML files a while back and it seems like this method was (re)moved in the process.

Can you tell us specifically how you are currently using the getSpectrumTitle method so that we can hopefully guide you to how to do the same with the refactored code?

Best regards, Harald

wenbostar commented 3 years ago

Hi Harald,

Thanks for your help. Below is how I'm using getSpectrumTitle:

File mgfFile = new File(spectraFile);
MgfFileIterator mgfFileIterator = new MgfFileIterator(mgfFile);
int i=0;
Spectrum spectrum = null;
while(mgfFileIterator.hasNext()){
    i++;
    spectrum = mgfFileIterator.next();
    String raw_title = spectrum.getSpectrumTitle();
    spectrum.setSpectrumTitle(String.valueOf(i));
    // process which uses raw_title and spectrum
    // the downstream process needs to access the spectrum title by getSpectrumTitle function.
}
hbarsnes commented 3 years ago

I think you should be able to do what you need with the following code:

File mgfFile = new File(spectraFile);
MgfFileIterator mgfFileIterator = new MgfFileIterator(mgfFile, new WaitingHandlerDummy());

String spectrumTitle = mgfFileIterator.next();

while (spectrumTitle != null) {

      Spectrum spectrum = mgfFileIterator.getSpectrum();

      // process data

      spectrumTitle = mgfFileIterator.next();

}