use of de.ipbhalle.metfraglib.peaklistreader.FilteredStringTandemMassPeakListReader in project MetFragRelaunched by ipb-halle.
the class OfflineMetFusionSpectralSimilarityScore method main.
public static void main(String[] args) throws Exception {
MetFragGlobalSettings settings = new MetFragGlobalSettings();
settings.set(VariableNames.PEAK_LIST_STRING_NAME, "65.0381 17.51663\n" + "108.0472 18.403548\n" + "125.0479 26.16408\n" + "156.0125 47.006652\n" + "173.0383 100");
settings.set(VariableNames.PRECURSOR_NEUTRAL_MASS_NAME, 172.0306);
FilteredStringTandemMassPeakListReader peaklistreader = new FilteredStringTandemMassPeakListReader(settings);
DefaultPeakList peaklist = peaklistreader.read();
settings.set(VariableNames.PEAK_LIST_NAME, peaklist);
PrecursorCandidate candidate = new PrecursorCandidate("InChI=1S/C6H8N2O2S/c7-5-1-3-6(4-2-5)11(8,9)10/h1-4H,7H2,(H2,8,9,10)", "Sulfanilamide");
settings.set(VariableNames.CANDIDATE_NAME, candidate);
OfflineMetFusionSpectralSimilarityScore score = new OfflineMetFusionSpectralSimilarityScore(settings);
score.calculate();
System.out.println(score.getValue());
}
use of de.ipbhalle.metfraglib.peaklistreader.FilteredStringTandemMassPeakListReader in project MetFragRelaunched by ipb-halle.
the class CompareSpectraD3JSBean method generateFragmentsForPeakList.
protected java.util.Vector<PeakFragmentImage> generateFragmentsForPeakList(String peaklist, String smiles, String subpath, String randomString) throws Exception {
String inchi = MoleculeFunctions.getInChIFromSmiles(smiles);
ICandidate precursorCandidate = new TopDownPrecursorCandidate(inchi, "1");
precursorCandidate.initialisePrecursorCandidate();
precursorCandidate.setProperty(VariableNames.MOLECULAR_FORMULA_NAME, inchi.split("/")[1]);
precursorCandidate.setProperty(VariableNames.SMILES_NAME, smiles);
precursorCandidate.initialisePrecursorCandidate();
MetFragGlobalSettings settings = new MetFragGlobalSettings();
double monoisotopicmass = precursorCandidate.getMolecularFormula().getMonoisotopicMass();
settings.set(VariableNames.PRECURSOR_NEUTRAL_MASS_NAME, monoisotopicmass);
settings.set(VariableNames.PEAK_LIST_STRING_NAME, peaklist);
settings.set(VariableNames.PEAK_LIST_NAME, new FilteredStringTandemMassPeakListReader(settings).read());
precursorCandidate.setUseSmiles(true);
settings.set(VariableNames.CANDIDATE_NAME, precursorCandidate);
settings.set(VariableNames.BOND_ENERGY_OBJECT_NAME, new BondEnergies());
settings.set(VariableNames.RELATIVE_MASS_DEVIATION_NAME, Double.parseDouble(this.relativeMassDeviation));
settings.set(VariableNames.ABSOLUTE_MASS_DEVIATION_NAME, Double.parseDouble(this.absoluteMassDeviation));
AbstractFragmenterAssignerScorer fas = (AbstractFragmenterAssignerScorer) Class.forName((String) settings.get(VariableNames.METFRAG_ASSIGNER_SCORER_NAME)).getConstructor(Settings.class, ICandidate.class).newInstance(settings, precursorCandidate);
fas.setCandidate(precursorCandidate);
fas.initialise();
fas.calculate();
fas.assignInterimScoresResults();
ICandidate scoredCandidate = fas.getCandidates()[0];
// generate fragments
java.io.File imageFolderFragments = new java.io.File(this.getRootSessionFolder() + Constants.OS_SPECIFIC_FILE_SEPARATOR + "comparespectra" + Constants.OS_SPECIFIC_FILE_SEPARATOR + "images" + Constants.OS_SPECIFIC_FILE_SEPARATOR + "fragments" + Constants.OS_SPECIFIC_FILE_SEPARATOR + subpath);
if (imageFolderFragments.exists())
FileUtils.deleteDirectory(imageFolderFragments);
imageFolderFragments.mkdirs();
String sessionId = this.getSessionId();
java.util.Vector<PeakFragmentImage> imagePathVector = new java.util.Vector<PeakFragmentImage>();
for (int i = 0; i < scoredCandidate.getMatchList().getNumberElements(); i++) {
HighlightSubStructureImageGenerator imageGenerator = new HighlightSubStructureImageGenerator();
int size = 300;
if (monoisotopicmass > 500)
size = 400;
if (monoisotopicmass > 700)
size = 500;
imageGenerator.setImageHeight(size);
imageGenerator.setImageWidth(size);
RenderedImage image;
java.io.File imageFile = new java.io.File(imageFolderFragments.getAbsolutePath() + Constants.OS_SPECIFIC_FILE_SEPARATOR + "fragment_" + i + ".png");
try {
image = imageGenerator.generateImage(scoredCandidate.getPrecursorMolecule(), scoredCandidate.getMatchList().getElement(i).getBestMatchedFragment());
ImageIO.write(image, "png", imageFile);
} catch (Exception e) {
System.err.println("error generating fragment image");
}
imagePathVector.add(new PeakFragmentImage(scoredCandidate.getMatchList().getElement(i).getMatchedPeak().getMass(), this.getURL() + "/files/" + sessionId + "/comparespectra/images/fragments/" + subpath + "/fragment_" + i + ".png?dummy=" + randomString, MathTools.round(((FragmentMassToPeakMatch) scoredCandidate.getMatchList().getElement(i)).getBestMatchFragmentMass())));
}
return imagePathVector;
}
Aggregations