Skip to content

Commit

Permalink
Improved meta data extraction from mzML
Browse files Browse the repository at this point in the history
  • Loading branch information
wenbostar committed May 24, 2023
1 parent cc0c918 commit f82ed87
Show file tree
Hide file tree
Showing 3 changed files with 93 additions and 21 deletions.
8 changes: 0 additions & 8 deletions .idea/modules.xml

This file was deleted.

10 changes: 0 additions & 10 deletions PDV.iml

This file was deleted.

96 changes: 93 additions & 3 deletions src/main/java/PDVGUI/fileimport/MSOneImport.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,15 @@
import io.github.msdk.io.mzml.data.MzMLRawDataFile;
import io.github.msdk.io.mzxml.MzXMLFileParser;
import io.github.msdk.io.mzxml.MzXMLRawDataFile;
import umich.ms.datatypes.LCMSDataSubset;
import umich.ms.datatypes.lcmsrun.LCMSRunInfo;
import umich.ms.datatypes.scan.IScan;
import umich.ms.datatypes.scan.StorageStrategy;
import umich.ms.datatypes.scancollection.IScanCollection;
import umich.ms.datatypes.scancollection.impl.ScanCollectionDefault;
import umich.ms.fileio.exceptions.FileParsingException;
import umich.ms.fileio.filetypes.mzml.MZMLFile;
import umich.ms.fileio.filetypes.mzml.MZMLIndex;

import java.io.File;
import java.math.BigInteger;
Expand Down Expand Up @@ -86,6 +95,8 @@ private void parseSpectrum(){

List<MsScan> msScans = mzMLRawDataFile.getScans();

System.out.println("Load file:"+spectrumFile.getAbsolutePath());

if (spectrumFile.length() > 524288000) {

for (Chromatogram chromatogram : mzMLRawDataFile.getChromatograms()) {
Expand All @@ -110,7 +121,7 @@ private void parseSpectrum(){

rtRange = chromatogram.getRtRange();

detailsList.add("RT/t/Start:"+rtRange.lowerEndpoint()+" End:"+rtRange.upperEndpoint());
detailsList.add("LC gradient length/t/"+String.format("%.0f",rtRange.lowerEndpoint())+" - "+String.format("%.0f",rtRange.upperEndpoint())+" min");
}

for (MsScan msScan : msScans) {
Expand All @@ -122,6 +133,7 @@ private void parseSpectrum(){
}

} else {
System.out.println("Extract meta information from mzML ...");

float startRT = 10000;
float endRT = 0f;
Expand Down Expand Up @@ -153,8 +165,16 @@ private void parseSpectrum(){
}

keyToRtAndInt.put("TIC", rtToItem);
detailsList.add("LC gradient length/t/"+String.format("%.0f",startRT)+" - "+String.format("%.0f",endRT)+" min");

//detailsList.add("RT (min)/t/Start:" + startRT +" End:" + endRT);
}

detailsList.add("RT (min)/t/Start:" + startRT +" End:" + endRT);
HashMap<String,String> ms2meta = get_ms2_meta(spectrumFilePath);
if(ms2meta.size()>=1) {
for(String item: ms2meta.keySet()){
detailsList.add(item+"/t/" + ms2meta.get(item));
}
}

} else if (spectrumFileType.equals("mzxml")){
Expand Down Expand Up @@ -202,8 +222,11 @@ private void parseSpectrum(){
msNum[0] = "MS Num";
msNum[1] = String.valueOf(ms1Count);
msNum[2] = String.valueOf(ms2Count);
detailsList.add("MS1 Spectra/t/"+ms1Count);
detailsList.add("MS2 Spectra/t/"+ms2Count);

detailsList.add("MS Num/t/MS1:"+ms1Count+" MS2:"+ms2Count);
// detailsList.add("MS Num/t/MS1:"+ms1Count+" MS2:"+ms2Count);
System.out.println("Load MS data: done!");
}

/**
Expand All @@ -228,4 +251,71 @@ public ArrayList<String> getDetailsList() {
public BigInteger getBiggestNum(){
return BigInteger.valueOf((long) biggestNum);
}


public HashMap<String, String> get_ms2_meta(String fullMsFilePath){

HashMap<String,String> ms2meta = new HashMap<>();
String frag_method = "-";
MZMLFile source = new MZMLFile(fullMsFilePath);

LCMSRunInfo lcmsRunInfo = null;
try {
lcmsRunInfo = source.fetchRunInfo();
} catch (FileParsingException e) {
e.printStackTrace();
}
source.setNumThreadsForParsing(1);
ms2meta.put("MS Instrument",source.getRunInfo().getDefaultInstrument().getModel());

MZMLIndex mzMLindex = null;
try {
mzMLindex = source.fetchIndex();
} catch (FileParsingException e) {
e.printStackTrace();
}

if (mzMLindex.size() > 0) {

} else {
System.err.println("Parsed index was empty!");
}

IScanCollection scans;

scans = new ScanCollectionDefault(true);
scans.setDataSource(source);
try {
scans.loadData(LCMSDataSubset.MS2_WITH_SPECTRA, StorageStrategy.STRONG);
} catch (FileParsingException e) {
e.printStackTrace();
}

TreeMap<Integer, IScan> num2scanMap = scans.getMapNum2scan();
Set<Map.Entry<Integer, IScan>> num2scanEntries = num2scanMap.entrySet();



for (Map.Entry<Integer, IScan> next : num2scanEntries) {
IScan scan = next.getValue();
if (scan.getSpectrum() != null) {
//System.out.println(scan.getNum());
if (scan.getMsLevel() == 2) {
frag_method = scan.getPrecursor().getActivationInfo().getActivationMethod();
double ce_h = scan.getPrecursor().getActivationInfo().getActivationEnergyHi();
double ce_l = scan.getPrecursor().getActivationInfo().getActivationEnergyLo();
if(ce_h == ce_l){
ms2meta.put("MS2 CE",String.valueOf(ce_h));
}else{
ms2meta.put("MS2 CE",String.valueOf(ce_l)+":"+String.valueOf(ce_h));
}
ms2meta.put("MS2 Fragmentation",frag_method);
// ms2meta.put("MS2 Analyzer",scan.getInstrument().getAnalyzer());
// ms2meta.put("MS2 Detector",scan.getInstrument().getDetector());
break;
}
}
}
return ms2meta;
}
}

0 comments on commit f82ed87

Please sign in to comment.