Skip to content

Commit

Permalink
Sync files with MassBank3-export-service
Browse files Browse the repository at this point in the history
  • Loading branch information
meier-rene committed Jan 22, 2025
1 parent 8d7ebc0 commit 9dc4684
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 68 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -569,7 +569,7 @@ public String createRecordString() {
sb.append("<b>CH$IUPAC:</b> ").append(CH_IUPAC()).append("<br>\n");
CH_LINK().forEach((key,value) -> {
switch(key){
case "CAS":
case "CAS", "INCHIKEY":
sb.append("<b>CH$LINK:</b> ").append(key).append(" <a href=\"https://www.google.com/search?q=&quot;").append(value).append("&quot;\" target=\"_blank\">").append(value).append("</a><br>\n");
break;
case "CAYMAN":
Expand All @@ -587,9 +587,6 @@ public String createRecordString() {
case "HMDB":
sb.append("<b>CH$LINK:</b> ").append(key).append(" <a href=\"http://www.hmdb.ca/metabolites/").append(value).append("\" target=\"_blank\">").append(value).append("</a><br>\n");
break;
case "INCHIKEY":
sb.append("<b>CH$LINK:</b> ").append(key).append(" <a href=\"https://www.google.com/search?q=&quot;").append(value).append("&quot;\" target=\"_blank\">").append(value).append("</a><br>\n");
break;
case "KAPPAVIEW":
sb.append("<b>CH$LINK:</b> ").append(key).append(" <a href=\"http://kpv.kazusa.or.jp/kpv4/compoundInformation/view.action?id=").append(value).append("\" target=\"_blank\">").append(value).append("</a><br>\n");
break;
Expand All @@ -599,7 +596,6 @@ public String createRecordString() {
case "KNAPSACK":
sb.append("<b>CH$LINK:</b> ").append(key).append(" <a href=\"http://www.knapsackfamily.com/knapsack_jsp/information.jsp?sname=C_ID&word=").append(value).append("\" target=\"_blank\">").append(value).append("</a><br>\n");
break;

case "LIPIDBANK":
sb.append("<b>CH$LINK:</b> ").append(key).append(" <a href=\"http://lipidbank.jp/cgi-bin/detail.cgi?id=").append(value).append("\" target=\"_blank\">").append(value).append("</a><br>\n");
break;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
package massbank.export;

import massbank.Record;
import org.apache.commons.lang3.tuple.Triple;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;
import org.apache.commons.lang3.tuple.Triple;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.openscience.cdk.exception.CDKException;
import massbank.Record;

/*
MONA *.msp format III:
Expand Down Expand Up @@ -80,7 +80,7 @@ public class RecordToNIST_MSP {
* A plain converter Record to String with RIKEN PRIME msp.
* @param record to convert
*/
public static String convert(Record record) {
public static String convert(massbank.Record record) {
StringBuilder sb = new StringBuilder();

if (record.DEPRECATED()) {
Expand All @@ -89,32 +89,32 @@ public static String convert(Record record) {
}

List<String> tmpList = record.CH_NAME();
sb.append("Name: ").append(tmpList.get(0)).append(System.getProperty("line.separator"));
sb.append("Name: ").append(tmpList.get(0)).append(System.lineSeparator());
for(int i = 1; i < tmpList.size(); i++)
sb.append("Synon: ").append(tmpList.get(i)).append(System.getProperty("line.separator"));
sb.append("Synon: ").append(tmpList.get(i)).append(System.lineSeparator());

sb.append("DB#: ").append(record.ACCESSION()).append(System.getProperty("line.separator"));
sb.append("DB#: ").append(record.ACCESSION()).append(System.lineSeparator());
if(record.CH_LINK().containsKey("INCHIKEY"))
sb.append("InChIKey: ").append(record.CH_LINK().get("INCHIKEY")).append(System.getProperty("line.separator"));
sb.append("InChI: ").append(record.CH_IUPAC()).append(System.getProperty("line.separator"));
sb.append("SMILES: ").append(record.CH_SMILES()).append(System.getProperty("line.separator"));
sb.append("InChIKey: ").append(record.CH_LINK().get("INCHIKEY")).append(System.lineSeparator());
sb.append("InChI: ").append(record.CH_IUPAC()).append(System.lineSeparator());
sb.append("SMILES: ").append(record.CH_SMILES()).append(System.lineSeparator());

if(record.MS_FOCUSED_ION_asMap().containsKey("PRECURSOR_TYPE"))
sb.append("Precursor_type: ").append(record.MS_FOCUSED_ION_asMap().get("PRECURSOR_TYPE")).append(System.getProperty("line.separator"));
sb.append("Spectrum_type: ").append(record.AC_MASS_SPECTROMETRY_MS_TYPE()).append(System.getProperty("line.separator"));
sb.append("Precursor_type: ").append(record.MS_FOCUSED_ION_asMap().get("PRECURSOR_TYPE")).append(System.lineSeparator());
sb.append("Spectrum_type: ").append(record.AC_MASS_SPECTROMETRY_MS_TYPE()).append(System.lineSeparator());
if(record.MS_FOCUSED_ION_asMap().containsKey("PRECURSOR_M/Z"))
sb.append("PrecursorMZ: ").append(record.MS_FOCUSED_ION_asMap().get("PRECURSOR_M/Z")).append(System.getProperty("line.separator"));
sb.append("PrecursorMZ: ").append(record.MS_FOCUSED_ION_asMap().get("PRECURSOR_M/Z")).append(System.lineSeparator());

sb.append("Instrument_type: ").append(record.AC_INSTRUMENT_TYPE()).append(System.getProperty("line.separator"));
sb.append("Instrument: ").append(record.AC_INSTRUMENT()).append(System.getProperty("line.separator"));
sb.append("Ion_mode: ").append(record.AC_MASS_SPECTROMETRY_ION_MODE()).append(System.getProperty("line.separator"));
sb.append("Instrument_type: ").append(record.AC_INSTRUMENT_TYPE()).append(System.lineSeparator());
sb.append("Instrument: ").append(record.AC_INSTRUMENT()).append(System.lineSeparator());
sb.append("Ion_mode: ").append(record.AC_MASS_SPECTROMETRY_ION_MODE()).append(System.lineSeparator());

if(record.AC_MASS_SPECTROMETRY_asMap().containsKey("COLLISION_ENERGY"))
sb.append("Collision_energy: ").append(record.AC_MASS_SPECTROMETRY_asMap().get("COLLISION_ENERGY")).append(System.getProperty("line.separator"));
sb.append("Collision_energy: ").append(record.AC_MASS_SPECTROMETRY_asMap().get("COLLISION_ENERGY")).append(System.lineSeparator());

sb.append("Formula: ").append(record.CH_FORMULA()).append(System.getProperty("line.separator"));
sb.append("MW: ").append(Math.round(record.CH_EXACT_MASS().floatValue())).append(System.getProperty("line.separator"));
sb.append("ExactMass: ").append(record.CH_EXACT_MASS()).append(System.getProperty("line.separator"));
sb.append("Formula: ").append(record.CH_FORMULA()).append(System.lineSeparator());
sb.append("MW: ").append(Math.round(record.CH_EXACT_MASS().floatValue())).append(System.lineSeparator());
sb.append("ExactMass: ").append(record.CH_EXACT_MASS()).append(System.lineSeparator());

/*
https://chemdata.nist.gov/mass-spc/ftp/mass-spc/PepLib.pdf:
Expand All @@ -123,36 +123,35 @@ public static String convert(Record record) {
There is one mandatory field, namely Parent=<m/z>, which is the precursor ion m/z required for searching.
*/

sb.append("Comments: ").append("Parent=" + ((record.MS_FOCUSED_ION_asMap().containsKey("PRECURSOR_M/Z")) ? record.MS_FOCUSED_ION_asMap().get("PRECURSOR_M/Z") : -1)).append(System.getProperty("line.separator"));
sb.append("Comments: ").append("Parent=").append((record.MS_FOCUSED_ION_asMap().containsKey("PRECURSOR_M/Z")) ? record.MS_FOCUSED_ION_asMap().get("PRECURSOR_M/Z") : -1).append(System.lineSeparator());
//Comments: "accession=ET010001" "author=R. Gulde, E. Schymanski, K. Fenner, Department of Environmental Chemistry, Eawag" "license=CC BY" "copyright=Copyright (C) 2016 Eawag, Duebendorf, Switzerland" "publication=Gulde, Meier, Schymanski, Kohler, Helbling, Derrer, Rentsch & Fenner; ES&T 2016 50(6):2908-2920. DOI: 10.1021/acs.est.5b05186. Systematic Exploration of Biotransformation Reactions of Amine-containing Micropollutants in Activated Sludge" "comment=CONFIDENCE Parent Substance with Reference Standard (Level 1)" "comment=INTERNAL_ID 100" "exact mass=300.1393" "instrument=Q Exactive Orbitrap Thermo Scientific" "instrument type=LC-ESI-QFT" "ms level=MS2" "ionization=ESI" "fragmentation mode=HCD" "collision energy=15, 30, 45, 60, 70 or 90 (nominal)" "resolution=17500" "column=Atlantis T3 3um, 3x150mm, Waters with guard column" "flow gradient=95/5 at 0 min, 5/95 at 15 min, 5/95 at 20 min, 95/5 at 20.1 min, 95/5 at 25 min" "flow rate=300 uL/min" "retention time=14.6 min" "solvent a=water with 0.1% formic acid" "solvent b=methanol with 0.1% formic acid" "precursor m/z=301.1466" "precursor type=[M+H]+" "ionization mode=positive" "mass accuracy=0.007810149499385606" "mass error=-2.351999967231677E-6" "SMILES=CN1CCN(CC1)C(C1=CC=CC=C1)C1=CC=C(Cl)C=C1" "cas=82-93-9" "pubchem cid=2710" "chemspider=2609" "InChI=InChI=1S/C18H21ClN2/c1-20-11-13-21(14-12-20)18(15-5-3-2-4-6-15)16-7-9-17(19)10-8-16/h2-10,18H,11-14H2,1H3" "InChIKey=WFNAKBGANONZEQ-UHFFFAOYSA-N" "molecular formula=C18H21ClN2" "total exact mass=300.13932635199996" "SMILES=CN1CCN(CC1)C(C2=CC=CC=C2)C3=CC=C(C=C3)Cl"

sb.append("Splash: ").append(record.PK_SPLASH()).append(System.getProperty("line.separator"));
sb.append("Splash: ").append(record.PK_SPLASH()).append(System.lineSeparator());

// mz<1 needs to be prevented, check #157
StringBuilder peaklist = new StringBuilder();
int numPeaks = 0;
for(Triple<BigDecimal,BigDecimal,Integer> peak : record.PK_PEAK()) {
if (peak.getLeft().compareTo(new BigDecimal(1)) >= 0) {
numPeaks++;
peaklist.append(peak.getLeft() + " " + peak.getRight()).append(System.getProperty("line.separator"));
peaklist.append(peak.getLeft()).append(" ").append(peak.getRight()).append(System.lineSeparator());
}
}
sb.append("Num Peaks: ").append(numPeaks).append(System.getProperty("line.separator"));
sb.append("Num Peaks: ").append(numPeaks).append(System.lineSeparator());
sb.append(peaklist);

sb.append(System.getProperty("line.separator"));
sb.append(System.lineSeparator());
return sb.toString();
}

/**
* A wrapper to convert multiple Records and write to file.
* @param file to write
* @param records to convert
* @throws CDKException
*/
public static void recordsToNIST_MSP(File file, List<Record> records) {
*/
public static void recordsToNIST_MSP(File file, List<massbank.Record> records) {
// collect data
List<String> list = new ArrayList<String>();
List<String> list = new ArrayList<>();
for(Record record : records) {
list.add(convert(record));
list.add("");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
package massbank.export;

import massbank.Record;
import org.apache.commons.lang3.tuple.Triple;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
Expand All @@ -8,12 +13,6 @@
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import org.apache.commons.lang3.tuple.Pair;
import org.apache.commons.lang3.tuple.Triple;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.openscience.cdk.exception.CDKException;
import massbank.Record;

/*
RIKEN PRIME *.msp format II:
Expand Down Expand Up @@ -70,67 +69,66 @@ public class RecordToRIKEN_MSP {
* A plain converter Record to String with RIKEN PRIME msp.
* @param record to convert
*/
public static String convert(Record record) {
public static String convert(massbank.Record record) {
StringBuilder sb = new StringBuilder();

if (record.DEPRECATED()) {
logger.warn(record.ACCESSION() + " is deprecated. No export possible.");
logger.warn("{} is deprecated. No export possible.", record.ACCESSION());
return sb.toString();
}

sb.append("NAME : ").append(record.CH_NAME().get(0)).append(System.getProperty("line.separator"));
sb.append("NAME: ").append(record.CH_NAME().get(0)).append(System.lineSeparator());
Map<String, String> MS_FOCUSED_ION = record.MS_FOCUSED_ION_asMap();
sb.append("PRECURSORMZ: ").append((MS_FOCUSED_ION.containsKey("PRECURSOR_M/Z") ? MS_FOCUSED_ION.get("PRECURSOR_M/Z") : "")).append(System.getProperty("line.separator"));
sb.append("PRECURSORTYPE: ").append((MS_FOCUSED_ION.containsKey("PRECURSOR_TYPE") ? MS_FOCUSED_ION.get("PRECURSOR_TYPE") : "NA")).append(System.getProperty("line.separator"));
sb.append("FORMULA: ").append(record.CH_FORMULA()).append(System.getProperty("line.separator"));
sb.append("PRECURSORMZ: ").append((MS_FOCUSED_ION.getOrDefault("PRECURSOR_M/Z", ""))).append(System.lineSeparator());
sb.append("PRECURSORTYPE: ").append((MS_FOCUSED_ION.getOrDefault("PRECURSOR_TYPE", "NA"))).append(System.lineSeparator());
sb.append("FORMULA: ").append(record.CH_FORMULA()).append(System.lineSeparator());
if (record.CH_LINK().containsKey("ChemOnt")) {
sb.append("Ontology: ").append(record.CH_LINK().get("ChemOnt")).append(System.getProperty("line.separator"));
sb.append("Ontology: ").append(record.CH_LINK().get("ChemOnt")).append(System.lineSeparator());
}
sb.append("INCHIKEY: ").append(record.CH_LINK().containsKey("INCHIKEY") ? record.CH_LINK().get("INCHIKEY") : "N/A").append(System.getProperty("line.separator"));
sb.append("INCHI: ").append(record.CH_IUPAC()).append(System.getProperty("line.separator"));
sb.append("SMILES: ").append(record.CH_SMILES()).append(System.getProperty("line.separator"));
sb.append("RETENTIONTIME: ").append(record.AC_CHROMATOGRAPHY_asMap().containsKey("RETENTION_TIME") ? record.AC_CHROMATOGRAPHY_asMap().get("RETENTION_TIME") : "0").append(System.getProperty("line.separator"));
sb.append("INSTRUMENTTYPE: ").append(record.AC_INSTRUMENT_TYPE()).append(System.getProperty("line.separator"));
sb.append("INSTRUMENT: ").append(record.AC_INSTRUMENT()).append(System.getProperty("line.separator"));
sb.append("INCHIKEY: ").append(record.CH_LINK().getOrDefault("INCHIKEY", "N/A")).append(System.lineSeparator());
sb.append("INCHI: ").append(record.CH_IUPAC()).append(System.lineSeparator());
sb.append("SMILES: ").append(record.CH_SMILES()).append(System.lineSeparator());
sb.append("RETENTIONTIME: ").append(record.AC_CHROMATOGRAPHY_asMap().getOrDefault("RETENTION_TIME", "0")).append(System.lineSeparator());
sb.append("INSTRUMENTTYPE: ").append(record.AC_INSTRUMENT_TYPE()).append(System.lineSeparator());
sb.append("INSTRUMENT: ").append(record.AC_INSTRUMENT()).append(System.lineSeparator());
if (record.AC_MASS_SPECTROMETRY_ION_MODE().equals("NEGATIVE")) {
sb.append("IONMODE: Negative").append(System.getProperty("line.separator"));
sb.append("IONMODE: Negative").append(System.lineSeparator());
} else if (record.AC_MASS_SPECTROMETRY_ION_MODE().equals("POSITIVE")) {
sb.append("IONMODE: Positive").append(System.getProperty("line.separator"));
sb.append("IONMODE: Positive").append(System.lineSeparator());
}

List<String> links = new ArrayList<String>();
List<String> links = new ArrayList<>();

record.CH_LINK().forEach((key,value) -> {
if (!key.equals("ChemOnt")) links.add(key + ":" + value);
});
sb.append("LINKS: ").append(String.join("; ", links)).append(System.getProperty("line.separator"));
sb.append("LINKS: ").append(String.join("; ", links)).append(System.lineSeparator());

List<String> recordComment = record.COMMENT();
for (int i = 0; i < recordComment.size(); i++) {
if(recordComment.get(i).startsWith("CONFIDENCE")) recordComment.set(i,"Annotation " + recordComment.get(i).substring("CONFIDENCE".length()).trim());
}
recordComment.add(0, "DB#="+record.ACCESSION()+"; origin=MassBank");

sb.append("Comment: ").append(String.join("; ", recordComment)).append(System.getProperty("line.separator"));
sb.append("Splash: ").append(record.PK_SPLASH()).append(System.getProperty("line.separator"));
sb.append("Comment: ").append(String.join("; ", recordComment)).append(System.lineSeparator());
sb.append("Splash: ").append(record.PK_SPLASH()).append(System.lineSeparator());

sb.append("Num Peaks" + ": " + record.PK_NUM_PEAK()).append(System.getProperty("line.separator"));
sb.append("Num Peaks" + ": ").append(record.PK_NUM_PEAK()).append(System.lineSeparator());
for(Triple<BigDecimal,BigDecimal,Integer> peak : record.PK_PEAK())
sb.append(peak.getLeft().toPlainString() + "\t" + peak.getMiddle().toPlainString()).append(System.getProperty("line.separator"));
sb.append(peak.getLeft().toPlainString()).append("\t").append(peak.getMiddle().toPlainString()).append(System.lineSeparator());

sb.append(System.getProperty("line.separator"));
sb.append(System.lineSeparator());
return sb.toString();
}

/**
* A wrapper to convert multiple Records and write to file.
* @param file to write
* @param records to convert
* @throws CDKException
*/
public static void recordsToRIKEN_MSP(File file, List<Record> records) {
*/
public static void recordsToRIKEN_MSP(File file, List<massbank.Record> records) {
// collect data
List<String> list = new ArrayList<String>();
List<String> list = new ArrayList<>();
for(Record record : records) {
list.add(convert(record));
list.add("");
Expand Down

0 comments on commit 9dc4684

Please sign in to comment.