|
| 1 | +/* |
| 2 | + * Copyright 2017 CNRS |
| 3 | + * Author: Alexandre BUREL |
| 4 | + * Email: alexandre.burel@unistra.Fr |
| 5 | + * |
| 6 | + * This software is a computer program whose purpose is to extract polymer |
| 7 | + * codes encoded into MS/MS spectra. The goal of this software is to |
| 8 | + * automate the decoding for several spectra, in a short amount of time |
| 9 | + * using a user-friendly user-interface. |
| 10 | + * |
| 11 | + * This software is governed by the CeCILL license under French law and |
| 12 | + * abiding by the rules of distribution of free software. You can use, |
| 13 | + * modify and/ or redistribute the software under the terms of the CeCILL |
| 14 | + * license as circulated by CEA, CNRS and INRIA at the following URL |
| 15 | + * "http://www.cecill.info". |
| 16 | + * |
| 17 | + * As a counterpart to the access to the source code and rights to copy, |
| 18 | + * modify and redistribute granted by the license, users are provided only |
| 19 | + * with a limited warranty and the software's author, the holder of the |
| 20 | + * economic rights, and the successive licensors have only limited |
| 21 | + * liability. |
| 22 | + * |
| 23 | + * In this respect, the user's attention is drawn to the risks associated |
| 24 | + * with loading, using, modifying and/or developing or reproducing the |
| 25 | + * software by the user in light of its specific status of free software, |
| 26 | + * that may mean that it is complicated to manipulate, and that also |
| 27 | + * therefore means that it is reserved for developers and experienced |
| 28 | + * professionals having in-depth computer knowledge. Users are therefore |
| 29 | + * encouraged to load and test the software's suitability as regards their |
| 30 | + * requirements in conditions enabling the security of their systems and/or |
| 31 | + * data to be ensured and, more generally, to use and operate it in the |
| 32 | + * same conditions as regards security. |
| 33 | + * |
| 34 | + * The fact that you are presently reading this means that you have had |
| 35 | + * knowledge of the CeCILL license and that you accept its terms. |
| 36 | + * |
| 37 | + */ |
| 38 | + |
| 39 | +package fr.lsmbo.msdecoder; |
| 40 | + |
| 41 | +import java.io.File; |
| 42 | +import java.util.ArrayList; |
| 43 | +import java.util.List; |
| 44 | + |
| 45 | +import com.beust.jcommander.JCommander; |
| 46 | +import com.beust.jcommander.Parameter; |
| 47 | + |
| 48 | +import fr.lsmbo.msdecoder.decoder.*; |
| 49 | +import fr.lsmbo.msdecoder.gui.DecoderGUI; |
| 50 | + |
| 51 | +public class Main { |
| 52 | + |
| 53 | + // TODO add algorithm-specific parameters |
| 54 | + public static class ArgumentList { |
| 55 | + @Parameter |
| 56 | + private List<String> parameters = new ArrayList<String>(); |
| 57 | + |
| 58 | + @Parameter(names = { "-input", "--input_spectrum_path" }, description = "Spectrum text file") |
| 59 | + private String spectrum = ""; |
| 60 | + |
| 61 | + @Parameter(names = { "-tol", "--mz_tolerance" }, description = "M/z tolerance") |
| 62 | + private Double mzTolerance = 0.05; |
| 63 | + |
| 64 | + @Parameter(names = { "-it", "--intensity_threshold" }, description = "Intensity minimal value") |
| 65 | + private Double intensityThreshold = 4.0; // default should be 4 |
| 66 | + |
| 67 | + @Parameter(names = { "-iti", "--intensity_threshold_for_isotope_search" }, description = "Intensity minimal value to search for the first isotope") |
| 68 | + private Double intensityThresholdForIsotopeSearch = 25.0; // default should be 25 |
| 69 | + |
| 70 | + @Parameter(names = { "-p", "--polymer_type" }, description = "Indicate which polymer should be searched") |
| 71 | + private String polymer = ""; |
| 72 | + |
| 73 | + @Parameter(names = { "-g", "--graphical_interface" }, description = "Use user-friendly GUI (default if CLI arguments are not provided)") |
| 74 | + private boolean gui = false; |
| 75 | + |
| 76 | + @Parameter(names = { "-h", "--help" }, description = "Display this help") |
| 77 | + private boolean help = false; |
| 78 | + |
| 79 | + @Parameter(names = { "-v", "--version" }, description = "Print version number") |
| 80 | + private boolean version = false; |
| 81 | + |
| 82 | +// @Parameter(names = { "-t", "--test" }, description = "Run some internal test [to be removed]") |
| 83 | +// private boolean test = false; |
| 84 | + } |
| 85 | + |
| 86 | + private static boolean checkSpectrumFile(String file) { |
| 87 | + try { |
| 88 | + File f = new File(file); |
| 89 | + if(f.exists() && f.isFile() && f.canRead()) { |
| 90 | + return true; |
| 91 | + } |
| 92 | + } catch(Exception e) { |
| 93 | + System.out.println("File '"+file+"' is not readable"); |
| 94 | + e.printStackTrace(); |
| 95 | + } |
| 96 | + return false; |
| 97 | + } |
| 98 | + |
| 99 | + private static boolean checkPolymerType(String polymer) { |
| 100 | + for(PolymerTypes p: PolymerTypes.values()) { |
| 101 | + if(p.name().equals(polymer)) { |
| 102 | + return true; |
| 103 | + } |
| 104 | + } |
| 105 | + return false; |
| 106 | + } |
| 107 | + |
| 108 | + public static void main(String[] args) { |
| 109 | + |
| 110 | + ArgumentList jc = new ArgumentList(); |
| 111 | + JCommander cmds = new JCommander(jc, args); |
| 112 | + cmds.setProgramName(AppInfo.getAppName()); |
| 113 | + |
| 114 | + if(jc.help) { |
| 115 | + // just print usage and quit |
| 116 | + cmds.usage(); |
| 117 | + } else if(jc.version) { |
| 118 | + // just print version number and quit |
| 119 | + System.out.println(AppInfo.getAppTitle()); |
| 120 | + } else if(jc.parameters.size() == 0 || jc.gui) { |
| 121 | + // open gui |
| 122 | + DecoderGUI.run(); |
| 123 | + } else { |
| 124 | + // if CLI, then spectrum and mode must be provided ! |
| 125 | + if(checkSpectrumFile(jc.spectrum) && checkPolymerType(jc.polymer)) { |
| 126 | + // prepare a string for the expected response |
| 127 | + String code = ""; |
| 128 | + |
| 129 | + // call the requested algorithm |
| 130 | + try { |
| 131 | + AbstractDecoder d = Decoders.get(PolymerTypes.valueOf(jc.polymer)); |
| 132 | + code = d.decode(jc.spectrum, jc.mzTolerance, jc.intensityThreshold, jc.intensityThresholdForIsotopeSearch).getCode(); |
| 133 | + } catch(Exception e) { |
| 134 | + e.printStackTrace(); |
| 135 | + } |
| 136 | + // print the response |
| 137 | + System.out.println(code); |
| 138 | + } else { |
| 139 | + System.err.println("Error: input spectrum file and polymer type must be provided !"); |
| 140 | + } |
| 141 | + } |
| 142 | + } |
| 143 | + |
| 144 | +} |
0 commit comments