Skip to content

Commit

Permalink
Merge pull request #9 from f-taruttis/developtar
Browse files Browse the repository at this point in the history
Developtar
  • Loading branch information
s-wolf committed Nov 7, 2011
2 parents 38ac59b + 5bcf796 commit 868da47
Show file tree
Hide file tree
Showing 5 changed files with 120 additions and 48 deletions.
79 changes: 41 additions & 38 deletions src/de/ipbhalle/metfrag/massbankParser/NewMassbankParser.java
Expand Up @@ -172,6 +172,8 @@ public static Vector<Spectrum> 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;
Expand Down Expand Up @@ -202,10 +204,11 @@ public static Vector<Spectrum> Read(String filename) {

Map< String , Map <String, ArrayList<String>>> record = new HashMap < String , Map <String, ArrayList<String>>>();

peaks = new Vector<Peak>();

String lineTest="";


boolean readPeaks=false;

try {
BufferedReader in = new BufferedReader(new FileReader(filename));
Expand Down Expand Up @@ -269,15 +272,26 @@ public static Vector<Spectrum> 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<Peak>();




while(!line.contains("//"))/* && line!=null*/
while(!line.contains("//") && readPeaks)/* && line!=null*/
{


String splitString[] = new String[line.split("\\s+").length];
splitString=line.split("\\s+");

Expand All @@ -287,6 +301,7 @@ public static Vector<Spectrum> Read(String filename) {
}



line = in.readLine();

}
Expand Down Expand Up @@ -323,8 +338,8 @@ public static Vector<Spectrum> 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=") )
{
Expand Down Expand Up @@ -359,12 +374,18 @@ public static Vector<Spectrum> 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];

}
}
Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -581,31 +602,7 @@ public static Map<String,Double> readPrecursorTypes()
return preType;
}


/*
class CH${
ArrayList<String> name;
ArrayList<String> compoundClass;
String formula;
double mass;
String smiles;
String iupac;
HashMap<String,String> link;
ArrayList<String> comment;
public CH$(String line)
{
}
}*/



/**
Expand All @@ -618,15 +615,21 @@ public static void main(String[] args) {
//Vector<Spectrum> spectra = Read("/home/ftarutti/records/CO000001.txt");
//Vector<Spectrum> spectra = Read("/home/ftarutti/records/PB000122.txt");
//Vector<Spectrum> spectra = Read("/home/ftarutti/records/PR100124.txt");
Vector<Spectrum> spectra = Read("/vol/massbank/data/records/PR100975.txt");
//Vector<Spectrum> spectra = Read("/vol/massbank/data/records/PR100975.txt");
//Vector<Spectrum> spectra = Read("/home/ftarutti/records/PR100040.txt");
//Vector<Spectrum> spectra = Read("/home/ftarutti/records/PB006007.txt");

//Vector<Spectrum> spectra = Read("/home/ftarutti/Desktop/test");
Vector<Spectrum> spectra = Read("/home/ftarutti/testspectra/tmp/CO000510.txt");
for (Spectrum spectrum : spectra) {

spectrum.show();
}
Vector<Peak> peaks = spectrum.getPeaks();

for (Peak peak : peaks) {
System.out.println(peak.toString());
}

}

}
}
12 changes: 12 additions & 0 deletions src/de/ipbhalle/metfrag/massbankParser/Peak.java
Expand Up @@ -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();
}
}
29 changes: 23 additions & 6 deletions src/de/ipbhalle/metfrag/massbankParser/Spectrum.java
Expand Up @@ -38,6 +38,8 @@ public class Spectrum implements java.io.Serializable, Comparable<Spectrum> {
private int CID;
private String KEGG;
private String CHEBI;
private String metlin;
private String knapsack;
private String nameTrivial;
private String formula;
private boolean isPositive;
Expand All @@ -46,7 +48,7 @@ public class Spectrum implements java.io.Serializable, Comparable<Spectrum> {

private String smiles;

public Spectrum(int collisionEnergy, double tic, Vector<Peak> 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<Peak> 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;
Expand All @@ -56,6 +58,8 @@ public Spectrum(int collisionEnergy, double tic, Vector<Peak> 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;
Expand All @@ -66,7 +70,7 @@ public Spectrum(int collisionEnergy, double tic, Vector<Peak> peaks, double exac
this.smiles = smiles;
}

public Spectrum(int collisionEnergy, double tic, Vector<Peak> 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<Peak> 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;
Expand All @@ -76,6 +80,7 @@ public Spectrum(int collisionEnergy, double tic, Vector<Peak> peaks, double exac
this.InchI = InchI;
this.CID = CID;
this.KEGG = KEGG;
this.metlin=metlin;
this.nameTrivial = nameTrivial;
this.precursorMZ = precursorMZ;
this.precursorType = precursorType;
Expand All @@ -84,12 +89,12 @@ public Spectrum(int collisionEnergy, double tic, Vector<Peak> peaks, double exac
this.CHEBI = CHEBI;
}

public Spectrum(int collisionEnergy, Vector<Peak> 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<Peak> 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<Peak> 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<Peak> 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(){
Expand Down Expand Up @@ -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;
}
Expand Down
16 changes: 14 additions & 2 deletions src/de/ipbhalle/metfrag/spectrum/PreprocessSpectra.java
Expand Up @@ -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<WrapperSpectrum> spectra = new Vector<WrapperSpectrum>();

String lastFile = "";

for (File file : pubchemToFiles.get(pubchemID)) {
Expand All @@ -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<Double> mergedPeaks = mergePeaks(spectra, mzabs, mzppm);
//now write back those peaks into a new file
String line = "";
Expand Down Expand Up @@ -252,19 +257,26 @@ private Vector<Double> mergePeaks(Vector<WrapperSpectrum> spectra, double mzabs,
Vector<Double> newPeakList = new Vector<Double>();
newIntensity = new Vector<Double>();
newRelIntensity = new Vector<Double>();


this.peaksIntensity = new HashMap<Double, Vector<Double>>();
this.peaksRelIntensity = new HashMap<Double, Vector<Double>>();
for (int i = 0; i < spectra.size(); i++) {
System.out.println("Spectra number: "+i);
System.out.println(spectra.get(i).toString());
Vector<Peak> 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);
Expand Down Expand Up @@ -436,7 +448,7 @@ private HashMap<Double, Vector<Double>> addToMap(HashMap<Double, Vector<Double>>

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);
Expand Down

0 comments on commit 868da47

Please sign in to comment.