diff --git a/src/de/ipbhalle/metfrag/massbankParser/NewMassbankParser.java b/src/de/ipbhalle/metfrag/massbankParser/NewMassbankParser.java index 00bbd05..bdd3115 100644 --- a/src/de/ipbhalle/metfrag/massbankParser/NewMassbankParser.java +++ b/src/de/ipbhalle/metfrag/massbankParser/NewMassbankParser.java @@ -172,6 +172,8 @@ public static Vector Read(String filename) { int linkPubChem = 0; String linkCHEBI = ""; String linkKEGG = "none"; + String linkMetlin="none"; + String linkKnapSack ="none"; String[] array; String IUPAC = ""; int mode = 0, collisionEnergy = 0; @@ -202,10 +204,11 @@ public static Vector Read(String filename) { Map< String , Map >> record = new HashMap < String , Map >>(); + peaks = new Vector(); String lineTest=""; - + boolean readPeaks=false; try { BufferedReader in = new BufferedReader(new FileReader(filename)); @@ -269,15 +272,26 @@ public static Vector Read(String filename) { line = in.readLine(); + if(line.contains("PK$PEAK:")) + { + + readPeaks=true; + line = in.readLine(); + } + } //read Peaks if(line.equals("")) break; - peaks = new Vector(); + + + - while(!line.contains("//"))/* && line!=null*/ + while(!line.contains("//") && readPeaks)/* && line!=null*/ { + + String splitString[] = new String[line.split("\\s+").length]; splitString=line.split("\\s+"); @@ -287,6 +301,7 @@ public static Vector Read(String filename) { } + line = in.readLine(); } @@ -323,8 +338,8 @@ public static Vector Read(String filename) { nameTrivial = record.get(CH$).get(CH$+CH.NAME.toString()).get(1); } - - instrument = record.get(AC$).get(AC$+AC.INSTRUMENT.toString()).get(0); + if(record.get(AC$).containsKey(AC$+AC.INSTRUMENT.toString()) ) + instrument = record.get(AC$).get(AC$+AC.INSTRUMENT.toString()).get(0); if(record.get(CH$).get(CH$+CH.IUPAC.toString()).get(0).contains("InChI=") ) { @@ -359,12 +374,18 @@ public static Vector Read(String filename) { splitString = dblink[2].split(":"); - linkPubChem = Integer.valueOf(splitString[1]).intValue(); - - } else if (dblink[1].equals("KEGG")) + if(splitString.length>=2) + { + linkPubChem = Integer.valueOf(splitString[1]).intValue(); + } + } else if (dblink[1].equals("KEGG") && dblink.length >=3) linkKEGG = dblink[2]; - else if (dblink[1].equals("CHEBI")) + else if (dblink[1].equals("CHEBI") && dblink.length >=3) linkCHEBI = dblink[2]; + else if (dblink[1].contains("METLIN") && dblink.length>=3) + linkMetlin=dblink[2]; + else if (dblink[1].contains("KNAPSACK") && dblink.length>=3) + linkKnapSack=dblink[2]; } } @@ -481,7 +502,7 @@ else if (dblink[1].equals("CHEBI")) } - spectra.add(new Spectrum(collisionEnergy, peaks, mass, mode, IUPAC, linkPubChem, linkKEGG, linkCHEBI, nameTrivial, formula, precursorMZ, precursorType, isPositive, smiles)); + spectra.add(new Spectrum(collisionEnergy, peaks, mass, mode, IUPAC, linkPubChem, linkKEGG, linkCHEBI,linkMetlin , linkKnapSack ,nameTrivial, formula, precursorMZ, precursorType, isPositive, smiles)); return spectra; } @@ -581,31 +602,7 @@ public static Map readPrecursorTypes() return preType; } - - /* - class CH${ - - ArrayList name; - ArrayList compoundClass; - - String formula; - double mass; - - String smiles; - String iupac; - - HashMap link; - - ArrayList comment; - - public CH$(String line) - { - - - } - - - }*/ + /** @@ -618,15 +615,21 @@ public static void main(String[] args) { //Vector spectra = Read("/home/ftarutti/records/CO000001.txt"); //Vector spectra = Read("/home/ftarutti/records/PB000122.txt"); //Vector spectra = Read("/home/ftarutti/records/PR100124.txt"); - Vector spectra = Read("/vol/massbank/data/records/PR100975.txt"); + //Vector spectra = Read("/vol/massbank/data/records/PR100975.txt"); //Vector spectra = Read("/home/ftarutti/records/PR100040.txt"); //Vector spectra = Read("/home/ftarutti/records/PB006007.txt"); - //Vector spectra = Read("/home/ftarutti/Desktop/test"); + Vector spectra = Read("/home/ftarutti/testspectra/tmp/CO000510.txt"); for (Spectrum spectrum : spectra) { spectrum.show(); - } + Vector peaks = spectrum.getPeaks(); + + for (Peak peak : peaks) { + System.out.println(peak.toString()); + } + + } } } diff --git a/src/de/ipbhalle/metfrag/massbankParser/Peak.java b/src/de/ipbhalle/metfrag/massbankParser/Peak.java index e2e5140..4572a7a 100644 --- a/src/de/ipbhalle/metfrag/massbankParser/Peak.java +++ b/src/de/ipbhalle/metfrag/massbankParser/Peak.java @@ -146,4 +146,16 @@ public int compareTo(Peak p){ public int getNominalMass(){ return (int)Math.round(this.mass); } + + @Override public String toString() { + StringBuilder result = new StringBuilder(); + String NEW_LINE = System.getProperty("line.separator"); + + result.append("Intensity: "+this.intensity+NEW_LINE); + result.append("Relative Intesity: "+this.relIntensity+NEW_LINE); + result.append("Mass: "+this.mass+NEW_LINE); + result.append(NEW_LINE); + + return result.toString(); + } } diff --git a/src/de/ipbhalle/metfrag/massbankParser/Spectrum.java b/src/de/ipbhalle/metfrag/massbankParser/Spectrum.java index f0d0f4b..613903b 100644 --- a/src/de/ipbhalle/metfrag/massbankParser/Spectrum.java +++ b/src/de/ipbhalle/metfrag/massbankParser/Spectrum.java @@ -38,6 +38,8 @@ public class Spectrum implements java.io.Serializable, Comparable { private int CID; private String KEGG; private String CHEBI; + private String metlin; + private String knapsack; private String nameTrivial; private String formula; private boolean isPositive; @@ -46,7 +48,7 @@ public class Spectrum implements java.io.Serializable, Comparable { private String smiles; - public Spectrum(int collisionEnergy, double tic, Vector peaks, double exactMass, int mode, String InchI, int CID, String KEGG, String CHEBI, String nameTrivial, String formula, double precursorMZ, String precursorType, boolean isPositive, String smiles){ + public Spectrum(int collisionEnergy, double tic, Vector peaks, double exactMass, int mode, String InchI, int CID, String KEGG, String CHEBI,String metlin,String knapsack, String nameTrivial, String formula, double precursorMZ, String precursorType, boolean isPositive, String smiles){ this.collisionEnergy = collisionEnergy; this.tic = tic; @@ -56,6 +58,8 @@ public Spectrum(int collisionEnergy, double tic, Vector peaks, double exac this.InchI = InchI; this.CID = CID; this.KEGG = KEGG; + this.metlin = metlin; + this.knapsack = knapsack; this.nameTrivial = nameTrivial; this.precursorMZ = precursorMZ; this.precursorType = precursorType; @@ -66,7 +70,7 @@ public Spectrum(int collisionEnergy, double tic, Vector peaks, double exac this.smiles = smiles; } - public Spectrum(int collisionEnergy, double tic, Vector peaks, double exactMass, int mode, String InchI, int CID, String KEGG, String CHEBI, String nameTrivial, String formula, double precursorMZ, String precursorType, boolean isPositive){ + public Spectrum(int collisionEnergy, double tic, Vector peaks, double exactMass, int mode, String InchI, int CID, String KEGG, String CHEBI,String metlin, String nameTrivial, String formula, double precursorMZ, String precursorType, boolean isPositive){ this.collisionEnergy = collisionEnergy; this.tic = tic; @@ -76,6 +80,7 @@ public Spectrum(int collisionEnergy, double tic, Vector peaks, double exac this.InchI = InchI; this.CID = CID; this.KEGG = KEGG; + this.metlin=metlin; this.nameTrivial = nameTrivial; this.precursorMZ = precursorMZ; this.precursorType = precursorType; @@ -84,12 +89,12 @@ public Spectrum(int collisionEnergy, double tic, Vector peaks, double exac this.CHEBI = CHEBI; } - public Spectrum(int collisionEnergy, Vector peaks, double exactMass, int mode, String InchI, int CID, String KEGG, String linkCHEBI, String nameTrivial, String formula, double precursorMZ, String precursorType, boolean isPositive,String smiles){ - this( collisionEnergy, 0.0, peaks, exactMass, mode, InchI, CID, KEGG, linkCHEBI, nameTrivial, formula, precursorMZ, precursorType, isPositive,smiles); + public Spectrum(int collisionEnergy, Vector peaks, double exactMass, int mode, String InchI, int CID, String KEGG, String linkCHEBI,String linkMetlin, String linkKnapsack ,String nameTrivial, String formula, double precursorMZ, String precursorType, boolean isPositive,String smiles){ + this( collisionEnergy, 0.0, peaks, exactMass, mode, InchI, CID, KEGG, linkCHEBI,linkMetlin,linkKnapsack, nameTrivial, formula, precursorMZ, precursorType, isPositive,smiles); } - public Spectrum(int collisionEnergy, Vector peaks, double exactMass, int mode, String InchI, int CID, String KEGG, String linkCHEBI, String nameTrivial, String formula, double precursorMZ, String precursorType, boolean isPositive){ - this( collisionEnergy, 0.0, peaks, exactMass, mode, InchI, CID, KEGG, linkCHEBI, nameTrivial, formula, precursorMZ, precursorType, isPositive); + public Spectrum(int collisionEnergy, Vector peaks, double exactMass, int mode, String InchI, int CID, String KEGG, String linkCHEBI,String linkMetlin, String nameTrivial, String formula, double precursorMZ, String precursorType, boolean isPositive){ + this( collisionEnergy, 0.0, peaks, exactMass, mode, InchI, CID, KEGG, linkCHEBI,linkMetlin, nameTrivial, formula, precursorMZ, precursorType, isPositive); } public int getCollisionEnergy(){ @@ -245,6 +250,18 @@ public String getCHEBI() { return CHEBI; } + public void setMetlin(String metlin) { + this.metlin = metlin; + } + + public String getMetlin() { + return metlin; + } + + public String getKnapsack() { + return knapsack; + } + public String getSmiles(){ return smiles; } diff --git a/src/de/ipbhalle/metfrag/spectrum/PreprocessSpectra.java b/src/de/ipbhalle/metfrag/spectrum/PreprocessSpectra.java index 8245602..af15091 100644 --- a/src/de/ipbhalle/metfrag/spectrum/PreprocessSpectra.java +++ b/src/de/ipbhalle/metfrag/spectrum/PreprocessSpectra.java @@ -87,11 +87,12 @@ private void preprocessUnsorted(String folder, double mzabs, double mzppm) System.out.println(files[i].toString() + spectrum.getCID()); } } - + for (String pubchemID : pubchemToFiles.keySet()) { String mergedNames = ""; Vector spectra = new Vector(); + String lastFile = ""; for (File file : pubchemToFiles.get(pubchemID)) { @@ -103,12 +104,16 @@ private void preprocessUnsorted(String folder, double mzabs, double mzppm) continue; spectra.add(spectrum); + + mergedNames += file.getName().split("\\.")[0]; lastFile = file.toString(); } //now merge the peaks from the different collision energies + //System.out.println(spectra.get(0).getPeakList().toString()); + Vector mergedPeaks = mergePeaks(spectra, mzabs, mzppm); //now write back those peaks into a new file String line = ""; @@ -252,19 +257,26 @@ private Vector mergePeaks(Vector spectra, double mzabs, Vector newPeakList = new Vector(); newIntensity = new Vector(); newRelIntensity = new Vector(); + this.peaksIntensity = new HashMap>(); this.peaksRelIntensity = new HashMap>(); for (int i = 0; i < spectra.size(); i++) { + System.out.println("Spectra number: "+i); + System.out.println(spectra.get(i).toString()); Vector tempPeaks = spectra.get(i).getPeakList(); for (int j = 0; j < tempPeaks.size(); j++) { //peaks.add(tempPeaks.get(j).getMass()); + System.out.println(tempPeaks.get(j).toString()); peaksIntensity = addToMap(peaksIntensity, tempPeaks.get(j).getMass(), tempPeaks.get(j).getIntensity()); peaksRelIntensity = addToMap(peaksRelIntensity, tempPeaks.get(j).getMass(),tempPeaks.get(j).getRelIntensity()); } } + System.out.println(peaksIntensity.toString()); + Double[] peakArray = new Double[peaksIntensity.size()]; + peakArray = peaksIntensity.keySet().toArray(peakArray); //sort peak list Arrays.sort(peakArray); @@ -436,7 +448,7 @@ private HashMap> addToMap(HashMap> public static void main(String[] args) { // String folder = "/home/swolf/MassBankData/MetFragSunGrid/BrukerRawData/Processed/"; - String folder = "/home/ftarutti/testspectra/"; + String folder = "/home/ftarutti/testspectra/tmp/"; // String folder = "/home/swolf/test/"; PreprocessSpectra pps = new PreprocessSpectra(); pps.preprocessUnsorted(folder, 0.002, 10); diff --git a/src/de/ipbhalle/metfrag/spectrum/WrapperSpectrum.java b/src/de/ipbhalle/metfrag/spectrum/WrapperSpectrum.java index c3c0a5c..7a7b9dc 100644 --- a/src/de/ipbhalle/metfrag/spectrum/WrapperSpectrum.java +++ b/src/de/ipbhalle/metfrag/spectrum/WrapperSpectrum.java @@ -63,6 +63,8 @@ public class WrapperSpectrum { private int CID; private String KEGG; private String chebi; + private String metlin; + private String knapsack; private String nameTrivial; private String filename; private String formula; @@ -86,6 +88,8 @@ public WrapperSpectrum(String filename){ this.InchI = spectra.get(0).getInchi(); this.CID = spectra.get(0).getCID(); this.KEGG = spectra.get(0).getKEGG(); + this.metlin=spectra.get(0).getMetlin(); + this.knapsack =spectra.get(0).getKnapsack(); this.nameTrivial = spectra.get(0).getTrivialName(); this.chebi = spectra.get(0).getCHEBI(); this.setPrecursorType(spectra.get(0).getPrecursorType()); @@ -110,7 +114,7 @@ public WrapperSpectrum(String filename){ public WrapperSpectrum(String peakString, int mode, double exactMass, boolean isPositive, String smiles){ this.spectra = new Vector(); this.collisionEnergy = -1; - spectra.add(new Spectrum(-1, parsePeaks(peakString), exactMass, mode, "none", -1, "none", "none", "none", "", 0.0, "", isPositive,smiles)); + spectra.add(new Spectrum(-1, parsePeaks(peakString), exactMass, mode, "none", -1, "none", "none", "none","none","none", "", 0.0, "", isPositive,smiles)); this.peaks = spectra.get(0).getPeaks(); //just one spectra for now this.exactMass = spectra.get(0).getExactMass(); @@ -119,6 +123,8 @@ public WrapperSpectrum(String peakString, int mode, double exactMass, boolean is this.CID = spectra.get(0).getCID(); this.KEGG = spectra.get(0).getKEGG(); this.chebi = spectra.get(0).getCHEBI(); + this.metlin=spectra.get(0).getMetlin(); + this.knapsack=spectra.get(0).getKnapsack(); this.nameTrivial = spectra.get(0).getTrivialName(); this.setFormula(spectra.get(0).getFormula()); this.setPositive(isPositive); @@ -138,7 +144,7 @@ public WrapperSpectrum(String peakString, int mode, double exactMass, boolean is public WrapperSpectrum(String peakString, int mode, double exactMass, boolean isPositive){ this.spectra = new Vector(); this.collisionEnergy = -1; - spectra.add(new Spectrum(-1, parsePeaks(peakString), exactMass, mode, "none", -1, "none", "none", "none", "", 0.0, "", isPositive)); + spectra.add(new Spectrum(-1, parsePeaks(peakString), exactMass, mode, "none", -1, "none", "none", "none","none", "", 0.0, "", isPositive)); this.peaks = spectra.get(0).getPeaks(); //just one spectra for now this.exactMass = spectra.get(0).getExactMass(); @@ -147,6 +153,8 @@ public WrapperSpectrum(String peakString, int mode, double exactMass, boolean is this.CID = spectra.get(0).getCID(); this.KEGG = spectra.get(0).getKEGG(); this.chebi = spectra.get(0).getCHEBI(); + this.metlin=spectra.get(0).getMetlin(); + this.knapsack=spectra.get(0).getKnapsack(); this.nameTrivial = spectra.get(0).getTrivialName(); this.setFormula(spectra.get(0).getFormula()); this.setPositive(isPositive); @@ -317,6 +325,26 @@ public int getCID() return this.CID; } + /** + * Gets the Metlin ID. + * + * @return the Metlin ID + */ + public String getMetlin() + { + return this.metlin; + } + + /** + * Gets the Knapsack ID. + * + * @return the Knapsack ID + */ + public String getKnapsack() + { + return this.knapsack; + } + /** * Gets the collision energy. *