├── .gitignore
├── LICENSE-2.0.txt
├── README.md
├── pom.xml
└── src
├── main
├── assembly
│ └── zip.xml
├── java
│ ├── QueueBuffer
│ │ ├── CompareSpectrum.java
│ │ ├── DequeNCompare.java
│ │ └── ReaderThread.java
│ ├── bookChapter
│ │ ├── CompareScoringFunctions.java
│ │ ├── GetSpecAnDID.java
│ │ ├── experimental
│ │ │ ├── AnalyzeExpScoring.java
│ │ │ ├── FindSimilarity.java
│ │ │ ├── IDResult.java
│ │ │ ├── Identifications.java
│ │ │ ├── Result.java
│ │ │ ├── SelectSpectraToCompare.java
│ │ │ └── Similarity.java
│ │ └── theoretical
│ │ │ ├── AnalyzeTheoreticalMSMSCalculation.java
│ │ │ ├── CalculateObservedMass.java
│ │ │ ├── DBEntry.java
│ │ │ ├── Identify.java
│ │ │ └── TheoreticalPeak.java
│ ├── cal
│ │ ├── binBased
│ │ │ ├── BinMSnSpectrum.java
│ │ │ ├── BinSpectrum.java
│ │ │ ├── Calculate_BinSpectrum_Similarity.java
│ │ │ ├── Calculate_BinSpectrum_Similarity_Interface.java
│ │ │ └── ConvertToBinMSnSpectrum.java
│ │ ├── cumulativeBinomialProbability
│ │ │ ├── Testing.java
│ │ │ ├── score
│ │ │ │ ├── Andromeda_derived.java
│ │ │ │ ├── CumulativeBinomialProbabilityBasedScoring.java
│ │ │ │ ├── MSAmanda_derived.java
│ │ │ │ ├── MSRobin.java
│ │ │ │ ├── ScoreName.java
│ │ │ │ └── Score_Interface.java
│ │ │ └── spectra
│ │ │ │ └── CompareAndScore.java
│ │ ├── methods
│ │ │ └── SimilarityMethods.java
│ │ └── multithread
│ │ │ ├── Calculate_Similarity.java
│ │ │ └── SimilarityResult.java
│ ├── config
│ │ ├── ConfigHolder.java
│ │ └── ResourceUtils.java
│ ├── gui
│ │ ├── LogTextAreaAppender.java
│ │ ├── MainController.java
│ │ ├── MainFrame.form
│ │ ├── MainFrame.java
│ │ ├── RunDialog.form
│ │ └── RunDialog.java
│ ├── gui_spectral_match_visualization
│ │ ├── MainGUI.form
│ │ ├── MainGUI.java
│ │ ├── SimilarityTableCellRenderer.java
│ │ ├── SimilarityTableModel.java
│ │ ├── StartDialog.form
│ │ └── StartDialog.java
│ ├── main
│ │ ├── ScorePipeline.java
│ │ └── ScorePipelineStarter.java
│ ├── preprocess
│ │ ├── filter
│ │ │ ├── main
│ │ │ │ └── RunNoiseFiltering.java
│ │ │ ├── noise
│ │ │ │ ├── implementation
│ │ │ │ │ ├── DiscardLowIntensePeaks.java
│ │ │ │ │ ├── DivideAndNormalize.java
│ │ │ │ │ ├── DivideAndTopNFilter.java
│ │ │ │ │ ├── Filter.java
│ │ │ │ │ ├── NoiseFilteringPrideAsap.java
│ │ │ │ │ └── TopNFiltering.java
│ │ │ │ └── interfaces
│ │ │ │ │ └── NoiseFilter.java
│ │ │ └── precursor
│ │ │ │ ├── RemovePrecursor.java
│ │ │ │ ├── RemovePrecursorRelatedPeaks.java
│ │ │ │ └── RemoveWindowAround.java
│ │ ├── sort
│ │ │ └── Sorting.java
│ │ └── transformation
│ │ │ ├── implementation
│ │ │ └── TransformIntensitiesImp.java
│ │ │ ├── interfaces
│ │ │ └── TransformIntensity.java
│ │ │ └── methods
│ │ │ └── Transformations.java
│ ├── protein_spectrum_diversity
│ │ ├── Analyse.java
│ │ ├── AnalyzeNISTSPecLib.java
│ │ ├── CLEntry.java
│ │ ├── KennethFileWalker.java
│ │ └── Parse.java
│ └── util
│ │ ├── CalculateMS1Err.java
│ │ └── MathsUtil.java
├── log4j.properties
└── resources
│ ├── BookChapter.properties
│ ├── MS2Similarity.properties
│ ├── ProteinDiversity.properties
│ └── log4j.properties
└── test
└── java
├── cal
├── binBased
│ ├── BinMSnSpectrumTest.java
│ └── ConvertToBinMSnSpectrumTest.java
└── cumulativeBinomialProbability
│ ├── score
│ ├── FilterTest.java
│ └── MSRobinTest.java
│ └── spectra
│ └── CompareAndScoreTest.java
└── spectra
└── preprocess
├── filter
├── implementation
│ ├── DiscardLowIntensePeaksTest.java
│ └── TopNFilteringTest.java
├── noise
│ └── implementation
│ │ └── DivideAndNormalizeTest.java
└── precursor
│ └── RemoveWindowAroundTest.java
└── precursor
└── PrecursorPeakRemovalTest.java
/.gitignore:
--------------------------------------------------------------------------------
1 | /lib/*
2 | /target/*
3 | nbactions-getData.xml
4 | nbactions-release-profile.xml
5 | nb-configuration.xml
6 | .gitignore~
7 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Project description
2 |
3 | The scoring functions to assess spectrum similarity play a crucial role in many computational mass spectrometry algorithms. These scoring functions can be used to compare an acquired MS/MS spectrum against two different types of target spectra: either against a theoretical MS/MS spectrum derived from a peptide from a sequence database, or against another, previously acquired acquired MS/MS spectrum. The former is typically encountered in database searching, while the latter is used in spectrum clustering, spectral library searching, or the detection of unique spectra between different data sets in comparative proteomics studies.
4 |
5 | The most commonly used scoring functions in experimental versus theoretical spectrum matching could be divided into two groups:
6 |
7 | - non-probabilistic (cross correlations which was used for [SEQUEST](http://fields.scripps.edu/sequest/))
8 | - probabilistic (cumulative binomial probability derived scoring functions in [Andromeda](http://141.61.102.17/maxquant_doku/doku.php?id=maxquant:andromeda) and [MS Amanda](http://ms.imp.ac.at/?goto=msamanda))
9 |
10 |
11 | Scoring functions for the comparison of two experimental spectra:
12 | - Normalized dot product (most commonly used in spectrum library search algorithms such as [SpectraST](http://tools.proteomecenter.org/wiki/index.php?title=Software:SpectraST), [BiblioSpec](https://skyline.gs.washington.edu/labkey/project/home/software/BiblioSpec/begin.view))
13 | - Pearson’s and Spearman's correlation coefficients
14 |
15 | # Avaliable scoring functions
16 | This project contains the enlisted scoring functions in [Project description](## Project description). The scoring functions in order to compare an acquired MS/MS spectrum against:
17 |
18 | - a theoretical spectrum via
19 | - SEQUEST-like scoring function (non-probabilistic)
20 | - Andromeda-like scoring function (probabilistic)
21 |
22 | - another acquired spectrum via
23 | - Dot product
24 | - Normalized dot product
25 | - Normalized dot product with introducting weights from peak intensities
26 | - Pearson's r
27 | - Spearman's rho
28 | - Mean Squared Error (MSE) (and also root MSE)
29 | - Median Squared Error (MdSE) (and also root MdSE)
30 | - Probabilistic scoring functon (including peak intensities)
31 |
32 | # Citation
33 |
34 | [Yılmaz et al: J Proteome Res., 2016, 15 (6), pp 1963–1970 (DOI:10.1021/acs.jproteome.6b00140)](http://pubs.acs.org/doi/abs/10.1021/acs.jproteome.6b00140)
35 |
36 | If you use our differential pipeline stand-alone tool or GUI version, please include the reference above.
37 |
38 |
39 | ----
40 |
41 | # Download
42 |
43 | ### Differential pipeline
44 |
45 | The probabilistic scoring function was succesfully applied on the differential pipeline in order to compare two experimental data sets in a differential analysis.
46 |
47 | A stand-alone program and the GUI version of this stand-alone program can be downloaded here.
48 |
49 |
50 | ### A pairwise spectrum view GUI
51 | A pairwise spectrum view GUI enables the manual inspection of how spectra actually look alike and can be downloaded here.
52 |
53 | ### Book chapter
54 |
55 | The scoring functions enlisted [Avaliable scoring functions] were used to evaluate their ability to assess spectrum similarity by evaluating them on one of the CPTAC data sets. This has been described in a book chapter.
56 |
57 | The program to compare spectra with the avaliable scoring functions, against either theoretical or experimental spectra can be downloaded [here](http://genesis.ugent.be/maven2/com/compomics/spectrum_similarity/0.1/spectrum_similarity-0.1.zip).
58 |
59 | The settings to perform spectrum comparison are in the bookChapter.properties file.
60 |
61 | ----
62 |
63 | # Usage
64 | See the [wiki](https://github.com/compomics/spectrum_similarity/wiki) for additional information on how to setup, run and configure spectrum comparison related projects.
65 |
66 |
--------------------------------------------------------------------------------
/src/main/assembly/zip.xml:
--------------------------------------------------------------------------------
1 |
4 | zip
5 |
6 | zip
7 |
8 |
9 |
10 | ${project.basedir}/target/${project.artifactId}-${project.version}
11 | /
12 |
13 |
14 |
--------------------------------------------------------------------------------
/src/main/java/QueueBuffer/CompareSpectrum.java:
--------------------------------------------------------------------------------
1 | /*
2 | * To change this license header, choose License Headers in Project Properties.
3 | * To change this template file, choose Tools | Templates
4 | * and open the template in the editor.
5 | */
6 | package QueueBuffer;
7 |
8 | import java.util.concurrent.ExecutorService;
9 | import java.util.concurrent.Executors;
10 |
11 | /**
12 | *
13 | * @author Genet
14 | */
15 | public class CompareSpectrum {
16 |
17 | /**
18 | * @param args the command line arguments
19 | */
20 | public static void main(String[] args) {
21 | // TODO code application logic here
22 | String filename1="C:/testfile/spectra3.txt";
23 | String filename2="C:/testfile/spectra2.txt";
24 |
25 |
26 | final ExecutorService executor = Executors.newFixedThreadPool(2);
27 |
28 | DequeNCompare writer = new DequeNCompare(filename1, filename2);
29 |
30 |
31 | executor.execute(writer);
32 | executor.shutdown();
33 | }
34 |
35 | }
36 |
--------------------------------------------------------------------------------
/src/main/java/QueueBuffer/DequeNCompare.java:
--------------------------------------------------------------------------------
1 | /*
2 | * To change this license header, choose License Headers in Project Properties.
3 | * To change this template file, choose Tools | Templates
4 | * and open the template in the editor.
5 | */
6 | package QueueBuffer;
7 |
8 | import java.io.File;
9 | import java.io.FileNotFoundException;
10 | import java.io.PrintWriter;
11 | import java.util.ArrayList;
12 | import java.util.Collections;
13 | import java.util.concurrent.ArrayBlockingQueue;
14 | import java.util.concurrent.ExecutorService;
15 | import java.util.concurrent.Executors;
16 | import java.util.logging.Level;
17 | import java.util.logging.Logger;
18 |
19 | /**
20 | *
21 | * @author Genet
22 | */
23 | public class DequeNCompare implements Runnable {
24 |
25 | String filename1 = "";
26 | String filename2 = "";
27 |
28 | public DequeNCompare(String f1, String f2) {
29 | this.filename1 = f1;
30 | this.filename2 = f2;
31 | }
32 |
33 | ArrayBlockingQueue queue1 = new ArrayBlockingQueue<>(8192);
34 | ArrayBlockingQueue queue2 = new ArrayBlockingQueue<>(8192);
35 | ArrayList spectrumList1 = new ArrayList();
36 | ArrayList spectrumList2 = new ArrayList();
37 | PrintWriter pr = null;
38 |
39 | public static boolean flag = true;
40 |
41 | @Override
42 | public void run() {
43 |
44 | try {
45 |
46 | String tempBuffer1;
47 | String tempBuffer2;
48 |
49 | ReaderThread reader1 = new ReaderThread(queue1, filename1);
50 | ReaderThread reader2 = new ReaderThread(queue2, filename2);
51 | pr = new PrintWriter(new File("C:/testfile/compResult.txt"));
52 |
53 | final ExecutorService executor = Executors.newFixedThreadPool(3);
54 | executor.execute(reader1);
55 | executor.execute(reader2);
56 |
57 | //Thread.currentThread().setPriority(Thread.MAX_PRIORITY);
58 | while (true) {
59 |
60 | while (!((tempBuffer1 = queue1.take()).equals("END IONS"))) {// && !((tempBuffer2 = queue1.take()).equals("EOF"))) {
61 |
62 | spectrumList1.add(tempBuffer1);
63 | }
64 |
65 | while (!(tempBuffer2 = queue2.take()).equals("EOF")) {
66 |
67 | if (tempBuffer2.equals("END IONS")) {
68 | calculateSimilarity(spectrumList1, spectrumList2, pr);
69 | spectrumList2.clear();
70 | } else {
71 | spectrumList2.add(tempBuffer2);
72 | }
73 |
74 | }
75 |
76 | if (queue1.peek().equals("EOF")) {
77 | pr.close();
78 |
79 | executor.shutdown();
80 | break;
81 | } else {
82 | reader2 = new ReaderThread(queue2, filename2);
83 | executor.execute(reader2);
84 |
85 | }
86 | spectrumList1.clear();
87 | spectrumList2.clear();
88 |
89 | }
90 |
91 | } catch (InterruptedException e) {
92 |
93 | } catch (FileNotFoundException ex) {
94 | Logger.getLogger(DequeNCompare.class.getName()).log(Level.SEVERE, null, ex);
95 | }
96 |
97 | }
98 |
99 | private void calculateSimilarity(ArrayList a, ArrayList b, PrintWriter pr) {
100 |
101 | boolean result = false;
102 |
103 | Collections.sort(a);
104 | Collections.sort(b);
105 | result = a.equals(b);
106 |
107 | pr.println("Size of first spectra = " + Integer.toString(a.size()) + "\n" + "Size of second spectra = " + Integer.toString(b.size()));
108 | pr.println("\n Similarity Result = " + Boolean.toString(result));
109 |
110 | }
111 |
112 | }
113 |
--------------------------------------------------------------------------------
/src/main/java/QueueBuffer/ReaderThread.java:
--------------------------------------------------------------------------------
1 | /*
2 | * To change this license header, choose License Headers in Project Properties.
3 | * To change this template file, choose Tools | Templates
4 | * and open the template in the editor.
5 | */
6 | package QueueBuffer;
7 |
8 | import java.io.BufferedReader;
9 | import java.io.File;
10 | import java.io.FileNotFoundException;
11 | import java.io.FileReader;
12 | import java.io.IOException;
13 | import java.util.concurrent.ArrayBlockingQueue;
14 |
15 | /**
16 | *
17 | * @author Genet
18 | */
19 | public class ReaderThread implements Runnable {
20 |
21 | protected ArrayBlockingQueue ringBuff = null;
22 | String filename;
23 |
24 | public ReaderThread(ArrayBlockingQueue blockingQueue, String filename) {
25 | this.ringBuff = blockingQueue;
26 | this.filename = filename;
27 | }
28 |
29 |
30 | @Override
31 | public void run() {
32 | BufferedReader br = null;
33 | try {
34 |
35 | br = new BufferedReader(new FileReader(new File(filename)));
36 |
37 | String currentLine = null;
38 | //Thread.currentThread().setPriority(Thread.MIN_PRIORITY);
39 |
40 | while ((currentLine = br.readLine()) != null) {
41 | if (Character.isDigit(currentLine.charAt(0)) || currentLine.equals("END IONS")) {
42 | //spectra=buffer1.split(" ");
43 | // if (ringBuff.size() > 8000) {
44 | // Thread.currentThread().wait(1);
45 | // }
46 |
47 | ringBuff.put(currentLine);
48 | }
49 |
50 | }
51 | ringBuff.put("EOF"); //When end of file has been reached
52 |
53 | } catch (FileNotFoundException e) {
54 |
55 | e.printStackTrace();
56 | } catch (IOException e) {
57 |
58 | e.printStackTrace();
59 | } catch (InterruptedException e) {
60 |
61 | } finally {
62 | try {
63 | br.close();
64 | // br2.close();
65 | } catch (IOException e) {
66 | e.printStackTrace();
67 | }
68 | }
69 |
70 | }
71 | }
72 |
--------------------------------------------------------------------------------
/src/main/java/bookChapter/CompareScoringFunctions.java:
--------------------------------------------------------------------------------
1 | /*
2 | * To change this license header, choose License Headers in Project Properties.
3 | * To change this template file, choose Tools | Templates
4 | * and open the template in the editor.
5 | */
6 | package bookChapter;
7 |
8 | import bookChapter.experimental.AnalyzeExpScoring;
9 | import bookChapter.theoretical.AnalyzeTheoreticalMSMSCalculation;
10 | import config.ConfigHolder;
11 | import java.io.FileNotFoundException;
12 | import java.io.IOException;
13 | import java.util.concurrent.ExecutionException;
14 | import java.util.logging.Logger;
15 | import uk.ac.ebi.jmzml.xml.io.MzMLUnmarshallerException;
16 |
17 | /**
18 | * This class enables scoring given spectra against either theoretical spectra
19 | * or acquired spectra.
20 | *
21 | * @author Sule
22 | */
23 | public class CompareScoringFunctions {
24 |
25 | /**
26 | * @param args the command line arguments
27 | * @throws java.io.IOException
28 | * @throws java.lang.ClassNotFoundException
29 | * @throws java.lang.InterruptedException
30 | * @throws uk.ac.ebi.jmzml.xml.io.MzMLUnmarshallerException
31 | * @throws java.io.FileNotFoundException
32 | * @throws java.util.concurrent.ExecutionException
33 | */
34 | public static void main(String[] args) throws IOException, ClassNotFoundException, InterruptedException, MzMLUnmarshallerException, FileNotFoundException, ExecutionException {
35 | Logger l = Logger.getLogger("CompareScoringFunctions");
36 | boolean doesCompareTheoreticals = ConfigHolder.getInstance().getBoolean("compareTheoreticals");
37 | if (doesCompareTheoreticals) {
38 | l.info("Comparison against theoretical specttra.");
39 | AnalyzeTheoreticalMSMSCalculation.main(args);
40 | } else {
41 | l.info("Comparison against acquired (aka experimental) specttra.");
42 | AnalyzeExpScoring.main(args);
43 | }
44 | }
45 |
46 | }
47 |
--------------------------------------------------------------------------------
/src/main/java/bookChapter/GetSpecAnDID.java:
--------------------------------------------------------------------------------
1 | /*
2 | * To change this license header, choose License Headers in Project Properties.
3 | * To change this template file, choose Tools | Templates
4 | * and open the template in the editor.
5 | */
6 | package bookChapter;
7 |
8 | import bookChapter.experimental.Identifications;
9 | import java.io.BufferedReader;
10 | import java.io.File;
11 | import java.io.FileNotFoundException;
12 | import java.io.FileReader;
13 | import java.io.IOException;
14 | import java.util.HashMap;
15 | import java.util.HashSet;
16 |
17 | /**
18 | *
19 | * @author Sule
20 | */
21 | public class GetSpecAnDID {
22 |
23 | public static HashMap getSpecAndIDs(File f, double pep, boolean isModified) throws FileNotFoundException, IOException {
24 | HashMap specAnDIDs = new HashMap();
25 | BufferedReader br = new BufferedReader(new FileReader(f));
26 | String line = "";
27 | while ((line = br.readLine()) != null) {
28 | if (!line.startsWith("modXpeptide") && !line.startsWith("sequence")) {
29 | String[] split = line.split("\t");
30 | if (split.length == 59) {
31 | String specTitle = split[2],
32 | rawPeptideIdentification = split[0],
33 | identification = split[57],
34 | scoreStr = split[54],
35 | tmpPEPstr = split[56],
36 | chargeStr = split[1],
37 | protein = split[58];
38 | double tmpPep = Double.parseDouble(tmpPEPstr),
39 | score = Double.parseDouble(scoreStr);
40 | int charge = Integer.parseInt(chargeStr);
41 | identification = identification.substring(identification.indexOf(".") + 1, identification.lastIndexOf("."));
42 | Identifications id = new Identifications(specTitle, identification, protein, score, tmpPep, charge, rawPeptideIdentification);
43 |
44 | if (tmpPep <= pep && id.isIsModified() == isModified) {
45 | if (specAnDIDs.containsKey(specTitle)) {
46 | if (id.getScore() > specAnDIDs.get(specTitle).getScore()) {
47 | specAnDIDs.remove(specTitle);
48 | specAnDIDs.put(specTitle, id);
49 | }
50 |
51 | } else {
52 | specAnDIDs.put(specTitle, id);
53 | }
54 | }
55 | }
56 | }
57 | }
58 | return specAnDIDs;
59 | }
60 |
61 | public static HashMap getSpecAndIDs(File f, double pep) throws FileNotFoundException, IOException {
62 | HashMap specAnDIDs = new HashMap();
63 | BufferedReader br = new BufferedReader(new FileReader(f));
64 | String line = "";
65 | while ((line = br.readLine()) != null) {
66 | if (!line.startsWith("modXpeptide") && !line.startsWith("sequence")) {
67 | String[] split = line.split("\t");
68 | if (split.length == 59) {
69 | String specTitle = split[2],
70 | rawPeptideIdentification = split[0],
71 | identification = split[57],
72 | scoreStr = split[54],
73 | tmpPEPstr = split[56],
74 | chargeStr = split[1],
75 | protein = split[58];
76 | double tmpPep = Double.parseDouble(tmpPEPstr),
77 | score = Double.parseDouble(scoreStr);
78 | int charge = Integer.parseInt(chargeStr);
79 | identification = identification.substring(identification.indexOf(".") + 1, identification.lastIndexOf("."));
80 | Identifications id = new Identifications(specTitle, identification, protein, score, tmpPep, charge, rawPeptideIdentification);
81 |
82 | if (tmpPep <= pep) {
83 | if (specAnDIDs.containsKey(specTitle)) {
84 | if (id.getScore() > specAnDIDs.get(specTitle).getScore()) {
85 | specAnDIDs.remove(specTitle);
86 | specAnDIDs.put(specTitle, id);
87 | }
88 |
89 | } else {
90 | specAnDIDs.put(specTitle, id);
91 | }
92 | }
93 | }
94 | }
95 | }
96 | return specAnDIDs;
97 | }
98 |
99 | /**
100 | * This method returns spectrum with identification, if spectra were
101 | * assigned to UPS proteins
102 | *
103 | * @param f
104 | * @param pep
105 | * @return
106 | * @throws FileNotFoundException
107 | * @throws IOException
108 | */
109 | public static HashMap getUPSSpecAndIDs(File f, double pep, boolean doesSelectUPS) throws FileNotFoundException, IOException {
110 | HashMap specAnDIDs = new HashMap();
111 | BufferedReader br = new BufferedReader(new FileReader(f));
112 | String line = "";
113 | while ((line = br.readLine()) != null) {
114 | if (!line.startsWith("modXpeptide") && !line.startsWith("sequence")) {
115 | String[] split = line.split("\t");
116 | if (split.length == 59) {
117 | String specTitle = split[2],
118 | rawPeptideIdentification = split[0],
119 | identification = split[57],
120 | scoreStr = split[54],
121 | tmpPEPstr = split[56],
122 | chargeStr = split[1],
123 | protein = split[58];
124 | double tmpPep = Double.parseDouble(tmpPEPstr),
125 | score = Double.parseDouble(scoreStr);
126 | int charge = Integer.parseInt(chargeStr);
127 | identification = identification.substring(identification.indexOf(".") + 1, identification.lastIndexOf("."));
128 | Identifications id = new Identifications(specTitle, identification,protein, score, tmpPep, charge, rawPeptideIdentification);
129 | // if protein has pep value of <= and assigned to UPS proteins
130 | if (tmpPep <= pep && protein.contains("ups") && doesSelectUPS) {
131 | if (specAnDIDs.containsKey(specTitle)) {
132 | if (id.getScore() > specAnDIDs.get(specTitle).getScore()) {
133 | specAnDIDs.remove(specTitle);
134 | specAnDIDs.put(specTitle, id);
135 | }
136 | } else {
137 | specAnDIDs.put(specTitle, id);
138 | }
139 | // if a validated-peptide was not derived from UPS proteins
140 | }
141 | if (tmpPep <= pep && !protein.contains("ups") && !protein.contains("SHUFFLED") && !doesSelectUPS) {
142 | if (specAnDIDs.containsKey(specTitle)) {
143 | if (id.getScore() > specAnDIDs.get(specTitle).getScore()) {
144 | specAnDIDs.remove(specTitle);
145 | specAnDIDs.put(specTitle, id);
146 | }
147 | } else {
148 | specAnDIDs.put(specTitle, id);
149 | }
150 | }
151 | }
152 | }
153 | }
154 | return specAnDIDs;
155 | }
156 |
157 | }
158 |
--------------------------------------------------------------------------------
/src/main/java/bookChapter/experimental/FindSimilarity.java:
--------------------------------------------------------------------------------
1 | /*
2 | * To change this license header, choose License Headers in Project Properties.
3 | * To change this template file, choose Tools | Templates
4 | * and open the template in the editor.
5 | */
6 | package bookChapter.experimental;
7 |
8 | import java.io.File;
9 | import java.io.IOException;
10 |
11 | /**
12 | *
13 | * @author Sule
14 | */
15 | public class FindSimilarity {
16 |
17 | /**
18 | * @param args the command line arguments
19 | */
20 | public static void main(String[] args) throws IOException {
21 |
22 | double pep = 0.5;
23 | // change the settings
24 | String settings1 = "BC_NFTR_NFTR_NF_None_TR_None_PPR_None_CHR_givenCharge_PRECTOL_3.0_binScores.txt",
25 | // Intensity transformation
26 | settings2 = "BC_NFTR_NFTR_NF_None_TR_Log2_PPR_None_CHR_givenCharge_PRECTOL_3.0_binScores.txt",
27 | settings3 = "BC_NFTR_NFTR_NF_None_TR_Sqrt_PPR_None_CHR_givenCharge_PRECTOL_3.0_binScores.txt",
28 | // Noise filtering
29 | settings4 = "BC_NFTR_NFTR_NF_Top50N_TR_None_PPR_None_CHR_givenCharge_PRECTOL_3.0_binScores.txt",
30 | settings5 = "BC_NFTR_NFTR_NF_Top100N_TR_None_PPR_None_CHR_givenCharge_PRECTOL_3.0_binScores.txt",
31 | settings6 = "BC_NFTR_NFTR_NF_Pride_TR_None_PPR_None_CHR_givenCharge_PRECTOL_3.0_binScores.txt",
32 | settings7 = "BC_NFTR_NFTR_NF_LowPrec_TR_None_PPR_None_CHR_givenCharge_PRECTOL_3.0_binScores.txt",
33 | // precursor peak removal
34 | settings8 = "BC_NFTR_NFTR_NF_None_TR_None_PPR_windowBased_CHR_givenCharge_PRECTOL_3.0_binScores.txt",
35 | settings9 = "BC_NFTR_NFTR_NF_None_TR_None_PPR_anyRelevantPeaks_CHR_givenCharge_PRECTOL_3.0_binScores.txt",
36 |
37 | // NF-TR or TR-NF with the best one
38 | settings10= "BC_NFTR_TRNF_NF_Pride_TR_Sqrt_PPR_None_CHR_givenCharge_PRECTOL_3.0_binScores.txt",
39 | settings11= "BC_NFTR_NFTR_NF_Pride_TR_Sqrt_PPR_None_CHR_givenCharge_PRECTOL_3.0_binScores.txt",
40 |
41 | setting = "";
42 | setting = settings11;
43 | String settingsFolder = "C:\\Users\\Sule\\Desktop\\BOOK_CHAPTER\\experimental",
44 | mascotIDFolder = "C:\\Users\\Sule\\Desktop\\BOOK_CHAPTER\\mascot_search/";
45 |
46 | // ups run output - ups-matched spectra on yeast-ups data set against ups-matched spectra
47 | // read and define same/different peptide
48 | // select only exact matched peptide peptide ID spectra with also new column of same peptide
49 | // write this same peptide ID spectra on the output
50 | // peptide Info: either same peptide or different peptide
51 | // protein Info: either same protein or different protein
52 | // return "nsp" number of same peptide
53 |
54 | // nonups output - non-ups matched spectra on yeast-ups data set
55 | // randomly select nsp number of non-ups matched spectra
56 | // peptide Info: either same peptide or different peptide
57 | // protein Info: either same protein or different protein
58 | // add these selected non-ups matched different peptide as
59 | // there are two files
60 | File upsResult = new File(settingsFolder + "/" + "ups_specs_" + setting), // input
61 | nonUPSResult = new File(settingsFolder + "/" + "non_ups_specs_" + setting), // input2
62 | output = new File(settingsFolder + "/toAnalyze/steps/" + "id_" + setting), // output
63 | yeast_ups_mascot = new File(mascotIDFolder + "/Orbi2_study6a_W080314_6E008_yeast_S48_ft8_pc_SvenSPyeast.dat.parsed.ms2pip.percolator_only.ms2pipscore"),
64 | ups_mascot = new File(mascotIDFolder + "/Orbi2_study6a_W080314_6QC1_sigma48_ft8_pc_SvenSPyeast.dat.parsed.ms2pip.percolator_only.ms2pipscore");
65 |
66 | Similarity s = new Similarity(upsResult, nonUPSResult, output, ups_mascot, yeast_ups_mascot);
67 | s.analyze();
68 |
69 | }
70 | }
71 |
--------------------------------------------------------------------------------
/src/main/java/bookChapter/experimental/IDResult.java:
--------------------------------------------------------------------------------
1 | /*
2 | * To change this license header, choose License Headers in Project Properties.
3 | * To change this template file, choose Tools | Templates
4 | * and open the template in the editor.
5 | */
6 |
7 | package bookChapter.experimental;
8 |
9 | import com.compomics.util.experiment.massspectrometry.MSnSpectrum;
10 |
11 | /**
12 | *
13 | * @author Sule
14 | */
15 | public class IDResult {
16 | private MSnSpectrum specA,
17 | specB;
18 | private String identification;
19 | private double score;
20 |
21 | public IDResult(MSnSpectrum specA, MSnSpectrum specB, String identification, double score) {
22 | this.specA = specA;
23 | this.specB = specB;
24 | this.identification = identification;
25 | this.score = score;
26 | }
27 |
28 | public MSnSpectrum getSpecA() {
29 | return specA;
30 | }
31 |
32 | public void setSpecA(MSnSpectrum specA) {
33 | this.specA = specA;
34 | }
35 |
36 | public MSnSpectrum getSpecB() {
37 | return specB;
38 | }
39 |
40 | public void setSpecB(MSnSpectrum specB) {
41 | this.specB = specB;
42 | }
43 |
44 | public String getIdentification() {
45 | return identification;
46 | }
47 |
48 | public void setIdentification(String identification) {
49 | this.identification = identification;
50 | }
51 |
52 | public double getScore() {
53 | return score;
54 | }
55 |
56 | public void setScore(double score) {
57 | this.score = score;
58 | }
59 |
60 | }
61 |
--------------------------------------------------------------------------------
/src/main/java/bookChapter/experimental/Identifications.java:
--------------------------------------------------------------------------------
1 | /*
2 | * To change this license header, choose License Headers in Project Properties.
3 | * To change this template file, choose Tools | Templates
4 | * and open the template in the editor.
5 | */
6 | package bookChapter.experimental;
7 |
8 | /**
9 | *
10 | * @author Sule
11 | */
12 | public class Identifications {
13 |
14 | private String specTitle,
15 | peptide,
16 | protein,
17 | rawPeptide;
18 | private double score,
19 | pep;
20 | private int charge;
21 | private boolean isModified = false;
22 |
23 | public Identifications(String specTitle, String peptide, String protein, double score, double pep, int charge, String rawPeptide) {
24 | this.specTitle = specTitle;
25 | this.rawPeptide=rawPeptide;
26 | this.peptide = peptide;
27 | this.protein = protein;
28 | this.score = score;
29 | this.pep = pep;
30 | this.charge = charge;
31 | // this part is specific to CPTAC data set
32 | if (rawPeptide.startsWith("ace")) {
33 | isModified = true;
34 | }
35 | if (rawPeptide.contains("moxM")) {
36 | isModified = true;
37 | }
38 | if (rawPeptide.contains("pyrQ")) {
39 | isModified = true;
40 | }
41 | if (rawPeptide.contains("cmmC")) {
42 | isModified = true;
43 | }
44 | }
45 |
46 | public String getProtein() {
47 | return protein;
48 | }
49 |
50 | public void setProtein(String protein) {
51 | this.protein = protein;
52 | }
53 |
54 |
55 | public boolean isIsModified() {
56 | return isModified;
57 | }
58 |
59 | public void setIsModified(boolean isModified) {
60 | this.isModified = isModified;
61 | }
62 |
63 | public int getCharge() {
64 | return charge;
65 | }
66 |
67 | public void setCharge(int charge) {
68 | this.charge = charge;
69 | }
70 |
71 | public String getSpecTitle() {
72 | return specTitle;
73 | }
74 |
75 | public void setSpecTitle(String specTitle) {
76 | this.specTitle = specTitle;
77 | }
78 |
79 | public String getPeptide() {
80 | return peptide;
81 | }
82 |
83 | public void setPeptide(String peptide) {
84 | this.peptide = peptide;
85 | }
86 |
87 | public double getScore() {
88 | return score;
89 | }
90 |
91 | public void setScore(double score) {
92 | this.score = score;
93 | }
94 |
95 | public double getPep() {
96 | return pep;
97 | }
98 |
99 | public void setPep(double pep) {
100 | this.pep = pep;
101 | }
102 |
103 | @Override
104 | public String toString() {
105 | return "Identifications{" + "specTitle=" + specTitle + ", peptide=" + peptide + ", rawPeptide=" + rawPeptide + ", score=" + score + ", pep=" + pep + ", charge=" + charge + ", isModified=" + isModified + '}';
106 | }
107 |
108 |
109 |
110 | }
111 |
--------------------------------------------------------------------------------
/src/main/java/bookChapter/experimental/SelectSpectraToCompare.java:
--------------------------------------------------------------------------------
1 | /*
2 | * To change this license header, choose License Headers in Project Properties.
3 | * To change this template file, choose Tools | Templates
4 | * and open the template in the editor.
5 | */
6 | package bookChapter.experimental;
7 |
8 | import static bookChapter.GetSpecAnDID.getUPSSpecAndIDs;
9 | import com.compomics.util.experiment.massspectrometry.MSnSpectrum;
10 | import com.compomics.util.experiment.massspectrometry.SpectrumFactory;
11 | import com.compomics.util.gui.waiting.waitinghandlers.WaitingHandlerCLIImpl;
12 | import java.io.BufferedWriter;
13 | import java.io.File;
14 | import java.io.FileWriter;
15 | import java.io.IOException;
16 | import java.util.HashMap;
17 | import uk.ac.ebi.jmzml.xml.io.MzMLUnmarshallerException;
18 |
19 | /**
20 | *
21 | * This class selects UPS-spectra based on their selected mascot scores. Then,
22 | * it stores them on a file containing these selected spectra
23 | *
24 | * @author Sule
25 | */
26 | public class SelectSpectraToCompare {
27 |
28 | /**
29 | * @param args the command line arguments
30 | */
31 | public static void main(String[] args) throws IOException, MzMLUnmarshallerException {
32 | File ups_mgf = new File("C:\\Users\\Sule\\Desktop\\BOOK_CHAPTER\\mgf/Orbi2_study6a_W080314_6QC1_sigma48_ft8_pc.mgf"),
33 | ups_yeast_mgf = new File("C:\\Users\\Sule\\Desktop\\BOOK_CHAPTER\\mgf/Orbi2_study6a_W080314_6E008_yeast_S48_ft8_pc.mgf"),
34 | ups_mascot = new File("C:\\Users\\Sule\\Desktop\\BOOK_CHAPTER\\mascot_search/Orbi2_study6a_W080314_6QC1_sigma48_ft8_pc_SvenSPyeast.dat.parsed.ms2pip.percolator_only.ms2pipscore"),
35 | ups_yeast_mascot = new File("C:\\Users\\Sule\\Desktop\\BOOK_CHAPTER\\mascot_search/Orbi2_study6a_W080314_6E008_yeast_S48_ft8_pc_SvenSPyeast.dat.parsed.ms2pip.percolator_only.ms2pipscore");
36 |
37 | File mgf_upsSpecs_at_upsSample = new File("C:\\Users\\Sule\\Desktop\\BOOK_CHAPTER\\mgf/exp/Orbi2_study6a_W080314_6QC1_sigma48_ft8_pc_UPS_3.mgf"),
38 | mgf_upsSpecs_at_upsyeastSample = new File("C:\\Users\\Sule\\Desktop\\BOOK_CHAPTER\\mgf/exp/Orbi2_study6a_W080314_6E008_yeast_S48_ft8_pc_UPS_3.mgf"),
39 | mgf_nonUPSSpecs_at_upsyeastSample = new File("C:\\Users\\Sule\\Desktop\\BOOK_CHAPTER\\mgf/exp/Orbi2_study6a_W080314_6E008_yeast_S48_ft8_pc_NONUPS_3.mgf");
40 | // select UPS identified spectra to be scored against...
41 | HashMap upsSpecs_at_upsSample = getUPSSpecAndIDs(ups_mascot, 0.05, true),
42 | upsSpecs_at_upsyeastSample = getUPSSpecAndIDs(ups_yeast_mascot, 0.05, true),
43 | nonUPSSpecs_at_upsyeastSample = getUPSSpecAndIDs(ups_yeast_mascot, 0.05, false);
44 |
45 | write(mgf_upsSpecs_at_upsSample,
46 | ups_mgf,
47 | upsSpecs_at_upsSample);
48 |
49 | write(mgf_upsSpecs_at_upsyeastSample,
50 | ups_yeast_mgf,
51 | upsSpecs_at_upsyeastSample);
52 |
53 | write(mgf_nonUPSSpecs_at_upsyeastSample,
54 | ups_yeast_mgf,
55 | nonUPSSpecs_at_upsyeastSample);
56 |
57 | // check min m/z and max m/z - would be necessary for binning
58 | double min_mz = Double.MAX_VALUE,
59 | max_mz = 0;
60 | double[] minmz_maxmz = getMinMaxMZ(mgf_upsSpecs_at_upsSample, min_mz, max_mz);
61 | minmz_maxmz = getMinMaxMZ(mgf_upsSpecs_at_upsyeastSample, minmz_maxmz[0], minmz_maxmz[1]);
62 | minmz_maxmz = getMinMaxMZ(mgf_nonUPSSpecs_at_upsyeastSample, minmz_maxmz[0], minmz_maxmz[1]);
63 | System.out.println("min m/z=" + minmz_maxmz[0]);
64 | System.out.println("max m/z=" + minmz_maxmz[1]);
65 |
66 | }
67 |
68 | private static double[] getMinMaxMZ(File ups_mgf, double min_mz, double max_mz) throws IOException, IllegalArgumentException, MzMLUnmarshallerException {
69 | double[] mzs = new double[2];
70 | SpectrumFactory fct = SpectrumFactory.getInstance();
71 | fct.addSpectra(ups_mgf, new WaitingHandlerCLIImpl());
72 | // load mgf file
73 | for (String mgfTitle : fct.getSpectrumTitles(ups_mgf.getName())) {
74 | MSnSpectrum m = (MSnSpectrum) fct.getSpectrum(ups_mgf.getName(), mgfTitle);
75 | if (m.getMinMz() < min_mz) {
76 | min_mz = m.getMinMz();
77 | }
78 | if (m.getMaxMz() > max_mz) {
79 | max_mz = m.getMaxMz();
80 | }
81 | }
82 | mzs[0] = min_mz;
83 | mzs[1] = max_mz;
84 | return mzs;
85 | }
86 |
87 | /**
88 | * Write selected mgfs on a given file
89 | *
90 | * @param mgf
91 | * @param ups_mgf
92 | * @param upsSpecs_at_upsSample
93 | * @throws IOException
94 | * @throws MzMLUnmarshallerException
95 | */
96 | private static void write(File mgf, File ups_mgf, HashMap upsSpecs_at_upsSample) throws IOException, MzMLUnmarshallerException {
97 | BufferedWriter bw = new BufferedWriter(new FileWriter(mgf));
98 | // read each spectrum on the given file
99 | SpectrumFactory fct = SpectrumFactory.getInstance();
100 | fct.addSpectra(ups_mgf, new WaitingHandlerCLIImpl());
101 | for (String title : upsSpecs_at_upsSample.keySet()) {
102 | // load mgf file
103 | for (String mgfTitle : fct.getSpectrumTitles(ups_mgf.getName())) {
104 | if (mgfTitle.equals(title)) {
105 | MSnSpectrum m = (MSnSpectrum) fct.getSpectrum(ups_mgf.getName(), mgfTitle);
106 | bw.write(m.asMgf());
107 | }
108 | }
109 | }
110 | bw.close();
111 | }
112 |
113 | }
114 |
--------------------------------------------------------------------------------
/src/main/java/bookChapter/theoretical/CalculateObservedMass.java:
--------------------------------------------------------------------------------
1 | /*
2 | * To change this license header, choose License Headers in Project Properties.
3 | * To change this template file, choose Tools | Templates
4 | * and open the template in the editor.
5 | */
6 |
7 | package bookChapter.theoretical;
8 |
9 | import com.compomics.util.experiment.biology.ions.ElementaryIon;
10 | import com.compomics.util.experiment.massspectrometry.MSnSpectrum;
11 |
12 | /**
13 | *
14 | * @author Sule
15 | */
16 | public class CalculateObservedMass {
17 |
18 | /**
19 | * To return (M+H)+ mass from given spectrum
20 | * It is assumed that given spectrum containing only one charge...
21 | * Based on this charge value, (M+H)+ is calculated
22 | *
23 | * @param ms
24 | * @return
25 | */
26 | public static double calculateMass(MSnSpectrum ms){
27 | double precursor_mz = ms.getPrecursor().getMz();
28 | int chargeValue = ms.getPrecursor().getPossibleCharges().get(0).value;
29 | double multipliedMZ = precursor_mz * chargeValue,
30 | theoProton = ElementaryIon.proton.getTheoreticMass(),
31 | multipliedProton = chargeValue * theoProton,
32 | mass = multipliedMZ - multipliedProton + theoProton;
33 |
34 | return mass;
35 | }
36 |
37 | }
38 |
--------------------------------------------------------------------------------
/src/main/java/bookChapter/theoretical/DBEntry.java:
--------------------------------------------------------------------------------
1 | /*
2 | * To change this license header, choose License Headers in Project Properties.
3 | * To change this template file, choose Tools | Templates
4 | * and open the template in the editor.
5 | */
6 |
7 | package bookChapter.theoretical;
8 |
9 | import com.compomics.util.experiment.biology.Peptide;
10 |
11 | /**
12 | * Entries from database
13 | *
14 | * @author Sule
15 | */
16 | public class DBEntry {
17 |
18 | private Peptide peptide;
19 | private String proteinDescription,
20 | proteinAccession;
21 | private double peptideMass;
22 |
23 | public DBEntry(Peptide peptide, String proteinDescription, String proteinAccession, double peptideMass) {
24 | this.peptide = peptide;
25 | this.proteinDescription = proteinDescription;
26 | this.proteinAccession = proteinAccession;
27 | this.peptideMass = peptideMass;
28 | }
29 |
30 | public Peptide getPeptide() {
31 | return peptide;
32 | }
33 |
34 | public void setPeptide(Peptide peptide) {
35 | this.peptide = peptide;
36 | }
37 |
38 | public String getProteinDescription() {
39 | return proteinDescription;
40 | }
41 |
42 | public void setProteinDescription(String proteinDescription) {
43 | this.proteinDescription = proteinDescription;
44 | }
45 |
46 | public String getProteinAccession() {
47 | return proteinAccession;
48 | }
49 |
50 | public void setProteinAccession(String proteinAccession) {
51 | this.proteinAccession = proteinAccession;
52 | }
53 |
54 | public double getPeptideMass() {
55 | return peptideMass;
56 | }
57 |
58 | public void setPeptideMass(double peptideMass) {
59 | this.peptideMass = peptideMass;
60 | }
61 |
62 | @Override
63 | public int hashCode() {
64 | int hash = 3;
65 | hash = 37 * hash + (this.peptide != null ? this.peptide.hashCode() : 0);
66 | hash = 37 * hash + (this.proteinDescription != null ? this.proteinDescription.hashCode() : 0);
67 | hash = 37 * hash + (this.proteinAccession != null ? this.proteinAccession.hashCode() : 0);
68 | hash = 37 * hash + (int) (Double.doubleToLongBits(this.peptideMass) ^ (Double.doubleToLongBits(this.peptideMass) >>> 32));
69 | return hash;
70 | }
71 |
72 | @Override
73 | public boolean equals(Object obj) {
74 | if (obj == null) {
75 | return false;
76 | }
77 | if (getClass() != obj.getClass()) {
78 | return false;
79 | }
80 | final DBEntry other = (DBEntry) obj;
81 | if (this.peptide != other.peptide && (this.peptide == null || !this.peptide.equals(other.peptide))) {
82 | return false;
83 | }
84 | if ((this.proteinDescription == null) ? (other.proteinDescription != null) : !this.proteinDescription.equals(other.proteinDescription)) {
85 | return false;
86 | }
87 | if ((this.proteinAccession == null) ? (other.proteinAccession != null) : !this.proteinAccession.equals(other.proteinAccession)) {
88 | return false;
89 | }
90 | if (Double.doubleToLongBits(this.peptideMass) != Double.doubleToLongBits(other.peptideMass)) {
91 | return false;
92 | }
93 | return true;
94 | }
95 |
96 |
97 |
98 | }
99 |
--------------------------------------------------------------------------------
/src/main/java/bookChapter/theoretical/TheoreticalPeak.java:
--------------------------------------------------------------------------------
1 | /*
2 | * To change this license header, choose License Headers in Project Properties.
3 | * To change this template file, choose Tools | Templates
4 | * and open the template in the editor.
5 | */
6 |
7 | package bookChapter.theoretical;
8 |
9 | import com.compomics.util.experiment.massspectrometry.Peak;
10 |
11 | /**
12 | *
13 | * @author Sule
14 | */
15 | public class TheoreticalPeak extends Peak {
16 | private int charge;
17 | private String name;
18 |
19 | public TheoreticalPeak(double mz, double intensity, int charge, String name) {
20 | super(mz, intensity);
21 | this.charge = charge;
22 | this.name = name;
23 | }
24 |
25 | public int getCharge() {
26 | return charge;
27 | }
28 |
29 | public void setCharge(int charge) {
30 | this.charge = charge;
31 | }
32 |
33 | public String getName() {
34 | return name;
35 | }
36 |
37 | public void setName(String name) {
38 | this.name = name;
39 | }
40 |
41 | @Override
42 | public int hashCode() {
43 | int hash = 3;
44 | hash = 89 * hash + (int) (Double.doubleToLongBits(this.mz) ^ (Double.doubleToLongBits(this.mz) >>> 32));
45 | hash = 89 * hash + (int) (Double.doubleToLongBits(this.intensity) ^ (Double.doubleToLongBits(this.intensity) >>> 32));
46 | hash = 89 * hash + this.charge;
47 | hash = 89 * hash + (this.name != null ? this.name.hashCode() : 0);
48 | return hash;
49 | }
50 |
51 | @Override
52 | public boolean equals(Object obj) {
53 | if (obj == null) {
54 | return false;
55 | }
56 | if (getClass() != obj.getClass()) {
57 | return false;
58 | }
59 | final TheoreticalPeak other = (TheoreticalPeak) obj;
60 | if (Double.doubleToLongBits(this.mz) != Double.doubleToLongBits(other.mz)) {
61 | return false;
62 | }
63 | if (Double.doubleToLongBits(this.intensity) != Double.doubleToLongBits(other.intensity)) {
64 | return false;
65 | }
66 | if (this.charge != other.charge) {
67 | return false;
68 | }
69 | if ((this.name == null) ? (other.name != null) : !this.name.equals(other.name)) {
70 | return false;
71 | }
72 | return true;
73 | }
74 |
75 |
76 |
77 |
78 | }
79 |
--------------------------------------------------------------------------------
/src/main/java/cal/binBased/BinSpectrum.java:
--------------------------------------------------------------------------------
1 | /*
2 | * To change this license header, choose License Headers in Project Properties.
3 | * To change this template file, choose Tools | Templates
4 | * and open the template in the editor.
5 | */
6 | package cal.binBased;
7 |
8 | /**
9 | *
10 | * @author Sule
11 | */
12 | public abstract class BinSpectrum {
13 | protected double min_value, // minimum mz value of the two spectra that are compared
14 | max_value, // maximum value of the two spectra that are compared
15 | fragment_tolerance; //to set size of a bin
16 | protected double[] bin_spectrum; //bin versioned spectrum with sum of all intensities
17 | protected boolean is_scaled_into_bins; // false shows that a spectrum is not binned yet, true shows that a binspectrum is generated.
18 |
19 |
20 | /* Getter and setter methods */
21 | public boolean isIs_scaled_into_bins() {
22 | return is_scaled_into_bins;
23 | }
24 |
25 | public void setIs_scaled_into_bins(boolean is_scaled_into_bins) {
26 | this.is_scaled_into_bins = is_scaled_into_bins;
27 | }
28 |
29 |
30 | /**
31 | * This method returns a min value used to start minimum bin creation
32 | * (double value of min m/z)
33 | *
34 | * @return
35 | */
36 | public double getMin_value() {
37 | return min_value;
38 | }
39 |
40 | /**
41 | * This method returns a max value used to start minimum bin creation
42 | * (double value of min m/z)
43 | *
44 | * @return
45 | */
46 | public double getMax_value() {
47 | return max_value;
48 | }
49 |
50 | /**
51 | * This method returns a fragment tolerance that is used to set a size of a
52 | * bin Note that a bin size is 2*fragment tolerance
53 | *
54 | * @return a fragment tolerance
55 | */
56 | public double getFragment_tolerance() {
57 | return fragment_tolerance;
58 | }
59 |
60 | /**
61 | * This method returns a bin spectrum
62 | *
63 | * @return a double array with weight of each unit is sum of intensities on
64 | * a given range
65 | */
66 | public double[] getBin_spectrum() {
67 | if (!is_scaled_into_bins) {
68 | construct_bin_spectrum();
69 | }
70 | return bin_spectrum;
71 | }
72 |
73 | /**
74 | * This methods converts an MSnSpectrum object into bin scaled version. The
75 | * range of bins starts from minimum value (minimum m/z value between
76 | * spectra that are going to be compared). Size of each bin equals to
77 | * 2*fragment_tolerance. Weight of each bin equals to sum of all intensities
78 | * between the range in selection (including peak on lowest border and
79 | * excluding peaks on highest border). Upper limit is max_value+0.00001 to
80 | * make sure that if the last peak is exactly on the border, intensity value
81 | * would be added. It fills double array with these intensity values and
82 | * then returns bin_scaled_spectrum.
83 | *
84 | */
85 | public abstract void construct_bin_spectrum();
86 |
87 | }
88 |
89 |
90 |
--------------------------------------------------------------------------------
/src/main/java/cal/binBased/Calculate_BinSpectrum_Similarity_Interface.java:
--------------------------------------------------------------------------------
1 | /*
2 | * To change this template, choose Tools | Templates
3 | * and open the template in the editor.
4 | */
5 | package cal.binBased;
6 |
7 | import cal.methods.SimilarityMethods;
8 |
9 | /**
10 | * This interface shows a method to calculate similarities between two
11 | * BinMSnSpectrum objects
12 | *
13 | * @author Sule
14 | */
15 | public interface Calculate_BinSpectrum_Similarity_Interface {
16 |
17 | /**
18 | * This method estimates similarity between two given BinMSnSpectrum objects
19 | * based on selected SimilarityMethod. If a method is dot product, the best
20 | * score equals to 100 or 1 and mean or median based score is selected, the
21 | * best score equals to 0. Before calculating similarity between spectra,
22 | * they must be scaled into bins (BinMSnSpectrum).
23 | *
24 | * @param specA a BinMSnSpectrum object that is analyzed
25 | * @param specB BinMSnSpectrum object that is analyzed
26 | * @param method is a Similarity Method
27 | *
28 | * @return the similarity score between the given two BinMSnSpectrum object. *
29 | */
30 | public double calculateSimilarity(BinMSnSpectrum specA, BinMSnSpectrum specB, SimilarityMethods method);
31 |
32 | }
33 |
--------------------------------------------------------------------------------
/src/main/java/cal/binBased/ConvertToBinMSnSpectrum.java:
--------------------------------------------------------------------------------
1 | /*
2 | * To change this license header, choose License Headers in Project Properties.
3 | * To change this template file, choose Tools | Templates
4 | * and open the template in the editor.
5 | */
6 | package cal.binBased;
7 |
8 | import com.compomics.util.experiment.massspectrometry.MSnSpectrum;
9 | import java.io.FileNotFoundException;
10 | import java.io.IOException;
11 | import preprocess.filter.noise.implementation.DiscardLowIntensePeaks;
12 | import preprocess.filter.noise.implementation.NoiseFilteringPrideAsap;
13 | import preprocess.filter.noise.implementation.TopNFiltering;
14 | import preprocess.transformation.implementation.TransformIntensitiesImp;
15 | import preprocess.transformation.methods.Transformations;
16 | import uk.ac.ebi.jmzml.xml.io.MzMLUnmarshallerException;
17 |
18 | /**
19 | * This class converts an MSnSpectrum object to BinMSnSpectrum object to
20 | * calculate similarities
21 | *
22 | * @author Sule
23 | */
24 | public class ConvertToBinMSnSpectrum {
25 |
26 | private double min_mz,// min mz to start binning
27 | max_mz,// max mz to end binnig
28 | fragment_tolerance; // to bin
29 | private int topN, // to apply noise filtering to select topN intense peaks
30 | percentage,// to apply noise filtering to remove peak with intensities less than percentage*maximum intensity
31 | noise_filtering_case,
32 | transformation_case,
33 | intensities_sum_or_mean_or_median;
34 |
35 | /**
36 | * Constructor
37 | *
38 | * @param min_mz minimum mz from all over data set to start binning
39 | * @param max_mz maximum mz from all over data set to end binnin
40 | * @param topN to apply noise filtering to select topN intense peaks
41 | * @param percentage to apply noise filtering to remove peak with
42 | * intensities less than percentage*maximum intensity
43 | * @param fragment_tolerance to bin spectra bin size = 2*fragment_tolerance
44 | * @param noise_filtering_case 0-nothing,1-PrideAsapNoiseFiltering
45 | * 2-TopNFiltering 3-DiscardLowIntensePeaks
46 | * @param transformation_case 0-nothing, 1-Log2, 2-Sqr root
47 | * @param intensities_sum_or_mean_or_median 0-sum, 1-mean, 2-median
48 | */
49 | public ConvertToBinMSnSpectrum(double min_mz, double max_mz, int topN, int percentage, double fragment_tolerance, int noise_filtering_case, int transformation_case, int intensities_sum_or_mean_or_median) {
50 | this.min_mz = min_mz;
51 | this.max_mz = max_mz;
52 | this.topN = topN;
53 | this.percentage = percentage;
54 | this.fragment_tolerance = fragment_tolerance;
55 | this.noise_filtering_case = noise_filtering_case;
56 | this.transformation_case = transformation_case;
57 | this.intensities_sum_or_mean_or_median = intensities_sum_or_mean_or_median;
58 | }
59 |
60 | /**
61 | * This method enables converting MSnSpectrum into BinMSnSpectrum to
62 | * calculate similarities
63 | *
64 | * @param ms an MSnSpectrum object
65 | * @param isNFTR true: first noise filtering then intensity transformation,
66 | * false; first intensity transformation then noise filtering
67 | *
68 | * @return
69 | * @throws IOException
70 | * @throws FileNotFoundException
71 | * @throws ClassNotFoundException
72 | * @throws MzMLUnmarshallerException
73 | */
74 | public BinMSnSpectrum convertToBinMSnSpectrum(MSnSpectrum ms, boolean isNFTR)
75 | throws IOException, FileNotFoundException, ClassNotFoundException, MzMLUnmarshallerException {
76 | BinMSnSpectrum bin_msms = null;
77 | // first run noise filtering
78 | if (isNFTR) {
79 | if (noise_filtering_case > 0) {
80 | apply_noise_filtering(ms);
81 | }
82 | // then transform intensities..
83 | if (transformation_case > 0) {
84 | transform_intensities(ms);
85 | }
86 | } else {
87 | // first transformation
88 | if (transformation_case > 0) {
89 | transform_intensities(ms);
90 | }
91 | // then noise filtering
92 | if (noise_filtering_case > 0) {
93 | apply_noise_filtering(ms);
94 | }
95 | }
96 | // create a BinMSnSpectrum from MSnSpectrum object
97 | bin_msms = new BinMSnSpectrum(ms, min_mz, max_mz, fragment_tolerance, intensities_sum_or_mean_or_median);
98 | return bin_msms;
99 | }
100 |
101 | /**
102 | * This class transforms intensities either Log2 or Square root 1-Log2
103 | * 2-Square root
104 | *
105 | * @param transformation_case
106 | * @param ms an MSnSpectrum object
107 | */
108 | private void transform_intensities(MSnSpectrum ms) {
109 | Transformations tr = null;
110 | TransformIntensitiesImp transform = null;
111 | switch (transformation_case) {
112 | case 1: // Log 2
113 | tr = Transformations.LOG_2;
114 | transform = new TransformIntensitiesImp(tr, ms);
115 | transform.transform(tr);
116 | ms.setPeakList(transform.getTr_peaks());
117 | break;
118 | case 2: // Square root
119 | tr = Transformations.SQR_ROOT;
120 | transform = new TransformIntensitiesImp(tr, ms);
121 | transform.transform(tr);
122 | ms.setPeakList(transform.getTr_peaks());
123 | break;
124 | }
125 | }
126 |
127 | /**
128 | * This class applies noise filtering 1 - PrideAsapNoiseFiltering 2 -
129 | * TopNFiltering 3 - DiscardLowIntensePeaks
130 | *
131 | * @param noise_filtering_case [0-3]
132 | * @param ms an MSnSpectrum object
133 | *
134 | */
135 | private void apply_noise_filtering(MSnSpectrum ms) {
136 | switch (noise_filtering_case) {
137 | case 1:
138 | NoiseFilteringPrideAsap noiseFilterImp = new NoiseFilteringPrideAsap();
139 | noiseFilterImp.noiseFilter(ms);
140 | break;
141 | case 2:
142 | TopNFiltering topNFiltering = new TopNFiltering(topN);
143 | topNFiltering.noiseFilter(ms);
144 | break;
145 | case 3:
146 | DiscardLowIntensePeaks discardLowIntensePeaks = new DiscardLowIntensePeaks(percentage);
147 | discardLowIntensePeaks.noiseFilter(ms);
148 | break;
149 | }
150 | }
151 |
152 | }
153 |
--------------------------------------------------------------------------------
/src/main/java/cal/cumulativeBinomialProbability/Testing.java:
--------------------------------------------------------------------------------
1 | /*
2 | * To change this license header, choose License Headers in Project Properties.
3 | * To change this template file, choose Tools | Templates
4 | * and open the template in the editor.
5 | */
6 | package cal.cumulativeBinomialProbability;
7 |
8 | import cal.cumulativeBinomialProbability.spectra.CompareAndScore;
9 | import com.compomics.util.experiment.massspectrometry.MSnSpectrum;
10 | import com.compomics.util.experiment.massspectrometry.SpectrumFactory;
11 | import java.io.File;
12 | import java.io.FileNotFoundException;
13 | import java.io.IOException;
14 | import java.util.ArrayList;
15 | import uk.ac.ebi.jmzml.xml.io.MzMLUnmarshallerException;
16 |
17 | /**
18 | *
19 | * @author Sule
20 | */
21 | public class Testing {
22 |
23 | /**
24 | * @param args the command line arguments
25 | */
26 | public static void main(String[] args) throws IOException, FileNotFoundException, MzMLUnmarshallerException, ClassNotFoundException, Exception {
27 |
28 | File first_mgf = new File("C:\\Users\\Sule\\Desktop\\sim/yeast_human_test.mgf"),
29 | second_mgf = new File("C:\\Users\\Sule\\Desktop\\sim/yeast_test.mgf");
30 | ArrayList first_spectra = new ArrayList(),
31 | second_spectra = new ArrayList();
32 | CompareAndScore match;
33 | int intensityOption = 0;
34 | SpectrumFactory fct = SpectrumFactory.getInstance();
35 |
36 | if (first_mgf.getName().endsWith(".mgf")) {
37 | fct.clearFactory();
38 | fct.addSpectra(first_mgf);
39 | for (String title : fct.getSpectrumTitles(first_mgf.getName())) {
40 | MSnSpectrum ms = (MSnSpectrum) fct.getSpectrum(first_mgf.getName(), title);
41 | first_spectra.add(ms);
42 | }
43 | }
44 |
45 | if (second_mgf.getName().endsWith(".mgf")) {
46 | fct.clearFactory();
47 | fct.addSpectra(second_mgf);
48 | for (String title : fct.getSpectrumTitles(second_mgf.getName())) {
49 | MSnSpectrum ms = (MSnSpectrum) fct.getSpectrum(second_mgf.getName(), title);
50 | second_spectra.add(ms);
51 | }
52 | }
53 |
54 | for (MSnSpectrum msms : first_spectra) {
55 | if (!msms.getPeakList().isEmpty()) {
56 | // Transformations tr = Transformations.LOG_2;;
57 | // TransformIntensitiesImp transform = new TransformIntensitiesImp(tr, msms);
58 | // transform.transform(tr);
59 | // msms.setPeakList(transform.getTr_peaks());
60 | for (MSnSpectrum msms_second : second_spectra) {
61 | if (!msms_second.getPeakList().isEmpty()) {
62 |
63 | // TransformIntensitiesImp transform2 = new TransformIntensitiesImp(tr, msms_second);
64 | // transform2.transform(tr);
65 | // msms_second.setPeakList(transform2.getTr_peaks());
66 | match = new CompareAndScore(msms, msms_second, 0.5, 0, intensityOption);
67 | double psMscore = match.getMSRobinScore();
68 | System.out.println("Option1" + "\t" + msms.getSpectrumTitle() + "\t" + msms_second.getSpectrumTitle() + "\t" + "similarity score=" + "\t" + psMscore);
69 |
70 | match = new CompareAndScore(msms, msms_second, 0.5, 1,intensityOption);
71 | psMscore = match.getMSRobinScore();
72 | System.out.println("Option2" + "\t" + msms.getSpectrumTitle() + "\t" + msms_second.getSpectrumTitle() + "\t" + "similarity score=" + "\t" + psMscore);
73 |
74 | System.out.println("**************");
75 | }
76 | }
77 | }
78 | }
79 |
80 | }
81 |
82 | }
83 |
--------------------------------------------------------------------------------
/src/main/java/cal/cumulativeBinomialProbability/score/Andromeda_derived.java:
--------------------------------------------------------------------------------
1 | /*
2 | * To change this license header, choose License Headers in Project Properties.
3 | * To change this template file, choose Tools | Templates
4 | * and open the template in the editor.
5 | */
6 | package cal.cumulativeBinomialProbability.score;
7 |
8 | import java.util.logging.Level;
9 | import java.util.logging.Logger;
10 |
11 | /**
12 | * This class calculates cumulative binominal probability based scores with
13 | * considering intensities from experimental spectra to
14 | * cumulativeBinomialProbability these.
15 | *
16 | * n: number of matched peaks
17 | *
18 | * N: number of theoretical peaks
19 | *
20 | * p: probability,topN/windowSize from a Filter object. Note that topN is [1-10]
21 | *
22 | * Note that cumulative binominal probability function calculates the score as
23 | * inclusive (not exclusive)
24 | *
25 | *
26 | * For each filtered peakList with a given topN parameter, p is calculated as
27 | * explained and cumulative binominal probability based scoring function part is
28 | * calculated as:
29 | *
30 | * Probability_Part (PP) = -10*[-log(P)]
31 | *
32 | *
33 | * @author Sule
34 | */
35 | public class Andromeda_derived extends CumulativeBinomialProbabilityBasedScoring {
36 |
37 | private double weight = -1; // making sure that weight is not used if it is not changed-found theoretical peaks weight for each peptide
38 |
39 | public Andromeda_derived(double p, int N, int n) {
40 | super.p = p; // probability=m/windowSize (windowSize=100Da default)m=[1- 10] peaks
41 | super.N = N; // N: All theoretical peaks at a theoretical spectrum (on Andromeda_derived)
42 | super.n = n; // n: Matched peaks is number of matched peaks on theoretical spectrum
43 | super.name = ScoreName.AndromedaD;
44 | }
45 |
46 | public Andromeda_derived(double p, int N, int n, double weight) {
47 | super.p = p; // probability=m/windowSize (windowSize=100Da default)m=[1- 10] peaks
48 | super.N = N; // N: All theoretical peaks at a theoretical spectrum (on Andromeda_derived)
49 | super.n = n; // n: Matched peaks is number of matched peaks on theoretical spectrum
50 | super.name = ScoreName.AndromedaD;
51 | this.weight = weight;
52 | }
53 |
54 | @Override
55 | protected void calculateScore() {
56 | try {
57 | double probability_based_score = super.calculateCumulativeBinominalProbability();
58 | if (probability_based_score != 0) {
59 | score = - 10 * (Math.log10(probability_based_score));
60 | }
61 | if (weight != -1 && weight != 0) {
62 | score = score + Math.abs(score * Math.log10(1 / (double) weight));
63 | }
64 | // to eliminate obtaining -0 values..
65 | score += 0.0;
66 | isCalculated = true;
67 | } catch (Exception ex) {
68 | Logger.getLogger(Andromeda_derived.class.getName()).log(Level.SEVERE, null, ex);
69 | }
70 | }
71 |
72 | }
73 |
--------------------------------------------------------------------------------
/src/main/java/cal/cumulativeBinomialProbability/score/CumulativeBinomialProbabilityBasedScoring.java:
--------------------------------------------------------------------------------
1 | /*
2 | * To change this license header, choose License Headers in Project Properties.
3 | * To change this template file, choose Tools | Templates
4 | * and open the template in the editor.
5 | */
6 | package cal.cumulativeBinomialProbability.score;
7 |
8 | import org.apache.commons.math.distribution.BinomialDistribution;
9 | import org.apache.commons.math.distribution.BinomialDistributionImpl;
10 |
11 | /**
12 | * This abstract class is used to write cumulative binominal probability based
13 | * scoring function
14 | *
15 | * @author Sule
16 | */
17 | public abstract class CumulativeBinomialProbabilityBasedScoring {
18 |
19 | protected double p; // probability of success on a single trial
20 | protected int N, // number of trials
21 | n;// number of successes
22 | protected double score = 0.0; // cumulative bionominal probability based score for given N,n,p.
23 | protected boolean isCalculated = false; // To make sure that a score is not calculated over and over while calling getter method
24 | protected ScoreName name;
25 |
26 | /**
27 | * To calculate cumulative binominal probability score
28 | *
29 | */
30 | protected abstract void calculateScore();
31 |
32 | /**
33 | * It returns a cumulativeBinomialProbability. It checks if a it is already
34 | * calculated; if not it calculates
35 | *
36 | * @return
37 | */
38 | public double getScore() {
39 | if (!isCalculated) {
40 | calculateScore();
41 | }
42 | return score;
43 | }
44 |
45 | /**
46 | * To calculate CumulativeBinominalProbability with given n,N and p values.
47 | * by calling BinomialDistribution class on Apache
48 | *
49 | * @return
50 | * @throws Exception
51 | */
52 | protected double calculateCumulativeBinominalProbability() throws Exception {
53 | BinomialDistribution b = new BinomialDistributionImpl(N, p);
54 | int tmp = n - 1;
55 | double probability = 1 - b.cumulativeProbability(tmp);
56 | return probability;
57 | }
58 |
59 | }
60 |
--------------------------------------------------------------------------------
/src/main/java/cal/cumulativeBinomialProbability/score/MSAmanda_derived.java:
--------------------------------------------------------------------------------
1 | /*
2 | * To change this license header, choose License Headers in Project Properties.
3 | * To change this template file, choose Tools | Templates
4 | * and open the template in the editor.
5 | */
6 | package cal.cumulativeBinomialProbability.score;
7 |
8 | import java.util.logging.Level;
9 | import java.util.logging.Logger;
10 |
11 | /**
12 | * This class calculates cumulative binominal probability based scores with
13 | * considering intensities from experimental spectra to
14 | * cumulativeBinomialProbability these.
15 | *
16 | * n: number of matched peaks
17 | *
18 | * N: number of (picked) peaks of a filtered spectrum with topN
19 | *
20 | * p: probability,topN/windowSize from a Filter object. Note that topN is [1-10]
21 | *
22 | * Note that cumulative binominal probability function calculates the score as
23 | * inclusive (not exclusive)
24 | *
25 | * Intensity_part(IP): (Explained_IntensitiesA/All_IntensitiesA)
26 | *
27 | * For each filtered peakList with a given topN parameter, p is calculated as
28 | * explained and cumulative binominal probability based scoring function part is
29 | * calculated as:
30 | *
31 | * Probability_Part (PP) = -10*[-log(P)]
32 | *
33 | * Later on, intensity part is introduced as with two options:
34 | *
35 | * (option0) Final_score = PP*Sqrt(IP)
36 | *
37 | * (option1) Final_score = PP*IP *
38 | *
39 | * @author Sule
40 | */
41 | public class MSAmanda_derived extends CumulativeBinomialProbabilityBasedScoring {
42 |
43 | private double intensity, // sum of all intensities from every picked peak
44 | explainedIntensity, // sum of all intensities from matched picked peak
45 | weight = -1;
46 | private int intensityOption; // 0:SQRT(IP), 1:IP
47 |
48 | /**
49 | *
50 | * @param p probability=topN/windowSize, topN=[1- 10] peaks
51 | * @param N Picked (filtered) peaks on an experimental spectrum (on MSAmanda
52 | * derived but this equals to all peaks at a theoretical spectrum on
53 | * Andromeda derived)
54 | * @param n Matched peaks-is number of matched peaks against a theoretical
55 | * spectrum
56 | * @param intensity sum of all intensities from every picked peak
57 | * @param explainedIntensity sum of all intensities from matched picked peak
58 | * @param intesityOption 0-Intensities are squared, 1-No preprocessing on
59 | * intensity part
60 | * @param ScoreName name of scoring function
61 | *
62 | */
63 | public MSAmanda_derived(double p, int N, int n, double intensity, double explainedIntensity, int intesityOption, ScoreName name) {
64 | super.p = p;
65 | super.N = N;
66 | super.n = n;
67 | this.intensity = intensity;
68 | this.explainedIntensity = explainedIntensity;
69 | this.intensityOption = intesityOption;
70 | this.name = name;
71 | }
72 |
73 | public MSAmanda_derived(double p, int N, int n, double intensity, double explainedIntensity, int intesityOption, ScoreName name, double weight) {
74 | super.p = p;
75 | super.N = N;
76 | super.n = n;
77 | this.intensity = intensity;
78 | this.explainedIntensity = explainedIntensity;
79 | this.intensityOption = intesityOption;
80 | this.name = name;
81 | this.weight = weight;
82 | }
83 |
84 | /**
85 | * This calculate MSAmanda_derived cumulativeBinomialProbability with an
86 | * option in selection. Option0-Sqrt(IntensityPart) Option1-IntensityPart
87 | */
88 | @Override
89 | protected void calculateScore() {
90 | try {
91 | double tmp = 0;
92 | double probability_based_score = super.calculateCumulativeBinominalProbability(),
93 | intensity_part = (double) explainedIntensity / (double) intensity;
94 | if (intensityOption == 0 && probability_based_score != 0) {
95 | tmp = -10 * (Math.log10(probability_based_score));
96 | intensity_part = (Math.sqrt(intensity_part));
97 | score = tmp * intensity_part;
98 | } else if (intensityOption == 1 && probability_based_score != 0) {
99 | tmp = - 10 * (Math.log10(probability_based_score));
100 | score = tmp * intensity_part;
101 | } else if (intensityOption == 2 && probability_based_score != 0) {
102 | score = -10 * (Math.log10(probability_based_score / intensity_part));
103 | }
104 | if (weight != -1 && weight != 0) {
105 | score = score + (score * Math.log(1 / (double) weight));
106 | }
107 | // to eliminate obtaining -0 values..
108 | score += 0.0;
109 | isCalculated = true;
110 | } catch (Exception ex) {
111 | Logger.getLogger(MSAmanda_derived.class.getName()).log(Level.SEVERE, null, ex);
112 | }
113 | }
114 |
115 | }
116 |
--------------------------------------------------------------------------------
/src/main/java/cal/cumulativeBinomialProbability/score/MSRobin.java:
--------------------------------------------------------------------------------
1 | /*
2 | * To change this license header, choose License Headers in Project Properties.
3 | * To change this template file, choose Tools | Templates
4 | * and open the template in the editor.
5 | */
6 | package cal.cumulativeBinomialProbability.score;
7 |
8 | import util.MathsUtil;
9 | import java.util.logging.Level;
10 | import java.util.logging.Logger;
11 |
12 | /**
13 | * This class calculates cumulative binominal probability based scores with
14 | * considering intensities from experimental spectra to
15 | * cumulativeBinomialProbability these.
16 | *
17 | * n: number of matched peaks
18 | *
19 | * N: number of peaks of a spectrum with a bigger peak list
20 | *
21 | * p: probability,topN/windowSize from a Filter object. Note that topN is [1-10]
22 | *
23 | * Note that cumulative binominal probability function calculates the score as
24 | * inclusive (not exclusive)
25 | *
26 | * Intensity_part(IP): [(0.5*(Explained_Intensities A/All_Intensities
27 | * A))+(0.5*(Explained_Intensities B/All_intensitiesB))]
28 | *
29 | * For each filtered peakList with a given topN parameter, p is calculated as
30 | * explained and cumulative binominal probability based scoring function part is
31 | * calculated as:
32 | *
33 | * Probability_Part (PP) = -10*[-log(P)]
34 | *
35 | * Later on, intensity part is introduced as with two options:
36 | *
37 | * (option0) Final_score = PP*Sqrt(IP)
38 | *
39 | * (option1) Final_score = PP*IP *
40 | *
41 | * @author Sule
42 | */
43 | public class MSRobin extends CumulativeBinomialProbabilityBasedScoring implements Score_Interface {
44 |
45 | private double intensity_part;
46 | private double option; // 0: Sqrt(IP) 1: IP and some others
47 |
48 | /**
49 | * To construct an object to calculate MSRobin cumulativeBinomialProbability
50 | *
51 | * @param p probability,topN/windowSize from a Filter object. Note that topN
52 | * is [1-10]
53 | *
54 | * @param N number of peaks of a spectrum with a bigger peak list
55 | * @param n number of matched peaks between two experimental spectra
56 | * @param intensity_part a pre-calculated value while picking peaks
57 | * @param option 0-Intensities are squared, 1-No preprocessing on intensity
58 | * part
59 | *
60 | */
61 | public MSRobin(double p, int N, int n, double intensity_part, int option) {
62 | super.p = p;
63 | super.N = N;
64 | super.n = n;
65 | this.option = option;
66 | this.intensity_part = intensity_part;
67 | }
68 |
69 | /**
70 | * To calculate CumulativeBinominalProbability with given n,N and p values.
71 | * n is inclusive during cumulative binominal probability function
72 | *
73 | * @return
74 | * @throws Exception
75 | */
76 | @Override
77 | public double calculateCumulativeBinominalProbability() throws Exception {
78 | double probability = 0;
79 | for (int k = n; k < N + 1; k++) {
80 | double factorial_part = MathsUtil.calculateCombination(N, k);
81 | double tmp_probability = factorial_part * (Math.pow(p, k)) * (Math.pow((1 - p), (N - k)));
82 | probability += tmp_probability;
83 | }
84 | return probability;
85 | }
86 |
87 | /**
88 | * This calculate MSRobin cumulativeBinomialProbability with an option in
89 | * selection
90 | */
91 | @Override
92 | public void calculateScore() {
93 |
94 | try {
95 | double probability_part = calculateCumulativeBinominalProbability();
96 | if (option == 0) {
97 | probability_part = -10 * (Math.log10(probability_part));
98 | intensity_part = (Math.sqrt(intensity_part));
99 | score = probability_part * intensity_part;
100 | } else if (option == 1) {
101 | probability_part = -10 * (Math.log10(probability_part));
102 | score = probability_part * intensity_part;
103 | } else if (option == 2) {
104 | probability_part = -(Math.log10(probability_part));
105 | score = probability_part * intensity_part;
106 | } else if (option == 3) {
107 | // only probability
108 | score = -10 * (Math.log10(probability_part));
109 | } else if (option == 4) {
110 | // only probability
111 | score = (1 - probability_part) * intensity_part;
112 | }
113 | score += 0; // just making sure the value would not be negative zero
114 | isCalculated = true;
115 | } catch (Exception ex) {
116 | Logger.getLogger(MSRobin.class.getName()).log(Level.SEVERE, null, ex);
117 | }
118 | }
119 |
120 | public double getIntensity_part() {
121 | return intensity_part;
122 | }
123 |
124 | public void setIntensity_part(double intensity_part) {
125 | this.intensity_part = intensity_part;
126 | }
127 |
128 | public double getProbability_part() throws Exception {
129 | double probability_part = calculateCumulativeBinominalProbability();
130 | return probability_part;
131 | }
132 |
133 | }
134 |
--------------------------------------------------------------------------------
/src/main/java/cal/cumulativeBinomialProbability/score/ScoreName.java:
--------------------------------------------------------------------------------
1 | /*
2 | * To change this license header, choose License Headers in Project Properties.
3 | * To change this template file, choose Tools | Templates
4 | * and open the template in the editor.
5 | */
6 |
7 | package cal.cumulativeBinomialProbability.score;
8 |
9 | /**
10 | * Scoring function names
11 | * @author Sule
12 | */
13 | public enum ScoreName {
14 | AndromedaD, // Andromeda derive - cumulative binomial probability derived function/only number of peak/N=theoretical peaks
15 | MSAmandaD, // MSAmanda derive - cumulative binomial probability derived function/number of peak and explained intensities/N=matched experimental peaks
16 | TheoMSAmandaD, // (Theoretical)MSAmanda derive - cumulative binomial probability derived function/number of peak and explained intensities/N=theoretical experimental peaks
17 | AndromedaDWeighted,
18 | TheoMSAmandaDWeighted
19 | }
20 |
--------------------------------------------------------------------------------
/src/main/java/cal/cumulativeBinomialProbability/score/Score_Interface.java:
--------------------------------------------------------------------------------
1 | /*
2 | * To change this license header, choose License Headers in Project Properties.
3 | * To change this template file, choose Tools | Templates
4 | * and open the template in the editor.
5 | */
6 | package cal.cumulativeBinomialProbability.score;
7 |
8 | /**
9 | *
10 | * @author Sule
11 | */
12 | public interface Score_Interface {
13 |
14 |
15 | /**
16 | * To calculate a score
17 | *
18 | */
19 | public abstract void calculateScore();
20 |
21 | }
22 |
--------------------------------------------------------------------------------
/src/main/java/cal/methods/SimilarityMethods.java:
--------------------------------------------------------------------------------
1 | /*
2 | * To change this template, choose Tools | Templates
3 | * and open the template in the editor.
4 | */
5 | package cal.methods;
6 |
7 | /**
8 | *
9 | * @author Sule
10 | */
11 | public enum SimilarityMethods {
12 |
13 | DOT_PRODUCT, // dot product score without any weights on m/z values.
14 | NORMALIZED_DOT_PRODUCT_STANDARD, // normalized-dot product score without any weights on m/z values.
15 | NORMALIZED_DOT_PRODUCT_HORAI, // weighted normalized-dot product score, weight of peak intensity=0.5 and weight of peak mz =2
16 | NORMALIZED_DOT_PRODUCT_ZHANG, // weighted normalized-dot product score, weight of peak intensity=0.53 and weight of peak mz=1.3
17 | NORMALIZED_DOT_PRODUCT_SOKOLOW, // weighted normalized-dot product score, weight of peak intensity=0.5 and weight of peak mz =1
18 | NORMALIZED_DOT_PRODUCT_USER_DEFINED, // weighted normalized-dot product score, weight of peak intensity=x and peak mz=y are determined by user
19 |
20 | // TO DO: Check these Squared error formulas!
21 | MEAN_SQUARED_ERROR, // [Mean (Sum((intensityPeak1 - intensityPeak2)^2)) ] Math.abs(mz(Peak1)- mz(Peak2)) scores = new EnumMap(SimilarityMethods.class);
27 |
28 | public SimilarityResult(String spectrumName, MSnSpectrum bestSimilarSpec, String spectrumChargeAsString, double spectrumPrecursorMZ) {
29 | this.spectrumName = spectrumName;
30 | this.bestSimilarSpec = bestSimilarSpec;
31 | this.spectrumChargeAsString = spectrumChargeAsString;
32 | this.spectrumPrecursorMZ = spectrumPrecursorMZ;
33 | scores.put(SimilarityMethods.DOT_PRODUCT, Double.MIN_VALUE);
34 | scores.put(SimilarityMethods.NORMALIZED_DOT_PRODUCT_STANDARD, Double.MIN_VALUE);
35 | scores.put(SimilarityMethods.PEARSONS_CORRELATION, Double.MIN_VALUE);
36 | scores.put(SimilarityMethods.SPEARMANS_CORRELATION, Double.MIN_VALUE);
37 | scores.put(SimilarityMethods.MSRobin, Double.MIN_VALUE);
38 | scores.put(SimilarityMethods.MEAN_SQUARED_ERROR, Double.MAX_VALUE);
39 | }
40 |
41 | public MSnSpectrum getBestSimilarSpec() {
42 | return bestSimilarSpec;
43 | }
44 |
45 | public void setBestSimilarSpec(MSnSpectrum bestSimilarSpec) {
46 | this.bestSimilarSpec = bestSimilarSpec;
47 | }
48 |
49 | public String getSpectrumName() {
50 | return spectrumName;
51 | }
52 |
53 | public String getSpectrumChargeAsString() {
54 | return spectrumChargeAsString;
55 | }
56 |
57 | public double getSpectrumPrecursorMZ() {
58 | return spectrumPrecursorMZ;
59 | }
60 |
61 | public double getScore() {
62 | return score;
63 | }
64 |
65 | public void setScore(double score) {
66 | this.score = score;
67 | }
68 |
69 | public EnumMap getScores() {
70 | return scores;
71 | }
72 |
73 | public void setScores(EnumMap scores) {
74 | this.scores = scores;
75 | }
76 |
77 | public String getSpectrumToCompare() {
78 | return spectrumToCompare;
79 | }
80 |
81 | public void setSpectrumToCompareName(String spectrumToCompare) {
82 | this.spectrumToCompare = spectrumToCompare;
83 | }
84 |
85 | public String getSpectrumToCompareChargeAsString() {
86 | return spectrumToCompareChargeAsString;
87 | }
88 |
89 | public void setspectrumToCompareChargeAsString(String spectrumToCompareChargeAsString) {
90 | this.spectrumToCompareChargeAsString = spectrumToCompareChargeAsString;
91 | }
92 |
93 | /**
94 | * This method updates a score if the same spectrum with higher similarity
95 | * score MSE has best scores as the lowest score
96 | *
97 | * @param similarityMethods
98 | * @param score
99 | */
100 | public void updateScore(SimilarityMethods similarityMethods, double score, String name) {
101 | if (score > scores.get(similarityMethods) && (!similarityMethods.equals(SimilarityMethods.MEAN_SQUARED_ERROR))) {
102 | scores.put(similarityMethods, score);
103 | setSpectrumToCompareName(name);
104 | }
105 | if (score < scores.get(similarityMethods) && (similarityMethods.equals(SimilarityMethods.MEAN_SQUARED_ERROR))) {
106 | scores.put(similarityMethods, score);
107 | setSpectrumToCompareName(name);
108 | }
109 | }
110 | }
111 |
--------------------------------------------------------------------------------
/src/main/java/config/ConfigHolder.java:
--------------------------------------------------------------------------------
1 | /*
2 | * This class is a PropertiesConfiguration singleton.
3 | */
4 | package config;
5 |
6 | import java.io.IOException;
7 | import org.apache.commons.configuration.ConfigurationException;
8 | import org.apache.commons.configuration.PropertiesConfiguration;
9 | import org.apache.log4j.Logger;
10 | import org.springframework.core.io.Resource;
11 |
12 | public class ConfigHolder extends PropertiesConfiguration {
13 |
14 | /**
15 | * Logger instance.
16 | */
17 | private static final Logger LOGGER = Logger.getLogger(ConfigHolder.class);
18 | /**
19 | * ConfigHolder singleton instance.
20 | */
21 | private static ConfigHolder ourInstance;
22 |
23 | static {
24 | try {
25 | //Resource propertiesResource = ResourceUtils.getResourceByRelativePath("BookChapter.properties");
26 | Resource propertiesResource = ResourceUtils.getResourceByRelativePath("MS2Similarity.properties");
27 | ourInstance = new ConfigHolder(propertiesResource);
28 | } catch (IOException | ConfigurationException e) {
29 | LOGGER.error(e.getMessage(), e);
30 | }
31 | }
32 |
33 | /**
34 | * Private constructor to prevent instantiation.
35 | *
36 | * @param propertiesResource the properties resource
37 | * @throws ConfigurationException in case of a configuration initialization
38 | * problem
39 | * @throws IOException in case of an I/O related problem
40 | */
41 | private ConfigHolder(Resource propertiesResource) throws ConfigurationException, IOException {
42 | super(propertiesResource.getURL());
43 | }
44 |
45 | /**
46 | * Gets the PropertiesConfiguration instance
47 | *
48 | * @return the PropertiesConfigurationHolder instance
49 | */
50 | public static ConfigHolder getInstance() {
51 | return ourInstance;
52 | }
53 |
54 | public static ConfigHolder getInstanceProteinDiversity() throws ConfigurationException, IOException {
55 | Resource propertiesResource = ResourceUtils.getResourceByRelativePath("resources/ProteinDiversity.properties");
56 | ourInstance = new ConfigHolder(propertiesResource);
57 | return ourInstance;
58 | }
59 | }
60 |
--------------------------------------------------------------------------------
/src/main/java/config/ResourceUtils.java:
--------------------------------------------------------------------------------
1 | /*
2 | * To change this license header, choose License Headers in Project Properties.
3 | * To change this template file, choose Tools | Templates
4 | * and open the template in the editor.
5 | */
6 | package config;
7 |
8 | import java.io.File;
9 | import org.springframework.core.io.ClassPathResource;
10 | import org.springframework.core.io.FileSystemResource;
11 | import org.springframework.core.io.Resource;
12 |
13 | /**
14 | *
15 | * @author Niels Hulstaert
16 | */
17 | public class ResourceUtils {
18 |
19 | private static final String RESOURCES_FOLDER = "resources";
20 |
21 | /**
22 | * Gets a resource by its relative path. If the resource is not found on the
23 | * file system, the classpath is searched. If nothing is found, null is
24 | * returned.
25 | *
26 | * @param fileName the name of the resource
27 | * @return the found resource
28 | */
29 | public static Resource getResourceByRelativePath(String fileName) {
30 | Resource resource = new FileSystemResource(RESOURCES_FOLDER + File.separator + fileName);
31 | if (!resource.exists()) {
32 | //try to find it on the classpath
33 | resource = new ClassPathResource(fileName);
34 | if (!resource.exists()) {
35 | // making sure to run on Netbeans..
36 | resource = new FileSystemResource("src" + File.separator + "main" + File.separator + RESOURCES_FOLDER + File.separator + fileName);
37 | if (!resource.exists()) {
38 | resource = null;
39 | }
40 | }
41 | }
42 | return resource;
43 | }
44 |
45 | /**
46 | * Checks if a resource with the given relative path exists on the file
47 | * system.
48 | *
49 | * @param relativePath the relative path of the resource
50 | * @return the is existing boolean
51 | */
52 | public static boolean isExistingFile(String relativePath) {
53 | boolean isExistingResource = Boolean.FALSE;
54 | Resource resource = new FileSystemResource(relativePath);
55 | if (resource.exists()) {
56 | isExistingResource = true;
57 | }
58 |
59 | return isExistingResource;
60 | }
61 | }
62 |
--------------------------------------------------------------------------------
/src/main/java/gui/LogTextAreaAppender.java:
--------------------------------------------------------------------------------
1 | package gui;
2 |
3 | import javax.swing.SwingUtilities;
4 | import org.apache.log4j.WriterAppender;
5 | import org.apache.log4j.spi.LoggingEvent;
6 |
7 | /**
8 | * Appender class for writing log messages to a JTextArea.
9 | *
10 | * @author Niels Hulstaert
11 | */
12 | public class LogTextAreaAppender extends WriterAppender {
13 |
14 | /**
15 | * The dialog to log to.
16 | */
17 | private RunDialog runDialog;
18 |
19 | public void setRunDialog(RunDialog runDialog) {
20 | this.runDialog = runDialog;
21 | }
22 |
23 | @Override
24 | public void append(LoggingEvent event) {
25 | final String message = this.layout.format(event);
26 |
27 | SwingUtilities.invokeLater(new Runnable() {
28 | @Override
29 | public void run() {
30 | runDialog.getLogTextArea().append(message);
31 | //repaint view
32 | runDialog.validate();
33 | runDialog.repaint();
34 | }
35 | });
36 | }
37 |
38 | }
39 |
--------------------------------------------------------------------------------
/src/main/java/gui/RunDialog.form:
--------------------------------------------------------------------------------
1 |
2 |
3 |
107 |
--------------------------------------------------------------------------------
/src/main/java/gui/RunDialog.java:
--------------------------------------------------------------------------------
1 | package gui;
2 |
3 | import javax.swing.JButton;
4 | import javax.swing.JTextArea;
5 |
6 | /**
7 | *
8 | * @author Niels Hulstaert
9 | */
10 | public class RunDialog extends javax.swing.JDialog {
11 |
12 | /**
13 | * Creates new form RunDialog.
14 | *
15 | * @param parent the parent frame
16 | * @param modal the modal boolean
17 | */
18 | public RunDialog(java.awt.Frame parent, boolean modal) {
19 | super(parent, modal);
20 | initComponents();
21 |
22 | org.apache.log4j.lf5.viewer.LF5SwingUtils.makeVerticalScrollBarTrack(jScrollPane1);
23 | }
24 |
25 | public JButton getCancelButton() {
26 | return cancelButton;
27 | }
28 |
29 | public JButton getClearButton() {
30 | return clearButton;
31 | }
32 |
33 | public JTextArea getLogTextArea() {
34 | return logTextArea;
35 | }
36 |
37 | /**
38 | * This method is called from within the constructor to initialize the form.
39 | * WARNING: Do NOT modify this code. The content of this method is always
40 | * regenerated by the Form Editor.
41 | */
42 | @SuppressWarnings("unchecked")
43 | // //GEN-BEGIN:initComponents
44 | private void initComponents() {
45 |
46 | jScrollPane1 = new javax.swing.JScrollPane();
47 | logTextArea = new javax.swing.JTextArea();
48 | cancelButton = new javax.swing.JButton();
49 | clearButton = new javax.swing.JButton();
50 |
51 | setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
52 | setTitle("Spectrum similarity score pipeline progress");
53 |
54 | logTextArea.setEditable(false);
55 | logTextArea.setColumns(20);
56 | logTextArea.setLineWrap(true);
57 | logTextArea.setRows(5);
58 | jScrollPane1.setViewportView(logTextArea);
59 |
60 | cancelButton.setText("cancel");
61 | cancelButton.setToolTipText("cancel the pipeline execution");
62 | cancelButton.setMaximumSize(new java.awt.Dimension(85, 27));
63 | cancelButton.setMinimumSize(new java.awt.Dimension(85, 27));
64 | cancelButton.setPreferredSize(new java.awt.Dimension(85, 27));
65 |
66 | clearButton.setText("clear");
67 | clearButton.setToolTipText("clear the log output");
68 | clearButton.setMaximumSize(new java.awt.Dimension(85, 27));
69 | clearButton.setMinimumSize(new java.awt.Dimension(85, 27));
70 | clearButton.setPreferredSize(new java.awt.Dimension(85, 27));
71 |
72 | javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
73 | getContentPane().setLayout(layout);
74 | layout.setHorizontalGroup(
75 | layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
76 | .addGroup(layout.createSequentialGroup()
77 | .addContainerGap()
78 | .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
79 | .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 688, Short.MAX_VALUE)
80 | .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
81 | .addGap(0, 0, Short.MAX_VALUE)
82 | .addComponent(clearButton, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
83 | .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
84 | .addComponent(cancelButton, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
85 | .addContainerGap())
86 | );
87 | layout.setVerticalGroup(
88 | layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
89 | .addGroup(layout.createSequentialGroup()
90 | .addContainerGap()
91 | .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 255, Short.MAX_VALUE)
92 | .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
93 | .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
94 | .addComponent(cancelButton, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
95 | .addComponent(clearButton, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
96 | .addContainerGap())
97 | );
98 |
99 | pack();
100 | }// //GEN-END:initComponents
101 |
102 |
103 | // Variables declaration - do not modify//GEN-BEGIN:variables
104 | private javax.swing.JButton cancelButton;
105 | private javax.swing.JButton clearButton;
106 | private javax.swing.JScrollPane jScrollPane1;
107 | private javax.swing.JTextArea logTextArea;
108 | // End of variables declaration//GEN-END:variables
109 | }
110 |
--------------------------------------------------------------------------------
/src/main/java/gui_spectral_match_visualization/SimilarityTableCellRenderer.java:
--------------------------------------------------------------------------------
1 | /*
2 | * To change this template, choose Tools | Templates
3 | * and open the template in the editor.
4 | */
5 | package gui_spectral_match_visualization;
6 |
7 | import java.awt.Color;
8 | import java.awt.Component;
9 | import javax.swing.JTable;
10 | import javax.swing.table.DefaultTableCellRenderer;
11 |
12 | /**
13 | *
14 | * @author Sule
15 | */
16 | public class SimilarityTableCellRenderer extends DefaultTableCellRenderer {
17 |
18 | private int indSpecA = 1,
19 | indSpecB = 4;
20 |
21 | public int getIndSpecA() {
22 | return indSpecA;
23 | }
24 |
25 | public void setIndSpecA(int indSpecA) {
26 | this.indSpecA = indSpecA;
27 | }
28 |
29 | public int getIndSpecB() {
30 | return indSpecB;
31 | }
32 |
33 | public void setIndSpecB(int indSpecB) {
34 | this.indSpecB = indSpecB;
35 | }
36 |
37 | @Override
38 | public Component getTableCellRendererComponent(JTable table,
39 | Object value,
40 | boolean isSelected,
41 | boolean hasFocus,
42 | int row,
43 | int column) {
44 | Component c = super.getTableCellRendererComponent(table, value,
45 | isSelected, hasFocus,
46 | row, column);
47 | Color lightBlue = Color.getHSBColor(0.56f, 0.3f, 1f),
48 | lightPink = Color.getHSBColor(0.92f, 0.3f, 1f);
49 | // 0.16f,0.4f, 1f = lightYellow
50 | // Color.getHSBColor(0.76f,0.4f, 1f) = purple
51 | if (column == indSpecA) {
52 | c.setBackground(lightPink);
53 | c.setForeground(Color.BLACK);
54 | } else if (column == indSpecB) {
55 | c.setBackground(lightBlue);
56 | c.setForeground(Color.BLACK);
57 | } else {
58 | c.setBackground(Color.WHITE);
59 | c.setForeground(Color.BLACK);
60 | }
61 | // if a cell is selected, highlight a row
62 | if (isSelected) {
63 | if (column == indSpecA) {
64 | c.setBackground(Color.RED);
65 | c.setForeground(Color.WHITE);
66 | } else if (column == indSpecB) {
67 | c.setBackground(Color.BLUE);
68 | c.setForeground(Color.WHITE);
69 | } else {
70 | c.setBackground(Color.GRAY);
71 | c.setForeground(Color.WHITE);
72 | }
73 | }
74 | return c;
75 | }
76 | }
77 |
--------------------------------------------------------------------------------
/src/main/java/gui_spectral_match_visualization/SimilarityTableModel.java:
--------------------------------------------------------------------------------
1 | /*
2 | * To change this template, choose Tools | Templates
3 | * and open the template in the editor.
4 | */
5 | package gui_spectral_match_visualization;
6 |
7 | import javax.swing.table.AbstractTableModel;
8 |
9 | /**
10 | *
11 | * @author Sule
12 | */
13 | public class SimilarityTableModel extends AbstractTableModel {
14 |
15 | public SimilarityTableModel(String[] columnNames, Object[][] data) {
16 | this.columnNames = columnNames;
17 | this.data = data;
18 | }
19 |
20 | private String[] columnNames;
21 | private Object[][] data;
22 |
23 | public int getColumnCount() {
24 | return columnNames.length;
25 | }
26 |
27 | public int getRowCount() {
28 | return data.length;
29 | }
30 |
31 | @Override
32 | public String getColumnName(int col) {
33 | return columnNames[col];
34 | }
35 |
36 | public Object getValueAt(int row, int col) {
37 | return data[row][col];
38 | }
39 |
40 | public void setValueAt(Object value, int row, int col) {
41 | data[row][col] = value;
42 | fireTableCellUpdated(row, col);
43 | }
44 |
45 | public int getLeadSelectionIndex() {
46 | return -1;
47 | }
48 |
49 | }
50 |
--------------------------------------------------------------------------------
/src/main/java/main/ScorePipelineStarter.java:
--------------------------------------------------------------------------------
1 | package main;
2 |
3 | import gui.LogTextAreaAppender;
4 | import gui.MainController;
5 | import java.awt.Color;
6 | import java.awt.Dimension;
7 | import java.awt.EventQueue;
8 | import java.awt.Graphics2D;
9 | import javax.swing.JFileChooser;
10 | import javax.swing.JOptionPane;
11 | import javax.swing.JScrollPane;
12 | import javax.swing.JTextArea;
13 | import javax.swing.Painter;
14 | import javax.swing.UIManager;
15 | import org.apache.log4j.Level;
16 | import org.apache.log4j.Logger;
17 | import org.apache.log4j.PatternLayout;
18 | import org.apache.log4j.Priority;
19 |
20 | /**
21 | * This class runs the score pipeline graphical user interface (GUI).
22 | *
23 | * @author Niels Hulstaert
24 | */
25 | public class ScorePipelineStarter {
26 |
27 | /**
28 | * Logger instance.
29 | */
30 | private static Logger LOGGER;
31 |
32 | /**
33 | * The startup error message.
34 | */
35 | private static final String ERROR_MESSAGE = "An error occured during startup, please try again."
36 | + System.lineSeparator() + "If the problem persists, contact your administrator or post an issue on the google code page.";
37 |
38 | /**
39 | * The GUI main controller.
40 | */
41 | private MainController mainController = new MainController();
42 |
43 | /**
44 | * No-arg constructor.
45 | */
46 | public ScorePipelineStarter() {
47 | }
48 |
49 | /**
50 | * Main method.
51 | *
52 | * @param args the main method arguments
53 | */
54 | public static void main(final String[] args) {
55 | LOGGER = Logger.getLogger(ScorePipelineStarter.class);
56 | /*
57 | * Set the Nimbus look and feel
58 | */
59 | //
60 | /*
61 | * If Nimbus (introduced in Java SE 6) is not available, stay with the
62 | * default look and feel. For details see
63 | * http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
64 | */
65 | try {
66 | for (UIManager.LookAndFeelInfo info : UIManager.getInstalledLookAndFeels()) {
67 | if ("Nimbus".equals(info.getName())) {
68 | UIManager.setLookAndFeel(info.getClassName());
69 | break;
70 | }
71 | }
72 | } catch (ClassNotFoundException | InstantiationException | IllegalAccessException | javax.swing.UnsupportedLookAndFeelException ex) {
73 | LOGGER.error(ex.getMessage(), ex);
74 | }
75 | //
76 |
77 | //set background color for JOptionPane and JPanel instances
78 | UIManager.getLookAndFeelDefaults().put("OptionPane.background", Color.WHITE);
79 | UIManager.getLookAndFeelDefaults().put("Panel.background", Color.WHITE);
80 | UIManager.getLookAndFeelDefaults().put("FileChooser.background", Color.WHITE);
81 | //set background color for JFileChooser instances
82 | UIManager.getLookAndFeelDefaults().put("FileChooser[Enabled].backgroundPainter",
83 | (Painter) new Painter() {
84 | @Override
85 | public void paint(Graphics2D g, JFileChooser object, int width, int height) {
86 | g.setColor(Color.WHITE);
87 | g.draw(object.getBounds());
88 | }
89 | });
90 |
91 | ScorePipelineStarter scorePipelineStarter = new ScorePipelineStarter();
92 | scorePipelineStarter.launch();
93 | }
94 |
95 | /**
96 | * Launch the GUI.
97 | */
98 | private void launch() {
99 | try {
100 | mainController.init();
101 | mainController.showView();
102 | } catch (Exception ex) {
103 | LOGGER.error(ex.getMessage(), ex);
104 | //add message to JTextArea
105 | JTextArea textArea = new JTextArea(ERROR_MESSAGE + System.lineSeparator() + System.lineSeparator() + ex.getMessage());
106 | //put JTextArea in JScrollPane
107 | JScrollPane scrollPane = new JScrollPane(textArea);
108 | scrollPane.setPreferredSize(new Dimension(600, 200));
109 | textArea.setEditable(false);
110 | textArea.setLineWrap(true);
111 | textArea.setWrapStyleWord(true);
112 |
113 | JOptionPane.showMessageDialog(null, scrollPane, "Score pipeline startup error", JOptionPane.ERROR_MESSAGE);
114 | System.exit(0);
115 | }
116 | }
117 | }
118 |
--------------------------------------------------------------------------------
/src/main/java/preprocess/filter/main/RunNoiseFiltering.java:
--------------------------------------------------------------------------------
1 | /*
2 | * To change this template, choose Tools | Templates
3 | * and open the template in the editor.
4 | */
5 | package preprocess.filter.main;
6 |
7 | import preprocess.filter.noise.implementation.NoiseFilteringPrideAsap;
8 | import com.compomics.util.experiment.massspectrometry.MSnSpectrum;
9 | import com.compomics.util.experiment.massspectrometry.SpectrumFactory;
10 | import com.compomics.util.gui.waiting.waitinghandlers.WaitingHandlerCLIImpl;
11 | import com.compomics.util.waiting.WaitingHandler;
12 | import java.io.BufferedWriter;
13 | import java.io.File;
14 | import java.io.FileNotFoundException;
15 | import java.io.FileWriter;
16 | import java.io.IOException;
17 | import uk.ac.ebi.jmzml.xml.io.MzMLUnmarshallerException;
18 |
19 | /**
20 | *
21 | * @author Sule
22 | */
23 | public class RunNoiseFiltering {
24 |
25 | /**
26 | * @param args the command line arguments
27 | */
28 | public static void main(String[] args) throws IOException, FileNotFoundException, ClassNotFoundException, MzMLUnmarshallerException {
29 |
30 | File mgfs = new File("C:/Users/Sule/Documents/NetBeansProjects/TapeWormAnalysis/Data/mgfs/Proteowizard/Step4_after_UNAMdb_analysis/Goat_taenia_hydatigena_after_unam_analysis");
31 | int num = 0;
32 | // count spectra size before and after
33 | File result = new File("goat_all_spec_number.txt");
34 | BufferedWriter bw = new BufferedWriter(new FileWriter(result));
35 | bw.write("SpecName" + "\t" + "Before_Spec_Size" + "\t" + "After_Spec_Size" + "\n");
36 | WaitingHandler wr = new WaitingHandlerCLIImpl();
37 | for (File mgf : mgfs.listFiles()) {
38 | num = 0;
39 | if (mgf.getName().endsWith("mgf")) {
40 | File newMgf = new File(mgf.getName().substring(0, mgf.getName().indexOf(".mgf")) + "_noisefiltered_2.mgf");
41 | BufferedWriter bw2 = new BufferedWriter(new FileWriter(newMgf));
42 | SpectrumFactory fct = SpectrumFactory.getInstance();
43 | fct.addSpectra(mgf, wr);
44 | // System.out.println(mgf.getName());
45 | for (String title : fct.getSpectrumTitles(mgf.getName())) {
46 | MSnSpectrum msms = (MSnSpectrum) fct.getSpectrum(mgf.getName(), title);
47 | int before = msms.getPeakList().size();
48 | NoiseFilteringPrideAsap noiseFilterImp = new NoiseFilteringPrideAsap();
49 | noiseFilterImp.noiseFilter(msms);
50 | int after = msms.getPeakList().size();
51 | String asMgf = msms.asMgf();
52 | bw2.write(asMgf);
53 | bw2.newLine();
54 | System.out.println("Before=" + "\t" + before + "\t" + "after=" + after + "\t");
55 | bw.write(msms.getSpectrumTitle() + "\t" + before + "\t" + after + "\n");
56 | }
57 | // bw.write(mgf.getName() + "\t" + num + "\t"+ before+ "\t"+ after "\n");
58 | // System.out.println(mgf.getName() + "\t" + num);
59 | fct.clearFactory();
60 | bw2.close();
61 | }
62 | }
63 | bw.close();
64 | }
65 | }
66 |
--------------------------------------------------------------------------------
/src/main/java/preprocess/filter/noise/implementation/DiscardLowIntensePeaks.java:
--------------------------------------------------------------------------------
1 | /*
2 | * To change this license header, choose License Headers in Project Properties.
3 | * To change this template file, choose Tools | Templates
4 | * and open the template in the editor.
5 | */
6 | package preprocess.filter.noise.implementation;
7 |
8 | import preprocess.filter.noise.interfaces.NoiseFilter;
9 | import com.compomics.util.experiment.massspectrometry.MSnSpectrum;
10 | import com.compomics.util.experiment.massspectrometry.Peak;
11 | import java.util.ArrayList;
12 |
13 | /**
14 | * This class discards peaks with intensities smaller than
15 | * (Percentage*MaximumIntensity). The default percentage is 5%
16 | *
17 | * @author Sule
18 | */
19 | public class DiscardLowIntensePeaks implements NoiseFilter {
20 |
21 | private double percentage = 5.00; // X% of the highest intensity
22 |
23 | public DiscardLowIntensePeaks(double percentage) {
24 | this.percentage = percentage;
25 | }
26 |
27 | /**
28 | * This method discards peaks with intensities less than given percentage
29 | * (on constructor) of the maximum intensities.
30 | *
31 | * Default percentage is 5%
32 | *
33 | */
34 | @Override
35 | public MSnSpectrum noiseFilter(MSnSpectrum ms) {
36 | // select the peak with the most intense
37 | double highest_intensity = Double.MIN_VALUE;
38 | for (Peak p : ms.getPeakList()) {
39 | double tmp_intensity = p.getIntensity();
40 | if (highest_intensity < tmp_intensity) {
41 | highest_intensity = tmp_intensity;
42 | }
43 | }
44 | // find the threshold value and keep only the one higher than threshold
45 | double threshold = (highest_intensity * percentage) / 100;
46 | ArrayList subList = new ArrayList();
47 | for (Peak p : ms.getPeakList()) {
48 | double tmp_intensity = p.getIntensity();
49 | if (tmp_intensity >= threshold) {
50 | subList.add(p);
51 | }
52 | }
53 | ms.getPeakList().clear();
54 | ms.setMzOrdered(false);
55 | ms.setPeaks(subList);
56 | return ms;
57 | }
58 |
59 | }
60 |
--------------------------------------------------------------------------------
/src/main/java/preprocess/filter/noise/implementation/DivideAndNormalize.java:
--------------------------------------------------------------------------------
1 | /*
2 | * To change this license header, choose License Headers in Project Properties.
3 | * To change this template file, choose Tools | Templates
4 | * and open the template in the editor.
5 | */
6 | package preprocess.filter.noise.implementation;
7 |
8 | import com.compomics.util.experiment.massspectrometry.Peak;
9 | import com.compomics.util.experiment.massspectrometry.Spectrum;
10 | import java.util.ArrayList;
11 |
12 | /**
13 | * This class divide a spectrum into 10 intervals. For each interval, normalize
14 | * intensities by 50
15 | *
16 | * @author Sule
17 | */
18 | public class DivideAndNormalize extends Filter {
19 |
20 | private int intervals; // how many intervals are at one experimental spectrum
21 | private double normalize_value; // normalization value (each intensity normalize up to this)
22 |
23 | /**
24 | * A spectrum will be divided into #intervals For each interval, the maximum
25 | * intensity would be 50, the other intensities would be rescaled by its
26 | * ratio to the maximum intensity and multiplied by 50
27 | *
28 | * @param expSpectrum an experimental spectrum
29 | * @param intervals number of intervals dividing this given spectrum
30 | * @param normalize_value the value that would all intensities would be
31 | * normalized by
32 | */
33 | public DivideAndNormalize(Spectrum expSpectrum, int intervals, double normalize_value) {
34 | super.expSpectrum = expSpectrum;
35 | this.intervals = intervals;
36 | this.normalize_value = normalize_value;
37 | }
38 |
39 | public int getIntervals() {
40 | return intervals;
41 | }
42 |
43 | public double getNormalize_value() {
44 | return normalize_value;
45 | }
46 |
47 | @Override
48 | public void process() {
49 | double minMz = expSpectrum.getMinMz(),
50 | maxMZ = expSpectrum.getMaxMz();
51 | // Introducing 0.0000001 in order to make sure the last peak would be in the last bin
52 | double interval_size = (maxMZ - minMz + 0.0000001) / intervals; // divide one spectrum into 10 intervals
53 | double tmp_lower_interval = minMz, // inclusive
54 | tmp_upper_interval = minMz + interval_size; // exclusive...
55 | ArrayList interval_peaks = new ArrayList(); // peaks within interval
56 | double max_intensity_interval = 0;
57 | for (int index_exp = 0; index_exp < expSpectrum.getOrderedMzValues().length; index_exp++) {
58 | double tmpMZ = expSpectrum.getOrderedMzValues()[index_exp];
59 | Peak tmpPeak = expSpectrum.getPeakMap().get(tmpMZ);
60 | if (tmpMZ >= tmp_lower_interval && tmpMZ < tmp_upper_interval) {
61 | interval_peaks.add(tmpPeak);
62 | if (max_intensity_interval < tmpPeak.intensity) {
63 | max_intensity_interval = tmpPeak.intensity;
64 | }
65 | }
66 | if ((tmpMZ >= tmp_upper_interval) || (index_exp == expSpectrum.getOrderedMzValues().length - 1)) {
67 | // normalize all up to 50
68 | for (Peak p : interval_peaks) {
69 | double normalized_intensity = (double) (p.intensity * normalize_value) / (double) max_intensity_interval;
70 | filteredPeaks.add(new Peak(p.mz, normalized_intensity));
71 | }
72 | // reset parameters
73 | max_intensity_interval = 0;
74 | interval_peaks = new ArrayList();
75 | tmp_lower_interval += interval_size;
76 | tmp_upper_interval += interval_size;
77 | if ((index_exp != expSpectrum.getOrderedMzValues().length - 1)) {
78 | index_exp = index_exp - 1; // making sure to correctly starting if this is not the last interval...
79 | }
80 | }
81 | }
82 | }
83 |
84 | }
85 |
--------------------------------------------------------------------------------
/src/main/java/preprocess/filter/noise/implementation/DivideAndTopNFilter.java:
--------------------------------------------------------------------------------
1 | /*
2 | * To change this license header, choose License Headers in Project Properties.
3 | * To change this template file, choose Tools | Templates
4 | * and open the template in the editor.
5 | */
6 | package preprocess.filter.noise.implementation;
7 |
8 | import com.compomics.util.experiment.massspectrometry.Peak;
9 | import com.compomics.util.experiment.massspectrometry.Spectrum;
10 | import java.util.ArrayList;
11 | import java.util.Collections;
12 | //import org.apache.log4j.Logger;
13 |
14 | /**
15 | * This class divide a spectrum into windows and then selects N peaks with
16 | * highest intensity per each defined window size on an MSnSpectrum.
17 | *
18 | * @author Sule
19 | */
20 | public class DivideAndTopNFilter extends Filter {
21 |
22 | private int topN;
23 | private double windowMassSize = 100;
24 |
25 | /**
26 | * This constructs an object to filter out spectra based on 100Da window and
27 | * it selects X peaks with highest intensities for each window.
28 | *
29 | * @param expSpectrum is an experimental spectrum
30 | * @param topN is picked peak numbers with highest intensities
31 | */
32 | public DivideAndTopNFilter(Spectrum expSpectrum, int topN) {
33 | super.expSpectrum = expSpectrum;
34 | this.topN = topN;
35 | // LOGGER = Logger.getLogger(ConfigHolder.class);
36 | }
37 |
38 | /**
39 | * This constructs an object with a given window size instead of a default
40 | * value.
41 | *
42 | * The default window size is 100Da
43 | *
44 | * @param expSpectrum is an experimental spectrum
45 | * @param topN is picked peak numbers with highest intensities
46 | * @param windowMassSize size of window, based on this a given spectrum is
47 | * divided into smaller parts.
48 | *
49 | */
50 | public DivideAndTopNFilter(Spectrum expSpectrum, int topN, double windowMassSize) {
51 | super.expSpectrum = expSpectrum;
52 | this.topN = topN;
53 | this.windowMassSize = windowMassSize;
54 | // LOGGER = Logger.getLogger(ConfigHolder.class);
55 | }
56 |
57 | @Override
58 | protected void process() {
59 | // LOGGER.info(expSpectrum.getSpectrumTitle());
60 | double startMz = expSpectrum.getMinMz(),
61 | limitMz = startMz + windowMassSize;
62 | ArrayList cPeaks = new ArrayList();
63 | for (int index_exp = 0; index_exp < expSpectrum.getOrderedMzValues().length; index_exp++) {
64 | double tmpMZ = expSpectrum.getOrderedMzValues()[index_exp];
65 | Peak tmpPeak = expSpectrum.getPeakMap().get(tmpMZ);
66 | if (tmpMZ < limitMz) {
67 | cPeaks.add(tmpPeak);
68 | } else {
69 | Collections.sort(cPeaks, Peak.DescendingIntensityComparator);
70 | int tmp_num = topN;
71 | if (topN > cPeaks.size()) {
72 | tmp_num = cPeaks.size();
73 | }
74 | for (int num = 0; num < tmp_num; num++) {
75 | Peak tmpCPeakToAdd = cPeaks.get(num);
76 | filteredPeaks.add(tmpCPeakToAdd);
77 | }
78 | cPeaks.clear();
79 | limitMz = limitMz + windowMassSize;
80 | index_exp = index_exp - 1;
81 | }
82 | }
83 | if (!cPeaks.isEmpty()) {
84 | Collections.sort(cPeaks, Peak.DescendingIntensityComparator);
85 | int tmp_num = topN;
86 | if (topN > cPeaks.size()) {
87 | tmp_num = cPeaks.size();
88 | }
89 | for (int num = 0; num < tmp_num; num++) {
90 | Peak tmpCPeakToAdd = cPeaks.get(num);
91 | filteredPeaks.add(tmpCPeakToAdd);
92 | }
93 | }
94 | }
95 |
96 | public int getTopN() {
97 | return topN;
98 | }
99 |
100 | public void setTopN(int topN) {
101 | this.topN = topN;
102 | }
103 |
104 | public double getWindowMassSize() {
105 | return windowMassSize;
106 | }
107 |
108 | public void setWindowMassSize(double windowMassSize) {
109 | this.windowMassSize = windowMassSize;
110 | }
111 |
112 | }
113 |
--------------------------------------------------------------------------------
/src/main/java/preprocess/filter/noise/implementation/Filter.java:
--------------------------------------------------------------------------------
1 | /*
2 | * To change this license header, choose License Headers in Project Properties.
3 | * To change this template file, choose Tools | Templates
4 | * and open the template in the editor.
5 | */
6 | package preprocess.filter.noise.implementation;
7 |
8 | import com.compomics.util.experiment.massspectrometry.Peak;
9 | import com.compomics.util.experiment.massspectrometry.Spectrum;
10 | import java.util.ArrayList;
11 | import org.apache.log4j.Logger;
12 |
13 | /**
14 | * This class filter or normalize peaks on a given MSnSpectrum.
15 | *
16 | * @author Sule
17 | */
18 | public abstract class Filter {
19 |
20 | protected Spectrum expSpectrum;
21 | protected ArrayList filteredPeaks= new ArrayList();
22 | protected Logger LOGGER;
23 |
24 | /**
25 | * Apply filtering-process
26 | */
27 | protected abstract void process() ;
28 |
29 | public Spectrum getExpMSnSpectrum() {
30 | return expSpectrum;
31 | }
32 |
33 | public void setExpMSnSpectrum(Spectrum expMSnSpectrum) {
34 | this.expSpectrum = expMSnSpectrum;
35 | }
36 |
37 | /**
38 | * This method returns a list of filtered-peaks from given MSnSpectrum.
39 | *
40 | * @return an arraylist of Peaks
41 | */
42 | public ArrayList getFilteredPeaks() {
43 | if (filteredPeaks.isEmpty()&& !expSpectrum.getPeakList().isEmpty()) {
44 | process();
45 | }
46 | return filteredPeaks;
47 | }
48 | }
49 |
--------------------------------------------------------------------------------
/src/main/java/preprocess/filter/noise/implementation/NoiseFilteringPrideAsap.java:
--------------------------------------------------------------------------------
1 | /*
2 | * To change this template, choose Tools | Templates
3 | * and open the template in the editor.
4 | */
5 | package preprocess.filter.noise.implementation;
6 |
7 | import com.compomics.pride_asa_pipeline.logic.spectrum.filter.impl.NoiseThresholdFinderImpl;
8 | import preprocess.filter.noise.interfaces.NoiseFilter;
9 | import com.compomics.util.experiment.massspectrometry.MSnSpectrum;
10 | import com.compomics.util.experiment.massspectrometry.Peak;
11 | import java.util.ArrayList;
12 | import java.util.Collection;
13 |
14 | /**
15 | * This noise filtering was derived from PrideAsap
16 | *
17 | */
18 | public class NoiseFilteringPrideAsap implements NoiseFilter {
19 |
20 | private static final double PRECURSOR_MASS_WINDOW = 18.0;
21 |
22 | public NoiseFilteringPrideAsap() {
23 | }
24 |
25 | @Override
26 | public MSnSpectrum noiseFilter(MSnSpectrum ms) {
27 | NoiseThresholdFinderImpl threshold_finder = new NoiseThresholdFinderImpl();
28 | double[] intensityValuesAsArray = ms.getIntensityValuesAsArray();
29 | double threshold = threshold_finder.findNoiseThreshold(intensityValuesAsArray),
30 | precursor_mz = ms.getPrecursor().getMz();
31 | Collection peaks = ms.getPeakList();
32 | if (peaks == null) {
33 | return null;
34 | }
35 | ArrayList result = new ArrayList();
36 | for (Peak peak : peaks) {
37 | //add the peak to the peak list if the peak intensity > threshold
38 | // and if the MZ ratio is not in 18D range of experimental precursor mass
39 | if (peak.getIntensity() >= threshold && !(precursor_mz - PRECURSOR_MASS_WINDOW < peak.mz && peak.mz < precursor_mz + PRECURSOR_MASS_WINDOW)) {
40 | result.add(peak);
41 | }
42 | }
43 | ms.getPeakList().clear();
44 | ms.setPeaks(result);
45 | return ms;
46 | }
47 | }
48 |
--------------------------------------------------------------------------------
/src/main/java/preprocess/filter/noise/implementation/TopNFiltering.java:
--------------------------------------------------------------------------------
1 | /*
2 | * To change this license header, choose License Headers in Project Properties.
3 | * To change this template file, choose Tools | Templates
4 | * and open the template in the editor.
5 | */
6 | package preprocess.filter.noise.implementation;
7 |
8 | import preprocess.filter.noise.interfaces.NoiseFilter;
9 | import com.compomics.util.experiment.massspectrometry.MSnSpectrum;
10 | import com.compomics.util.experiment.massspectrometry.Peak;
11 | import java.util.ArrayList;
12 | import java.util.Collections;
13 |
14 | /**
15 | * This class keeps the top N intense peaks
16 | *
17 | * @author Sule
18 | */
19 | public class TopNFiltering implements NoiseFilter {
20 |
21 | private int topN = 50;
22 |
23 | /**
24 | *
25 | * @param topN is number of top intense peaks
26 | */
27 | public TopNFiltering(int topN) {
28 | this.topN = topN;
29 | }
30 |
31 | /**
32 | * This class keeps only the top N intense peaks
33 | *
34 | * @param ms
35 | * @return
36 | */
37 | @Override
38 | public MSnSpectrum noiseFilter(MSnSpectrum ms) {
39 | ArrayList peakList = new ArrayList(ms.getPeakList());
40 | // Sort peaks in descending order on intensities
41 | Collections.sort(peakList, Peak.DescendingIntensityComparator);
42 | // This part makes sure that topN can never be bigger than peakList
43 | if (peakList.size() < topN) {
44 | topN = peakList.size();
45 | }
46 | // This selects the top N peaks
47 | ArrayList subPeakList = new ArrayList(peakList.subList(0, topN));
48 | // clear and set a peak list
49 | ms.getPeakList().clear();
50 | ms.setMzOrdered(false);
51 | ms.setPeaks(subPeakList);
52 | return ms;
53 | }
54 |
55 | }
56 |
--------------------------------------------------------------------------------
/src/main/java/preprocess/filter/noise/interfaces/NoiseFilter.java:
--------------------------------------------------------------------------------
1 | /*
2 | * To change this template, choose Tools | Templates
3 | * and open the template in the editor.
4 | */
5 | package preprocess.filter.noise.interfaces;
6 |
7 | import com.compomics.util.experiment.massspectrometry.MSnSpectrum;
8 |
9 | /**
10 | *
11 | * @author Sule
12 | */
13 | public interface NoiseFilter {
14 |
15 | /**
16 | * This method applies noise filtering a given MSnSpectrum object.
17 | * @param ms
18 | * @return
19 | */
20 | public MSnSpectrum noiseFilter(MSnSpectrum ms);
21 |
22 | }
23 |
--------------------------------------------------------------------------------
/src/main/java/preprocess/filter/precursor/RemovePrecursor.java:
--------------------------------------------------------------------------------
1 | /*
2 | * To change this license header, choose License Headers in Project Properties.
3 | * To change this template file, choose Tools | Templates
4 | * and open the template in the editor.
5 | */
6 | package preprocess.filter.precursor;
7 |
8 | import com.compomics.util.experiment.massspectrometry.MSnSpectrum;
9 |
10 | /**
11 | * This class enables removal of precursor ion from a given experimental spectrum
12 | *
13 | * @author Sule
14 | */
15 | public abstract class RemovePrecursor {
16 |
17 | protected MSnSpectrum ms;
18 | protected double fragmentTolerance;
19 |
20 | /**
21 | *
22 | * @param ms an MSnSpectrum object
23 | * @param fragmentTolerance fragment tolerance to pick peaks close to
24 | * precursor ion
25 | */
26 | public RemovePrecursor(MSnSpectrum ms, double fragmentTolerance) {
27 | this.ms = ms;
28 | this.fragmentTolerance = fragmentTolerance;
29 | }
30 |
31 | /**
32 | * This method to remove any precursor peak from an already given MSnSpectrum on the
33 | * constructor..
34 | */
35 | public abstract void removePrecursor();
36 |
37 | }
38 |
--------------------------------------------------------------------------------
/src/main/java/preprocess/filter/precursor/RemovePrecursorRelatedPeaks.java:
--------------------------------------------------------------------------------
1 | /*
2 | * To change this license header, choose License Headers in Project Properties.
3 | * To change this template file, choose Tools | Templates
4 | * and open the template in the editor.
5 | */
6 | package preprocess.filter.precursor;
7 |
8 | import com.compomics.util.experiment.biology.ions.ElementaryIon;
9 | import com.compomics.util.experiment.massspectrometry.MSnSpectrum;
10 | import com.compomics.util.experiment.massspectrometry.Peak;
11 | import java.util.ArrayList;
12 |
13 | /**
14 | * This class removes any peak within a fragment tolerance. These peaks were
15 | * found to be derived from a precursor ion
16 | *
17 | * @author Sule
18 | */
19 | public class RemovePrecursorRelatedPeaks extends RemovePrecursor {
20 |
21 | /**
22 | *
23 | * @param msms an MSnSpectrum object
24 | * @param fragmentTolerance fragment tolerance to pick peaks close to
25 | * precursor ion
26 | */
27 | public RemovePrecursorRelatedPeaks(MSnSpectrum msms, double fragmentTolerance) {
28 | super(msms, fragmentTolerance);
29 | }
30 |
31 | /**
32 | * This method finds out any peak within a fragment tolerance which is
33 | * derived from a precursor
34 | *
35 | */
36 | @Override
37 | public void removePrecursor() {
38 | ArrayList precursorPeaksMZ = new ArrayList();
39 | ArrayList peaksToRemove = new ArrayList(),
40 | peaks = new ArrayList(ms.getPeakList());
41 | // get a precursor charge
42 | double precursorMZ = ms.getPrecursor().getMz();
43 | int charge = ms.getPrecursor().getPossibleCharges().get(ms.getPrecursor().getPossibleCharges().size() - 1).value;
44 | precursorPeaksMZ.add(precursorMZ);
45 | // first select peaks may derive from a precursor
46 | double precursorMass = ms.getPrecursor().getMass(charge),
47 | protonTheoMass = ElementaryIon.proton.getTheoreticMass();
48 | if (charge >= 1) {
49 | while (charge >= 1) {
50 | double tmpMZ = (precursorMass + (protonTheoMass * charge)) / charge;
51 | precursorPeaksMZ.add(tmpMZ);
52 | charge--;
53 | }
54 | }
55 | // Now check actual peaks to get them
56 | int startIndex = 0;
57 | for (Double possiblePrecursorMZ : precursorPeaksMZ) {
58 | Peak removedPeak = null;
59 | boolean found_a_close_peak = false;
60 | // to find a closest peak
61 | double tmpFragmentTolerance = fragmentTolerance;
62 | for (int i = startIndex; i < peaks.size(); i++) {
63 | Peak tmpPeak = peaks.get(i);
64 | double diffMZ = Math.abs(tmpPeak.getMz() - possiblePrecursorMZ);
65 | if (diffMZ <= tmpFragmentTolerance) {
66 | tmpFragmentTolerance = diffMZ;
67 | removedPeak = ms.getPeakMap().get(tmpPeak.getMz());
68 | if (i > startIndex && !found_a_close_peak) {
69 | startIndex = i;
70 | found_a_close_peak = true;
71 | }
72 | }
73 | }
74 | if (removedPeak != null) {
75 | peaksToRemove.add(removedPeak);
76 | }
77 | }
78 | // now clear peak list from possibly derived from precursor peaks
79 | peaks.removeAll(peaksToRemove);
80 | ms.getPeakList().clear();
81 | ms.setMzOrdered(false);
82 | ms.setPeaks(peaks);
83 | }
84 |
85 | }
86 |
--------------------------------------------------------------------------------
/src/main/java/preprocess/filter/precursor/RemoveWindowAround.java:
--------------------------------------------------------------------------------
1 | /*
2 | * To change this license header, choose License Headers in Project Properties.
3 | * To change this template file, choose Tools | Templates
4 | * and open the template in the editor.
5 | */
6 | package preprocess.filter.precursor;
7 |
8 | import com.compomics.util.experiment.massspectrometry.MSnSpectrum;
9 | import com.compomics.util.experiment.massspectrometry.Peak;
10 | import java.util.ArrayList;
11 |
12 | /**
13 | *
14 | * This class removes an m/z window around a precursor ion
15 | *
16 | * @author Sule
17 | */
18 | public class RemoveWindowAround extends RemovePrecursor {
19 |
20 | private double windowSize = 10; // 10u as the default value
21 |
22 | /**
23 | * Remove any peaks within 10 window size around the precursor ion
24 | *
25 | * @param msms an MSnSpectrum object
26 | * @param fragmentTolerance fragment tolerance to set a size of a window
27 | * around precursor ion
28 | */
29 | public RemoveWindowAround(MSnSpectrum msms, double fragmentTolerance) {
30 | super(msms, fragmentTolerance);
31 |
32 | }
33 |
34 | /**
35 | * Remove any peaks within windowSize window size around the precursor ion
36 | *
37 | * @param msms an MSnSpectrum object
38 | * @param fragmentTolerance fragment tolerance to set a size of a window
39 | * around precursor ion
40 | * @param windowSize a window around a precursor ion
41 | *
42 | */
43 | public RemoveWindowAround(MSnSpectrum msms, double fragmentTolerance, double windowSize) {
44 | super(msms, fragmentTolerance);
45 | this.windowSize = windowSize;
46 |
47 | }
48 |
49 | /**
50 | * This method removes a window around precursor ion
51 | */
52 | @Override
53 | public void removePrecursor() {
54 | double precursorMZ = ms.getPrecursor().getMz();
55 | ArrayList keptPeaks = new ArrayList();
56 | ArrayList mzsWithinAWindow = new ArrayList();
57 | double[] mzValuesAsArray = ms.getOrderedMzValues();
58 | // remove any peak if mz is smaller than and bigger than or equal to
59 | for (int i = 0; i < mzValuesAsArray.length; i++) {
60 | double mz = mzValuesAsArray[i];
61 | if (mz < (precursorMZ + (windowSize/2)) && mz > (precursorMZ - (windowSize/2))) {
62 | mzsWithinAWindow.add(mz);
63 | }
64 | }
65 | // update a peak list...
66 | for (Double mz : ms.getPeakMap().keySet()) {
67 | if (!mzsWithinAWindow.contains(mz)) {
68 | keptPeaks.add(ms.getPeakMap().get(mz));
69 | }
70 | }
71 | // now clear peak list from possibly derived from precursor peaks
72 | ms.getPeakList().clear();
73 | ms.setMzOrdered(false);
74 | ms.setPeaks(keptPeaks);
75 | }
76 |
77 | }
78 |
--------------------------------------------------------------------------------
/src/main/java/preprocess/sort/Sorting.java:
--------------------------------------------------------------------------------
1 | /*
2 | * To change this template, choose Tools | Templates
3 | * and open the template in the editor.
4 | */
5 | package preprocess.sort;
6 |
7 | import java.util.Collections;
8 | import java.util.Comparator;
9 | import java.util.Iterator;
10 | import java.util.LinkedHashMap;
11 | import java.util.LinkedList;
12 | import java.util.List;
13 | import java.util.Map;
14 |
15 | /**
16 | *
17 | * @author Sule
18 | */
19 | public class Sorting {
20 |
21 | /**
22 | * This method sorts a map by values
23 | *
24 | * @param map is the one in study
25 | * @return a map with sorted values(Desc)
26 | */
27 | public static Map sortByValue(Map map) {
28 | List list = new LinkedList(map.entrySet());
29 | Collections.sort(list, new Comparator() {
30 | public int compare(Object o1, Object o2) {
31 | return ((Comparable) ((Map.Entry) (o1)).getValue()).compareTo(((Map.Entry) (o2)).getValue());
32 | }
33 | });
34 | Map result = new LinkedHashMap();
35 | for (Iterator it = list.iterator(); it.hasNext();) {
36 | Map.Entry entry = (Map.Entry) it.next();
37 | result.put(entry.getKey(), entry.getValue());
38 | }
39 | return result;
40 | }
41 |
42 | public static Map sortByKey(Map map) {
43 | List list = new LinkedList(map.entrySet());
44 | Collections.sort(list, new Comparator() {
45 | public int compare(Object o1, Object o2) {
46 | return ((Comparable) ((Map.Entry) (o1)).getKey()).compareTo(((Map.Entry) (o2)).getKey());
47 | }
48 | });
49 | Map result = new LinkedHashMap();
50 | for (Iterator it = list.iterator(); it.hasNext();) {
51 | Map.Entry entry = (Map.Entry) it.next();
52 | result.put(entry.getKey(), entry.getValue());
53 | }
54 | return result;
55 | }
56 |
57 | }
58 |
--------------------------------------------------------------------------------
/src/main/java/preprocess/transformation/interfaces/TransformIntensity.java:
--------------------------------------------------------------------------------
1 | /*
2 | * To change this license header, choose License Headers in Project Properties.
3 | * To change this template file, choose Tools | Templates
4 | * and open the template in the editor.
5 | */
6 |
7 | package preprocess.transformation.interfaces;
8 |
9 | import preprocess.transformation.methods.Transformations;
10 |
11 | /**
12 | * This interface shows a method used to transform intensities on a spectrum.
13 | *
14 | * @author Sule
15 | */
16 | public interface TransformIntensity {
17 |
18 |
19 | /**
20 | * This method transforms intensities on a spectrum
21 |
22 | * @param tr an enum Object of Transformations
23 | */
24 | public void transform(Transformations tr);
25 |
26 | }
27 |
--------------------------------------------------------------------------------
/src/main/java/preprocess/transformation/methods/Transformations.java:
--------------------------------------------------------------------------------
1 | /*
2 | * To change this license header, choose License Headers in Project Properties.
3 | * To change this template file, choose Tools | Templates
4 | * and open the template in the editor.
5 | */
6 |
7 | package preprocess.transformation.methods;
8 |
9 | /**
10 | * The transformations are applied to intensities are:
11 | *
12 | * LOG: Logarithmic transformation of intensities with 10 log-base
13 | * LOG_2: Logarithmic transformation of intensities with 2 log-base
14 | * SQR_ROOT: Square root transformation of intensities
15 | * RECIPROCAL: Transformation via division of intensities by 1 (1/intensity)
16 | *
17 | * @author Sule
18 | */
19 | public enum Transformations {
20 | LOG,
21 | LOG_2,
22 | SQR_ROOT,
23 | RECIPROCAL
24 | }
25 |
--------------------------------------------------------------------------------
/src/main/java/protein_spectrum_diversity/Analyse.java:
--------------------------------------------------------------------------------
1 | /*
2 | * To change this license header, choose License Headers in Project Properties.
3 | * To change this template file, choose Tools | Templates
4 | * and open the template in the editor.
5 | */
6 | package protein_spectrum_diversity;
7 |
8 | import cal.cumulativeBinomialProbability.spectra.CompareAndScore;
9 | import com.compomics.util.experiment.massspectrometry.MSnSpectrum;
10 | import com.compomics.util.experiment.massspectrometry.SpectrumFactory;
11 | import com.compomics.util.gui.waiting.waitinghandlers.WaitingHandlerCLIImpl;
12 | import config.ConfigHolder;
13 | import java.io.BufferedReader;
14 | import java.io.BufferedWriter;
15 | import java.io.File;
16 | import java.io.FileNotFoundException;
17 | import java.io.FileReader;
18 | import java.io.FileWriter;
19 | import java.io.IOException;
20 | import java.util.ArrayList;
21 | import java.util.Collection;
22 | import java.util.HashMap;
23 | import org.apache.commons.configuration.ConfigurationException;
24 | import uk.ac.ebi.jmzml.xml.io.MzMLUnmarshallerException;
25 |
26 | /**
27 | * This class directly calculates pairwise similarities
28 | * Finding spectra method was designed to find spectra on Kenneth's folder structure on NAS
29 | *
30 | * @author Sule
31 | */
32 | public class Analyse {
33 |
34 | /**
35 | * @param args the command line arguments
36 | */
37 | public static void main(String[] args) throws ConfigurationException, ConfigurationException, IOException, MzMLUnmarshallerException, Exception {
38 |
39 | double fragTol = 0.5;
40 | int msRobinOption = ConfigHolder.getInstanceProteinDiversity().getInt("msrobinintensityoption"),
41 | intensityOption = 1;
42 | SpectrumFactory fct = SpectrumFactory.getInstance();
43 | String spectraName = ConfigHolder.getInstanceProteinDiversity().getString("spectra.folder.name"),
44 | peptides = ConfigHolder.getInstanceProteinDiversity().getString("peptide.file.name"),
45 | rootFolderName = ConfigHolder.getInstanceProteinDiversity().getString("root.folder.name"),
46 | outputFolderName = ConfigHolder.getInstanceProteinDiversity().getString("output.folder.name");
47 | File rootFolder = new File(rootFolderName);
48 | System.out.println(spectraName);
49 |
50 | HashMap> accession_and_peptides = getAccessionAndPeptides(new File(peptides));
51 | // write all pairwise comparisons on one file
52 | BufferedWriter all = new BufferedWriter(new FileWriter(outputFolderName + "\\" + "all_output.txt"));
53 | String outputTitle = "Accession" + "\t" + "spectrum" + "\t" + "spectrumToCompare" + "\t" + "probability" + "\t" + "intensity" + "\t" + "MSRobin" + "\n";
54 | all.write(outputTitle);
55 | for (String acc : accession_and_peptides.keySet()) {
56 | // write pairwise comparisons for each proteins on one file separately
57 | BufferedWriter bw = new BufferedWriter(new FileWriter(outputFolderName + "\\" + acc + "_output.txt"));
58 | bw.write(outputTitle);
59 | System.out.println(outputFolderName + "\\" + acc + "_output.txt");
60 | // get theoeretical spectra
61 | File mergePeptides = mergePeptides(accession_and_peptides.get(acc), rootFolder, outputFolderName, acc);
62 | if (mergePeptides.getName().endsWith(".mgf")) {
63 | fct.clearFactory();
64 | fct.addSpectra(mergePeptides, new WaitingHandlerCLIImpl());
65 | for (String title : fct.getSpectrumTitles(mergePeptides.getName())) {
66 | MSnSpectrum ms = (MSnSpectrum) fct.getSpectrum(mergePeptides.getName(), title);
67 | // read each given file
68 | for (String title2 : fct.getSpectrumTitles(mergePeptides.getName())) {
69 | if (!title.equals(title2)) {
70 | MSnSpectrum ms2 = (MSnSpectrum) fct.getSpectrum(mergePeptides.getName(), title2);
71 | CompareAndScore comparison = new CompareAndScore(ms, ms2, fragTol, msRobinOption, intensityOption);
72 | bw.write(acc + "\t" + ms.getSpectrumTitle() + "\t"
73 | + ms2.getSpectrumTitle() + "\t" + comparison.getProbability_part() + "\t" + comparison.getIntensity_part() + "\t" + comparison.getMSRobinScore());
74 | bw.newLine();
75 | all.write(acc + "\t" + ms.getSpectrumTitle() + "\t"
76 | + ms2.getSpectrumTitle() + "\t" + comparison.getProbability_part() + "\t" + comparison.getIntensity_part() + "\t" + comparison.getMSRobinScore());
77 | all.newLine();
78 | }
79 | }
80 | }
81 | }
82 | bw.close();
83 | }
84 | all.close();
85 | }
86 |
87 | public static File getMGFForPeptide(String peptidesequence, File rootFolder) {
88 | String[] tokens = peptidesequence.split("(?<=\\G.{" + 3 + "})");
89 | String path = rootFolder.getAbsolutePath();
90 | for (String aToken : tokens) {
91 | path = path + "/" + aToken;
92 | }
93 | path = path + "/" + peptidesequence + ".mgf";
94 | return new File(path);
95 | }
96 |
97 | public static File mergePeptides(Collection sequences, File rootFolder, String outputFolder, String accession) throws IOException {
98 | File outputFile = new File(outputFolder + File.separator + accession + "_merged.mgf");
99 | FileWriter out = new FileWriter(outputFile, true);
100 | for (String aSequence : sequences) {
101 | File sequenceMGF = getMGFForPeptide(aSequence, rootFolder);
102 | if (sequenceMGF.exists() && !sequenceMGF.isDirectory()) {
103 | BufferedReader in = new BufferedReader(new FileReader(sequenceMGF));
104 | String line = "";
105 | while ((line = in.readLine()) != null) {
106 | out.append(line).append(System.lineSeparator()).flush();
107 | }
108 | }
109 | }
110 | out.flush();
111 | return outputFile;
112 | }
113 |
114 | private static HashMap> getAccessionAndPeptides(File file) throws FileNotFoundException, IOException {
115 | HashMap> accession_and_sequence = new HashMap>();
116 | BufferedReader br = new BufferedReader(new FileReader(file));
117 | String line = "";
118 | while ((line = br.readLine()) != null) {
119 | String[] sp = line.split("\t");
120 | String pep = sp[0],
121 | protein = sp[1];
122 | pep = pep.substring(2, pep.length() - 3);
123 | if (accession_and_sequence.containsKey(protein)) {
124 | accession_and_sequence.get(protein).add(pep);
125 | } else {
126 | ArrayList peps = new ArrayList();
127 | peps.add(pep);
128 | accession_and_sequence.put(protein, peps);
129 | }
130 | }
131 | return accession_and_sequence;
132 | }
133 |
134 | }
135 |
--------------------------------------------------------------------------------
/src/main/java/protein_spectrum_diversity/AnalyzeNISTSPecLib.java:
--------------------------------------------------------------------------------
1 | /*
2 | * To change this license header, choose License Headers in Project Properties.
3 | * To change this template file, choose Tools | Templates
4 | * and open the template in the editor.
5 | */
6 | package protein_spectrum_diversity;
7 |
8 | import cal.cumulativeBinomialProbability.spectra.CompareAndScore;
9 | import com.compomics.util.experiment.massspectrometry.MSnSpectrum;
10 | import com.compomics.util.experiment.massspectrometry.SpectrumFactory;
11 | import com.compomics.util.gui.waiting.waitinghandlers.WaitingHandlerCLIImpl;
12 | import config.ConfigHolder;
13 | import java.io.BufferedReader;
14 | import java.io.BufferedWriter;
15 | import java.io.File;
16 | import java.io.FileNotFoundException;
17 | import java.io.FileReader;
18 | import java.io.FileWriter;
19 | import java.io.IOException;
20 | import java.util.ArrayList;
21 | import java.util.HashMap;
22 | import org.apache.commons.configuration.ConfigurationException;
23 | import uk.ac.ebi.jmzml.xml.io.MzMLUnmarshallerException;
24 |
25 | /**
26 | * This method works on one mgf files which contains spectra from NIST-spectral library.
27 | * According to the given highCoveragedProteinList, it selects any spectra from peptide derived from this highCoveragedProteinList.
28 | * For each protein in the highCoveragedProteinList, it calculates spectra for peptides of one protein.
29 | *
30 | *
31 | * @author Sule
32 | */
33 | public class AnalyzeNISTSPecLib {
34 |
35 | /**
36 | * @param args the command line arguments
37 | */
38 | public static void main(String[] args) throws ConfigurationException, ConfigurationException, IOException, MzMLUnmarshallerException, Exception {
39 | double fragTol = 0.5;
40 | int msRobinOption = ConfigHolder.getInstanceProteinDiversity().getInt("msrobin"),
41 | msRobinIntensity = ConfigHolder.getInstanceProteinDiversity().getInt("msrobinintensityoption"),
42 | run_INTOpt = ConfigHolder.getInstanceProteinDiversity().getInt("charge.option");
43 | SpectrumFactory fct = SpectrumFactory.getInstance();
44 | String spectraName = ConfigHolder.getInstanceProteinDiversity().getString("spectra.folder.name"),
45 | clFileName = ConfigHolder.getInstanceProteinDiversity().getString("cl.file.name"),
46 | outputFolderName = ConfigHolder.getInstanceProteinDiversity().getString("output.folder.name"),
47 | highCoveragedProteinList = ConfigHolder.getInstanceProteinDiversity().getString("high.coveraged.protein.list");
48 | File spectraFile = new File(spectraName),
49 | highCovaredProteinsList = new File(highCoveragedProteinList);
50 |
51 | HashMap> accession_and_peptides = getAccessionAndPeptides(new File(clFileName), highCovaredProteinsList);
52 | BufferedWriter bw2 = new BufferedWriter(new FileWriter(outputFolderName + "\\" + "all_output_only_doubly_charged.txt"));
53 | String outputTitle = "Accession" + "\t" + "spectrum" + "\t" + "spectrumToCompare" + "\t" + "probability" + "\t" + "intensity" + "\t" + "MSRobin" + "\n";
54 | bw2.write(outputTitle);
55 |
56 | // load all spectra
57 | fct.addSpectra(spectraFile, new WaitingHandlerCLIImpl());
58 |
59 | for (String acc : accession_and_peptides.keySet()) {
60 | BufferedWriter bw = new BufferedWriter(new FileWriter(outputFolderName + "\\" + acc + "_output.txt"));
61 | bw.write(outputTitle);
62 | // get theoeretical spectra
63 | ArrayList clentries = accession_and_peptides.get(acc);
64 | ArrayList toAnalyze = new ArrayList();
65 | // select all possible MS/MS spectra derived from one protein
66 | for (CLEntry cl : clentries) {
67 | MSnSpectrum tmpMSMS = (MSnSpectrum) fct.getSpectrum(spectraFile.getName(), String.valueOf(cl.getSpectrum_id()));
68 | cl.setMsms(tmpMSMS);
69 | toAnalyze.add(cl);
70 | }
71 | // calculate...
72 | for (int i = 0; i < toAnalyze.size() - 1; i++) {
73 | boolean doesCompare = false;
74 | MSnSpectrum tmpSp = toAnalyze.get(i).getMsms();
75 | if (tmpSp.getPrecursor().getPossibleChargesAsString().equals("2+") && run_INTOpt == 0) {
76 | doesCompare = true;
77 | }
78 | if (tmpSp.getPrecursor().getPossibleChargesAsString().equals("3+") && run_INTOpt == 1) {
79 | doesCompare = true;
80 | }
81 | if (run_INTOpt == 2) {
82 | doesCompare = true;
83 | }
84 | // check also
85 | if (doesCompare) {
86 | for (int j = i + 1; j < toAnalyze.size() - 1; j++) {
87 | boolean doesCompareToCompare = false;
88 | MSnSpectrum tmpNextSp = toAnalyze.get(j).getMsms();
89 | if (tmpNextSp.getPrecursor().getPossibleChargesAsString().equals("2+") && run_INTOpt == 0) {
90 | doesCompareToCompare = true;
91 | }
92 | if (tmpNextSp.getPrecursor().getPossibleChargesAsString().equals("3+") && run_INTOpt == 1) {
93 | doesCompareToCompare = true;
94 | }
95 | if (run_INTOpt == 2) {
96 | doesCompareToCompare = true;
97 | }
98 | if (doesCompareToCompare) {
99 | CompareAndScore comparison = new CompareAndScore(tmpSp, tmpNextSp, fragTol, msRobinOption, msRobinIntensity);
100 | double score = comparison.getMSRobinScore();
101 | bw.write(acc + "\t" + tmpSp.getSpectrumTitle() + "\t" + tmpNextSp.getSpectrumTitle() + "\t"
102 | + comparison.getProbability_part() + "\t" + comparison.getIntensity_part() + "\t" + score);
103 | bw.newLine();
104 |
105 | bw2.write(acc + "\t" + tmpSp.getSpectrumTitle() + "\t" + tmpNextSp.getSpectrumTitle() + "\t"
106 | + comparison.getProbability_part() + "\t" + comparison.getIntensity_part() + "\t" + score);
107 | bw2.newLine();
108 | }
109 | }
110 | }
111 | }
112 | bw.close();
113 | }
114 | bw2.close();
115 | }
116 |
117 | private static HashMap> getAccessionAndPeptides(File file, File highCovaredProteinsList) throws IOException {
118 | ArrayList highCovareged = getList(highCovaredProteinsList);
119 | HashMap> accsApeptides = new HashMap>();
120 | BufferedReader br = new BufferedReader(new FileReader(file));
121 | String line = "";
122 | while ((line = br.readLine()) != null) {
123 | if (!line.startsWith("spec_id")) {
124 | CLEntry obj = new CLEntry(line);
125 | String protein = obj.getProtein();
126 | if (accsApeptides.containsKey(protein) && highCovareged.contains(protein)) {
127 | accsApeptides.get(protein).add(obj);
128 | } else if (!accsApeptides.containsKey(protein) && highCovareged.contains(protein)) {
129 | ArrayList clentries = new ArrayList();
130 | clentries.add(obj);
131 | accsApeptides.put(protein, clentries);
132 | }
133 | }
134 | }
135 | return accsApeptides;
136 | }
137 |
138 | private static ArrayList getList(File highCovaredProteinsList) throws FileNotFoundException, IOException {
139 | ArrayList list = new ArrayList();
140 | BufferedReader br = new BufferedReader(new FileReader(highCovaredProteinsList));
141 | String line = "";
142 | while ((line = br.readLine()) != null) {
143 | list.add(line);
144 | }
145 | return list;
146 | }
147 |
148 | }
149 |
--------------------------------------------------------------------------------
/src/main/java/protein_spectrum_diversity/CLEntry.java:
--------------------------------------------------------------------------------
1 | /*
2 | * To change this license header, choose License Headers in Project Properties.
3 | * To change this template file, choose Tools | Templates
4 | * and open the template in the editor.
5 | */
6 | package protein_spectrum_diversity;
7 |
8 | import com.compomics.util.experiment.massspectrometry.MSnSpectrum;
9 |
10 | /**
11 | * This class holds information from CL-input file
12 | *
13 | * @author Sule
14 | */
15 | public class CLEntry {
16 |
17 | private int spectrum_id,
18 | charge;
19 | private String modification,
20 | peptide_sequence,
21 | protein;
22 | private MSnSpectrum msms;
23 |
24 | public CLEntry(String line) {
25 | String[] sp = line.split(" ");
26 | spectrum_id = Integer.parseInt(sp[0]);
27 | charge = Integer.parseInt(sp[1]);
28 | modification = sp[2];
29 | peptide_sequence = sp[3];
30 | protein = sp[4].replace("\"", "");
31 | protein = protein.replace("|", "_");
32 | }
33 |
34 | public MSnSpectrum getMsms() {
35 | return msms;
36 | }
37 |
38 | public void setMsms(MSnSpectrum msms) {
39 | this.msms = msms;
40 | }
41 |
42 | public int getSpectrum_id() {
43 | return spectrum_id;
44 | }
45 |
46 | public void setSpectrum_id(int spectrum_id) {
47 | this.spectrum_id = spectrum_id;
48 | }
49 |
50 | public int getCharge() {
51 | return charge;
52 | }
53 |
54 | public void setCharge(int charge) {
55 | this.charge = charge;
56 | }
57 |
58 | public String getModification() {
59 | return modification;
60 | }
61 |
62 | public void setModification(String modification) {
63 | this.modification = modification;
64 | }
65 |
66 | public String getPeptide_sequence() {
67 | return peptide_sequence;
68 | }
69 |
70 | public void setPeptide_sequence(String peptide_sequence) {
71 | this.peptide_sequence = peptide_sequence;
72 | }
73 |
74 | public String getProtein() {
75 | return protein;
76 | }
77 |
78 | public void setProtein(String protein) {
79 | this.protein = protein;
80 | }
81 |
82 | @Override
83 | public int hashCode() {
84 | int hash = 5;
85 | hash = 97 * hash + this.spectrum_id;
86 | hash = 97 * hash + this.charge;
87 | hash = 97 * hash + (this.modification != null ? this.modification.hashCode() : 0);
88 | hash = 97 * hash + (this.peptide_sequence != null ? this.peptide_sequence.hashCode() : 0);
89 | hash = 97 * hash + (this.protein != null ? this.protein.hashCode() : 0);
90 | hash = 97 * hash + (this.msms != null ? this.msms.hashCode() : 0);
91 | return hash;
92 | }
93 |
94 | @Override
95 | public boolean equals(Object obj) {
96 | if (obj == null) {
97 | return false;
98 | }
99 | if (getClass() != obj.getClass()) {
100 | return false;
101 | }
102 | final CLEntry other = (CLEntry) obj;
103 | if (this.spectrum_id != other.spectrum_id) {
104 | return false;
105 | }
106 | if (this.charge != other.charge) {
107 | return false;
108 | }
109 | if ((this.modification == null) ? (other.modification != null) : !this.modification.equals(other.modification)) {
110 | return false;
111 | }
112 | if ((this.peptide_sequence == null) ? (other.peptide_sequence != null) : !this.peptide_sequence.equals(other.peptide_sequence)) {
113 | return false;
114 | }
115 | if ((this.protein == null) ? (other.protein != null) : !this.protein.equals(other.protein)) {
116 | return false;
117 | }
118 | if (this.msms != other.msms && (this.msms == null || !this.msms.equals(other.msms))) {
119 | return false;
120 | }
121 | return true;
122 | }
123 |
124 | }
125 |
--------------------------------------------------------------------------------
/src/main/java/protein_spectrum_diversity/KennethFileWalker.java:
--------------------------------------------------------------------------------
1 | /*
2 | * To change this license header, choose License Headers in Project Properties.
3 | * To change this template file, choose Tools | Templates
4 | * and open the template in the editor.
5 | */
6 | package protein_spectrum_diversity;
7 |
8 | import java.io.File;
9 | import java.io.IOException;
10 | import java.nio.file.FileVisitResult;
11 | import java.nio.file.Files;
12 | import java.nio.file.Path;
13 | import java.nio.file.SimpleFileVisitor;
14 | import java.nio.file.attribute.BasicFileAttributes;
15 | import java.util.*;
16 |
17 | /**
18 | * This class finds individual mgfs inside of child folders at the rootPath
19 | *
20 | * @author Davy
21 | */
22 | public class KennethFileWalker {
23 |
24 | static Path rootPath = null;
25 | static KennethFileWalkerImpl walker = new KennethFileWalkerImpl();
26 | static File outputFolder;
27 |
28 | public static void main(String[] args) {
29 | if (args.length == 0 || Objects.equals(args[0], "--help") || Objects.equals(args[0], "-h")) {
30 | System.out.println("first argument : root folder to walk\n second argument: list of comma separated peptides to look for");
31 | } else {
32 | rootPath = new File(args[0]).toPath();
33 | if (!rootPath.toFile().exists()) {
34 | System.err.println("root path does not exist");
35 | }
36 | for (String peptide : Arrays.asList(args[1].split(","))) {
37 | try {
38 | walkFiles(peptide);
39 | } catch (IOException ioe) {
40 | ioe.printStackTrace();
41 | }
42 | }
43 | }
44 | }
45 |
46 | static public void walkFiles(String peptide) throws IOException {
47 | if (rootPath == null) {
48 | throw new IOException("rootpath not set");
49 | }
50 | List filePath = new ArrayList();
51 | int counter = 0;
52 | StringBuilder builder = new StringBuilder("");
53 |
54 | char[] pepChars = peptide.toCharArray();
55 |
56 | for (Character pepChar : pepChars) {
57 |
58 | if (counter == 3) {
59 | filePath.add(builder.toString());
60 | builder = new StringBuilder();
61 | counter = 0;
62 | }
63 | builder.append(pepChar);
64 | counter++;
65 | }
66 | if (builder.length() != 0) {
67 | filePath.add(builder.toString());
68 | }
69 | walker.setPath(peptide, filePath);
70 | Files.walkFileTree(rootPath, walker);
71 | }
72 |
73 | static public class KennethFileWalkerImpl extends SimpleFileVisitor {
74 |
75 | Iterator localPath;
76 | String localPeptide = "";
77 | String fullPeptide = "";
78 |
79 | public void setPath(String peptide, List path) {
80 | fullPeptide = peptide;
81 | System.out.println(fullPeptide);
82 |
83 | localPath = path.iterator();
84 | System.out.println(localPath);
85 | }
86 |
87 | @Override
88 | public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs) throws IOException {
89 | localPeptide = localPath.next();
90 | return super.preVisitDirectory(dir, attrs);
91 | }
92 |
93 | @Override
94 | public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
95 | if (file.getFileName().toString().equals(localPeptide)) {
96 | return FileVisitResult.SKIP_SIBLINGS;
97 | } else if (attrs.isRegularFile() && file.getFileName().toString().equals(fullPeptide)) {
98 | System.out.println(file.toAbsolutePath().toString());
99 | return FileVisitResult.TERMINATE;
100 | } else {
101 | return FileVisitResult.SKIP_SUBTREE;
102 | }
103 | }
104 | }
105 | }
106 |
--------------------------------------------------------------------------------
/src/main/java/protein_spectrum_diversity/Parse.java:
--------------------------------------------------------------------------------
1 | /*
2 | * To change this license header, choose License Headers in Project Properties.
3 | * To change this template file, choose Tools | Templates
4 | * and open the template in the editor.
5 | */
6 | package protein_spectrum_diversity;
7 |
8 | import com.compomics.util.experiment.massspectrometry.MSnSpectrum;
9 | import com.compomics.util.experiment.massspectrometry.SpectrumFactory;
10 | import com.compomics.util.gui.waiting.waitinghandlers.WaitingHandlerCLIImpl;
11 | import java.io.BufferedWriter;
12 | import java.io.File;
13 | import java.io.FileWriter;
14 | import java.io.IOException;
15 | import java.nio.file.FileVisitResult;
16 | import java.nio.file.Files;
17 | import java.nio.file.Path;
18 | import java.nio.file.Paths;
19 | import java.nio.file.SimpleFileVisitor;
20 | import java.nio.file.attribute.BasicFileAttributes;
21 | import java.util.ArrayList;
22 | import java.util.List;
23 | import java.util.regex.Pattern;
24 | import uk.ac.ebi.jmzml.xml.io.MzMLUnmarshallerException;
25 |
26 | /**
27 | * This class finds individual mgf files in children folders of given rootFolder
28 | *
29 | * @author Sule
30 | */
31 | public class Parse {
32 |
33 | /**
34 | * @param args the command line arguments
35 | */
36 | public static void main(String[] args) throws IOException, MzMLUnmarshallerException {
37 | File rootFolder = new File(args[0]),
38 | outputFolder = new File(args[1]),
39 | info = new File(args[2]);
40 |
41 | SpectrumFactory fct = SpectrumFactory.getInstance();
42 |
43 | Path path = Paths.get(rootFolder.getAbsolutePath());
44 | final List files = new ArrayList();
45 | try {
46 | Files.walkFileTree(path, new SimpleFileVisitor() {
47 | @Override
48 | public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
49 | if (!attrs.isDirectory()) {
50 | files.add(file);
51 | }
52 | return FileVisitResult.CONTINUE;
53 | }
54 | });
55 | } catch (IOException e) {
56 | e.printStackTrace();
57 | }
58 | // to split by file separator
59 | String pattern = Pattern.quote(System.getProperty("file.separator"));
60 | BufferedWriter bw = null;
61 | BufferedWriter bw_all = new BufferedWriter(new FileWriter(info));
62 | for (Path p : files) {
63 | String mgfName = p.toAbsolutePath().toString();
64 | if (mgfName.endsWith(".mgf")) {
65 | File mgfFile = new File(mgfName);
66 | fct.addSpectra(mgfFile, new WaitingHandlerCLIImpl());
67 |
68 | String[] splittedFileName = mgfName.split(pattern);
69 |
70 | String spectrumTitle = splittedFileName[(splittedFileName.length - 1)];
71 | spectrumTitle = "H-" + spectrumTitle.substring(0, spectrumTitle.indexOf(".mgf")) + "-OH";
72 | bw = new BufferedWriter(new FileWriter(outputFolder + "//" + spectrumTitle + ".mgf"));
73 |
74 | System.out.println(spectrumTitle +"\t"+mgfName);
75 |
76 | MSnSpectrum spectrum = (MSnSpectrum) fct.getSpectrum(mgfFile.getName(), spectrumTitle);
77 | bw_all.write(spectrum.getSpectrumTitle() + "\t" + spectrum.getPrecursor().getPossibleChargesAsString() + "\t" + spectrumTitle + "\n");
78 | bw.write(spectrum.asMgf());
79 | bw.close();
80 | fct.clearFactory();
81 | }
82 | }
83 | bw_all.close();
84 | }
85 |
86 | }
87 |
--------------------------------------------------------------------------------
/src/main/java/util/CalculateMS1Err.java:
--------------------------------------------------------------------------------
1 | /*
2 | * To change this license header, choose License Headers in Project Properties.
3 | * To change this template file, choose Tools | Templates
4 | * and open the template in the editor.
5 | */
6 |
7 | package util;
8 |
9 |
10 | /**
11 | * To calculate ms1error for a selected MSnSpectrum
12 | *
13 | * @author Sule
14 | */
15 | public class CalculateMS1Err {
16 |
17 | /**
18 | * Calculations was explained here
19 | * http://genesis.ugent.be/files/costore/practicals/bioinformatics-for-proteomics/A-Answers/A-Answers.pdf (Answer 1.3e)
20 | * The calculated value is not an absolute value (is either negative or positive).
21 | *
22 | *
23 | * @param isPPM true: PPM based, false: Dalton based
24 | * @param theoreticalPrecursorMass - Theoretical precursor mass
25 | * @param measuredPrecusorMass - Observed mass
26 | * @return ms1err
27 | */
28 | public static double getMS1Err(boolean isPPM, double theoreticalPrecursorMass, double measuredPrecusorMass) {
29 | // System.out.println("isPPM="+isPPM+"\t and theorMass="+theoreticalPrecursorMass+"\t and measuredMass="+measuredPrecusorMass);
30 | double error = 0;
31 | if (isPPM) {
32 | // This PPM calculation was from bioinformatics-for-proteomics
33 | double diff = measuredPrecusorMass - theoreticalPrecursorMass;
34 | double ppm_error = (diff) / theoreticalPrecursorMass;
35 | ppm_error = ppm_error * 1000000;
36 | error = ppm_error;
37 | } else {
38 | double mz_error = theoreticalPrecursorMass - measuredPrecusorMass;
39 | error = mz_error;
40 | }
41 | return error;
42 | }
43 |
44 | }
45 |
--------------------------------------------------------------------------------
/src/main/java/util/MathsUtil.java:
--------------------------------------------------------------------------------
1 | /*
2 | * To change this template, choose Tools | Templates
3 | * and open the template in the editor.
4 | */
5 | package util;
6 |
7 | /**
8 | *
9 | * @author Sule
10 | */
11 | public class MathsUtil {
12 |
13 | /**
14 | * This method calculates logX of given value.
15 | *
16 | * @param x
17 | * @param base 2=LOG2, 4=LOG4 or 10=LOG10
18 | * @return logBase of given value
19 | */
20 | public static double log(double x, int base) {
21 | return ((double) Math.log(x) / (double) Math.log(base));
22 | }
23 |
24 | /**
25 | * This method calculate combinations for C(n,r).
26 | *
27 | * @param n
28 | * @param r
29 | * @return
30 | * @throws Exception
31 | */
32 |
33 | public static long calculateCombination(int n, int r) throws Exception {
34 | long score = 0;
35 | if (r == 0) {
36 | score = 1;
37 | }
38 | if (n >= r) {
39 | double upper = 1,
40 | lower = 1;
41 | for (int i = n; i > n - r; i--) {
42 | upper = upper * i;
43 | }
44 | for (int i = r; i > 1; i--) {
45 | lower = lower * i;
46 | }
47 | score = (long) (upper / lower);
48 | } else {
49 | throw new Exception("Error! n >= r");
50 | }
51 | return score;
52 |
53 | }
54 | }
55 |
--------------------------------------------------------------------------------
/src/main/log4j.properties:
--------------------------------------------------------------------------------
1 | #####################
2 | # Root Logging #
3 | #####################
4 |
5 | # Root Logger option
6 |
7 | log4j.rootLogger=INFO, file
8 |
9 | # Direct log messages to a log file
10 | log4j.appender.file=org.apache.log4j.RollingFileAppender
11 |
12 | # Redirect to Tomcat logs folder
13 | # log4j.appender.file.File=C:\\logigng.log
14 | #log4j.appender.file.File=G:/GAME/taenia.loging_all_runs.log
15 | log4j.appender.file.Append=true
16 |
17 | log4j.appender.file.MaxFileSize=100MB
18 | log4j.appender.file.MaxBackupIndex=3
19 | log4j.appender.file.layout=org.apache.log4j.PatternLayout
20 | log4j.appender.file.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n
21 |
22 |
23 | ###### direct log messages to stdout ###
24 | log4j.appender.stdout=org.apache.log4j.ConsoleAppender
25 | log4j.appender.stdout.Target=System.out
26 | log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
27 | log4j.appender.stdout.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n
28 |
29 |
--------------------------------------------------------------------------------
/src/main/resources/BookChapter.properties:
--------------------------------------------------------------------------------
1 | # Properties file to evaluate scoring functions, these defaults settings were used for the book chapter
2 |
3 | ## true: Analyze against theoretical spectrum; false: Analyze against experimental spectrum
4 | ## If it is true, go to the "THEORETICAL SPECTRUM COMPARISON", otherwise go to the "EXPERIMENTAL SPECTRUM COMPARISON"
5 | compareTheoreticals = true
6 |
7 | ######################################
8 | ### THEORETICAL SPECTRUM COMPARSON ###
9 | ######################################
10 |
11 | ## database name (already in silico digested by DBToolKit)
12 | database.name = C:/Users/Sule/Dropbox/paper_writing/book_chapter/materialsC/db/ups1-ups2_tax2261_crapwoups_insilico.fasta
13 | ## a folder containing all spectra (MGF files)
14 | spectra.name = C:/Users/Sule/Dropbox/paper_writing/book_chapter/materialsC/spectra/Orbi2_study6a_W080314_6QC1_sigma48_ft8_pc.mgf
15 | ## result file name
16 | output=C:/Users/Sule/Dropbox/paper_writing/book_chapter/materialsC/output/against_theoretical_spectrum/all_charged/test_theo_calculation_14122015_allCharged_mine.txt
17 |
18 | ## MS1 and MS2error values
19 | precursor.tolerance = 10
20 | fragment.tolerance = 0.5
21 | ## T: to generate theoretical ions with all possible charges; F: to generate theoretical ions up to doubly charged state
22 | hasAllPossCharge = T
23 |
24 | ## correctionFactor is inclusive, only for SEQUEST-like score.
25 | ## For example, correctionFactor=74 results in cross-correlation calculation of every integer within -75 result = instance.getFilteredPeaks();
91 | assertEquals(9, result.size());
92 | assertEquals(150.40, result.get(2).getMz());
93 | assertEquals(160.60, result.get(1).getMz());
94 | assertEquals(199.20, result.get(0).getMz());
95 | assertEquals(210.40, result.get(5).getMz());
96 | assertEquals(220.40, result.get(4).getMz());
97 | assertEquals(280.70, result.get(3).getMz());
98 | assertEquals(300.00, result.get(7).getMz());
99 | assertEquals(310.00, result.get(6).getMz());
100 | assertEquals(370.00, result.get(8).getMz());
101 |
102 |
103 | instance = new DivideAndTopNFilter(ms, 2);
104 | result = instance.getFilteredPeaks();
105 | assertEquals(6, result.size());
106 | assertEquals(160.60, result.get(1).getMz());
107 | assertEquals(199.20, result.get(0).getMz());
108 | assertEquals(220.40, result.get(3).getMz());
109 | assertEquals(280.70, result.get(2).getMz());
110 | assertEquals(300.00, result.get(5).getMz());
111 | assertEquals(310.00, result.get(4).getMz());
112 | }
113 | }
114 |
--------------------------------------------------------------------------------
/src/test/java/cal/cumulativeBinomialProbability/score/MSRobinTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * To change this license header, choose License Headers in Project Properties.
3 | * To change this template file, choose Tools | Templates
4 | * and open the template in the editor.
5 | */
6 | package cal.cumulativeBinomialProbability.score;
7 |
8 | import junit.framework.TestCase;
9 |
10 | /**
11 | *
12 | * @author Sule
13 | */
14 | public class MSRobinTest extends TestCase {
15 |
16 | public MSRobinTest(String testName) {
17 | super(testName);
18 | }
19 |
20 | @Override
21 | protected void setUp() throws Exception {
22 | super.setUp();
23 | }
24 |
25 | @Override
26 | protected void tearDown() throws Exception {
27 | super.tearDown();
28 | }
29 |
30 | /**
31 | * Test of calculateScore method, of class MSRobin.
32 | */
33 | public void testCalculateScore() {
34 | System.out.println("calculateScore");
35 | double probability = 0.01,
36 | intensity_part = 0.5;
37 | int N = 20,
38 | n = 3;
39 | MSRobin instance = new MSRobin(probability, N, n, intensity_part, 0);
40 | instance.calculateScore();
41 | assertEquals(21.20, instance.getScore(), 0.01);
42 |
43 | probability = 0.1;
44 | intensity_part = 0.78;
45 | N = 20;
46 | n = 8;
47 | instance = new MSRobin(probability, N, n, intensity_part, 0);
48 | instance.calculateScore();
49 | assertEquals(29.86, instance.getScore(), 0.01);
50 |
51 | N = 20;
52 | n = 3;
53 | probability = 0.01;
54 | intensity_part = 0.5;
55 | instance = new MSRobin(probability, N, n, intensity_part, 1);
56 | instance.calculateScore();
57 | assertEquals(14.99, instance.getScore(), 0.01);
58 |
59 | probability = 0.1;
60 | intensity_part = 0.78;
61 | N = 20;
62 | n = 8;
63 | instance = new MSRobin(probability, N, n, intensity_part, 1);
64 | instance.calculateScore();
65 | assertEquals(26.37, instance.getScore(), 0.01);
66 |
67 | }
68 |
69 | }
70 |
--------------------------------------------------------------------------------
/src/test/java/cal/cumulativeBinomialProbability/spectra/CompareAndScoreTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * To change this license header, choose License Headers in Project Properties.
3 | * To change this template file, choose Tools | Templates
4 | * and open the template in the editor.
5 | */
6 | package cal.cumulativeBinomialProbability.spectra;
7 |
8 | import com.compomics.util.experiment.massspectrometry.MSnSpectrum;
9 | import com.compomics.util.experiment.massspectrometry.SpectrumFactory;
10 | import java.io.File;
11 | import java.io.FileNotFoundException;
12 | import java.io.IOException;
13 | import junit.framework.TestCase;
14 | import uk.ac.ebi.jmzml.xml.io.MzMLUnmarshallerException;
15 |
16 | /**
17 | *
18 | * @author Sule
19 | */
20 | public class CompareAndScoreTest extends TestCase {
21 |
22 | public CompareAndScoreTest(String testName) {
23 | super(testName);
24 | }
25 |
26 | @Override
27 | protected void setUp() throws Exception {
28 | super.setUp();
29 | }
30 |
31 | @Override
32 | protected void tearDown() throws Exception {
33 | super.tearDown();
34 | }
35 |
36 |
37 | /**
38 | * Test of getMSRobinScore method, of class CompareAndScore.
39 | */
40 | public void testGetMSRobinScore() throws IOException, MzMLUnmarshallerException, FileNotFoundException, ClassNotFoundException, Exception {
41 | System.out.println("getMSRobinScore");
42 | String expMGFFolder = "TestingData\\Scoring/";
43 | MSnSpectrum specA = null,
44 | specB = null;
45 |
46 | for (File mgf : new File(expMGFFolder).listFiles()) {
47 | if (mgf.getName().equals("specA.mgf")) {
48 | System.out.println(mgf.getName());
49 | SpectrumFactory fct = SpectrumFactory.getInstance();
50 | fct.addSpectra(mgf);
51 | for (String title2 : fct.getSpectrumTitles(mgf.getName())) {
52 | System.out.println(title2);
53 | specA = (MSnSpectrum) fct.getSpectrum(mgf.getName(), title2);
54 |
55 | }
56 | } else if (mgf.getName().equals("specB.mgf")) {
57 | System.out.println(mgf.getName());
58 | SpectrumFactory fct = SpectrumFactory.getInstance();
59 | fct.addSpectra(mgf);
60 | for (String title2 : fct.getSpectrumTitles(mgf.getName())) {
61 | System.out.println(title2);
62 | specB = (MSnSpectrum) fct.getSpectrum(mgf.getName(), title2);
63 | }
64 | }
65 | }
66 | CompareAndScore instance = new CompareAndScore(specA, specB, 0.5, 0, 0);
67 | System.out.println("Result=" + instance.getMSRobinScore());
68 | double expResult = 0.8;
69 | double result = instance.getMSRobinScore();
70 | assertEquals(expResult, result, 0.1);
71 |
72 | instance = new CompareAndScore(specA, specB, 0.5, 1,0);
73 | expResult = 0.22;
74 | result = instance.getMSRobinScore();
75 | assertEquals(expResult, result, 0.1);
76 |
77 | }
78 |
79 | }
80 |
--------------------------------------------------------------------------------
/src/test/java/spectra/preprocess/filter/implementation/DiscardLowIntensePeaksTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * To change this license header, choose License Headers in Project Properties.
3 | * To change this template file, choose Tools | Templates
4 | * and open the template in the editor.
5 | */
6 | package spectra.preprocess.filter.implementation;
7 |
8 | import preprocess.filter.noise.implementation.DiscardLowIntensePeaks;
9 | import com.compomics.util.experiment.massspectrometry.MSnSpectrum;
10 | import com.compomics.util.experiment.massspectrometry.Peak;
11 | import com.compomics.util.experiment.massspectrometry.SpectrumFactory;
12 | import java.io.File;
13 | import java.io.FileNotFoundException;
14 | import java.io.IOException;
15 | import java.util.ArrayList;
16 | import java.util.Collections;
17 | import junit.framework.TestCase;
18 | import uk.ac.ebi.jmzml.xml.io.MzMLUnmarshallerException;
19 |
20 | /**
21 | *
22 | * @author Sule
23 | */
24 | public class DiscardLowIntensePeaksTest extends TestCase {
25 |
26 | public DiscardLowIntensePeaksTest(String testName) {
27 | super(testName);
28 | }
29 |
30 | @Override
31 | protected void setUp() throws Exception {
32 | super.setUp();
33 | }
34 |
35 | @Override
36 | protected void tearDown() throws Exception {
37 | super.tearDown();
38 | }
39 |
40 | /**
41 | * Test of noiseFilter method, of class DiscardLowIntensePeaks.
42 | */
43 | public void testNoiseFilter() throws IOException, FileNotFoundException, ClassNotFoundException, MzMLUnmarshallerException {
44 | System.out.println("noiseFilter");
45 | File testFileFolder = new File("C:\\Users\\Sule\\Documents\\NetBeansProjects\\TapeWormAnalysis\\TestingData\\NoiseFiltering");
46 | for (File testFile : testFileFolder.listFiles()) {
47 | if (testFile.getName().endsWith(".mgf")) {
48 | SpectrumFactory fct = SpectrumFactory.getInstance();
49 | fct.addSpectra(testFile);
50 | System.out.println(testFile.getName());
51 | for (String title : fct.getSpectrumTitles(testFile.getName())) {
52 | MSnSpectrum ms = (MSnSpectrum) fct.getSpectrum(testFile.getName(), title);
53 |
54 | DiscardLowIntensePeaks instance = new DiscardLowIntensePeaks(5);
55 | MSnSpectrum result = instance.noiseFilter(ms);
56 |
57 | assertEquals(59, ms.getPeakList().size());
58 |
59 | ArrayList actualPeaks = new ArrayList(result.getPeakList());
60 | Collections.sort(actualPeaks, Peak.AscendingMzComparator);
61 |
62 | assertEquals(actualPeaks.get(0).getMz(), 129.0795898, 0);
63 | assertEquals(actualPeaks.get(1).getMz(), 130.1602173, 0);
64 | assertEquals(actualPeaks.get(9).getMz(), 232.1122437, 0);
65 | assertEquals(actualPeaks.get(14).getMz(), 258.8475342, 0);
66 | assertEquals(actualPeaks.get(16).getMz(), 263.7848511, 0);
67 |
68 | assertEquals(actualPeaks.get(0).getIntensity(), 29.98080826, 0);
69 | assertEquals(actualPeaks.get(1).getIntensity(), 33.76114655, 0);
70 | assertEquals(actualPeaks.get(9).getIntensity(), 38.57017899, 0);
71 | assertEquals(actualPeaks.get(14).getIntensity(), 26.63854218, 0);
72 | assertEquals(actualPeaks.get(16).getIntensity(), 13.93132687, 0);
73 | }
74 | }
75 | }
76 | }
77 |
78 | }
79 |
--------------------------------------------------------------------------------
/src/test/java/spectra/preprocess/filter/implementation/TopNFilteringTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * To change this license header, choose License Headers in Project Properties.
3 | * To change this template file, choose Tools | Templates
4 | * and open the template in the editor.
5 | */
6 |
7 | package spectra.preprocess.filter.implementation;
8 |
9 | import preprocess.filter.noise.implementation.TopNFiltering;
10 | import com.compomics.util.experiment.massspectrometry.MSnSpectrum;
11 | import com.compomics.util.experiment.massspectrometry.Peak;
12 | import com.compomics.util.experiment.massspectrometry.SpectrumFactory;
13 | import java.io.File;
14 | import java.io.FileNotFoundException;
15 | import java.io.IOException;
16 | import java.util.ArrayList;
17 | import java.util.Collections;
18 | import static junit.framework.Assert.assertEquals;
19 | import junit.framework.TestCase;
20 | import uk.ac.ebi.jmzml.xml.io.MzMLUnmarshallerException;
21 |
22 | /**
23 | *
24 | * @author Sule
25 | */
26 | public class TopNFilteringTest extends TestCase {
27 |
28 | public TopNFilteringTest(String testName) {
29 | super(testName);
30 | }
31 |
32 | @Override
33 | protected void setUp() throws Exception {
34 | super.setUp();
35 | }
36 |
37 | @Override
38 | protected void tearDown() throws Exception {
39 | super.tearDown();
40 | }
41 |
42 | /**
43 | * Test of noiseFilter method, of class TopNFiltering.
44 | */
45 | public void testNoiseFilter() throws IOException, FileNotFoundException, ClassNotFoundException, MzMLUnmarshallerException {
46 | System.out.println("noiseFilter");
47 | File testFileFolder = new File("C:\\Users\\Sule\\Documents\\NetBeansProjects\\TapeWormAnalysis\\TestingData\\NoiseFiltering");
48 | for (File testFile : testFileFolder.listFiles()) {
49 | if (testFile.getName().endsWith(".mgf")) {
50 | SpectrumFactory fct = SpectrumFactory.getInstance();
51 | fct.addSpectra(testFile);
52 | System.out.println(testFile.getName());
53 | for (String title : fct.getSpectrumTitles(testFile.getName())) {
54 | MSnSpectrum ms = (MSnSpectrum) fct.getSpectrum(testFile.getName(), title);
55 |
56 | TopNFiltering instance = new TopNFiltering(50);
57 | MSnSpectrum result = instance.noiseFilter(ms);
58 |
59 | assertEquals(50, ms.getPeakList().size());
60 |
61 | ArrayList actualPeaks = new ArrayList(result.getPeakList());
62 | Collections.sort(actualPeaks, Peak.AscendingMzComparator);
63 |
64 | assertEquals(actualPeaks.get(0).getMz(), 129.0795898, 0);
65 | assertEquals(actualPeaks.get(1).getMz(), 130.1602173, 0);
66 | assertEquals(actualPeaks.get(9).getMz(), 234.1070557, 0);
67 | assertEquals(actualPeaks.get(14).getMz(), 271.7967529, 0);
68 | assertEquals(actualPeaks.get(16).getMz(), 277.8079529, 0);
69 | assertEquals(actualPeaks.get(48).getMz(), 571.2167358, 0);
70 | assertEquals(actualPeaks.get(49).getMz(), 572.0350342, 0);
71 |
72 | assertEquals(actualPeaks.get(0).getIntensity(), 29.98080826, 0);
73 | assertEquals(actualPeaks.get(1).getIntensity(), 33.76114655, 0);
74 | assertEquals(actualPeaks.get(9).getIntensity(), 44.92469406, 0);
75 | assertEquals(actualPeaks.get(14).getIntensity(), 21.06731224, 0);
76 | assertEquals(actualPeaks.get(16).getIntensity(), 17.09956741, 0);
77 | assertEquals(actualPeaks.get(48).getIntensity(), 44.12823486, 0);
78 | assertEquals(actualPeaks.get(49).getIntensity(), 25.19287109, 0);
79 |
80 | instance = new TopNFiltering(40);
81 | instance.noiseFilter(ms);
82 | assertEquals(40, ms.getPeakList().size());
83 |
84 | }
85 | }
86 | }
87 | }
88 |
89 | }
90 |
--------------------------------------------------------------------------------
/src/test/java/spectra/preprocess/filter/noise/implementation/DivideAndNormalizeTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * To change this license header, choose License Headers in Project Properties.
3 | * To change this template file, choose Tools | Templates
4 | * and open the template in the editor.
5 | */
6 | package spectra.preprocess.filter.noise.implementation;
7 |
8 | import com.compomics.util.experiment.massspectrometry.MSnSpectrum;
9 | import com.compomics.util.experiment.massspectrometry.Peak;
10 | import com.compomics.util.experiment.massspectrometry.SpectrumFactory;
11 | import com.compomics.util.gui.waiting.waitinghandlers.WaitingHandlerCLIImpl;
12 | import java.io.File;
13 | import java.io.IOException;
14 | import java.util.ArrayList;
15 | import java.util.Collections;
16 | import junit.framework.TestCase;
17 | import preprocess.filter.noise.implementation.DivideAndNormalize;
18 | import uk.ac.ebi.jmzml.xml.io.MzMLUnmarshallerException;
19 |
20 | /**
21 | *
22 | * @author Sule
23 | */
24 | public class DivideAndNormalizeTest extends TestCase {
25 |
26 | public DivideAndNormalizeTest(String testName) {
27 | super(testName);
28 | }
29 |
30 | @Override
31 | protected void setUp() throws Exception {
32 | super.setUp();
33 | }
34 |
35 | @Override
36 | protected void tearDown() throws Exception {
37 | super.tearDown();
38 | }
39 |
40 | /**
41 | * Test of getIntervals method, of class DivideAndNormalize.
42 | */
43 | public void testGetIntervals() throws IOException, MzMLUnmarshallerException {
44 | MSnSpectrum ms = null;
45 | String mgfFileName = "C:\\Users\\Sule\\Desktop\\BOOK_CHAPTER\\mgf/TEST_BESTANDROMEDA_FORSEQUEST.mgf";
46 | SpectrumFactory fct = SpectrumFactory.getInstance();
47 | File f = new File(mgfFileName);
48 | if (mgfFileName.endsWith(".mgf")) {
49 | fct.addSpectra(f, new WaitingHandlerCLIImpl());
50 | for (String title : fct.getSpectrumTitles(f.getName())) {
51 | System.out.println(title);
52 | ms = (MSnSpectrum) fct.getSpectrum(f.getName(), title);
53 |
54 | }
55 | }
56 | int intervals = 10;
57 | double normalize_value = 50;
58 | DivideAndNormalize instance = new DivideAndNormalize(ms, intervals, normalize_value);
59 |
60 | System.out.println("getIntervals");
61 | int expResult = 10;
62 | int result = instance.getIntervals();
63 | assertEquals(expResult, result);
64 | }
65 |
66 | /**
67 | * Test of getNormalize_value method, of class DivideAndNormalize.
68 | */
69 | public void testGetNormalize_value() throws IOException, MzMLUnmarshallerException {
70 |
71 | MSnSpectrum ms = null;
72 | String mgfFileName = "C:\\Users\\Sule\\Desktop\\BOOK_CHAPTER\\mgf/TEST_BESTANDROMEDA_FORSEQUEST.mgf";
73 | SpectrumFactory fct = SpectrumFactory.getInstance();
74 | File f = new File(mgfFileName);
75 | if (mgfFileName.endsWith(".mgf")) {
76 | fct.addSpectra(f, new WaitingHandlerCLIImpl());
77 | for (String title : fct.getSpectrumTitles(f.getName())) {
78 | System.out.println(title);
79 | ms = (MSnSpectrum) fct.getSpectrum(f.getName(), title);
80 |
81 | }
82 | }
83 | int intervals = 10;
84 | double normalize_value = 50;
85 | DivideAndNormalize instance = new DivideAndNormalize(ms, intervals, normalize_value);
86 |
87 | System.out.println("getNormalize_value");
88 | double expResult = 50.0;
89 | double result = instance.getNormalize_value();
90 | assertEquals(expResult, result, 0.0);
91 | }
92 |
93 | /**
94 | * Test of process method, of class DivideAndNormalize.
95 | */
96 | public void testProcess() throws IOException, MzMLUnmarshallerException {
97 |
98 | MSnSpectrum ms = null;
99 | String mgfFileName = "C:\\Users\\Sule\\Desktop\\BOOK_CHAPTER\\mgf/TEST_BESTANDROMEDA_FORSEQUEST.mgf";
100 | SpectrumFactory fct = SpectrumFactory.getInstance();
101 | File f = new File(mgfFileName);
102 | if (mgfFileName.endsWith(".mgf")) {
103 | fct.addSpectra(f, new WaitingHandlerCLIImpl());
104 | for (String title : fct.getSpectrumTitles(f.getName())) {
105 | System.out.println(title);
106 | ms = (MSnSpectrum) fct.getSpectrum(f.getName(), title);
107 |
108 | }
109 | }
110 | System.out.println("process");
111 | int intervals = 10;
112 | double normalize_value = 50;
113 | DivideAndNormalize instance = new DivideAndNormalize(ms, intervals, normalize_value);
114 | instance.process();
115 | ArrayList filteredPeaks = instance.getFilteredPeaks();
116 | Collections.sort(filteredPeaks, Peak.AscendingMzComparator);
117 | for (Peak p : filteredPeaks) {
118 | System.out.println(p.mz + "\t" + p.intensity);
119 | }
120 |
121 | assertEquals(230, instance.getFilteredPeaks().size());
122 | assertEquals(10.35374064, instance.getFilteredPeaks().get(0).intensity, 0.01);
123 | assertEquals(2.6534, instance.getFilteredPeaks().get(1).intensity, 0.01);
124 | assertEquals(20.953, instance.getFilteredPeaks().get(2).intensity, 0.01);
125 | assertEquals(5.443, instance.getFilteredPeaks().get(3).intensity, 0.01);
126 | assertEquals(1.326, instance.getFilteredPeaks().get(4).intensity, 0.01);
127 | assertEquals(0.210866598, instance.getFilteredPeaks().get(58).intensity, 0.01);
128 | assertEquals(0.24175793, instance.getFilteredPeaks().get(35).intensity, 0.01);
129 | assertEquals(3.340702851, instance.getFilteredPeaks().get(99).intensity, 0.01);
130 | assertEquals(5.223916995, instance.getFilteredPeaks().get(183).intensity, 0.01);
131 | assertEquals(0.070, instance.getFilteredPeaks().get(197).intensity, 0.01);
132 | assertEquals(7.0549, instance.getFilteredPeaks().get(209).intensity, 0.01);
133 | assertEquals(50, instance.getFilteredPeaks().get(229).intensity, 0.01);
134 | }
135 |
136 | }
137 |
--------------------------------------------------------------------------------
/src/test/java/spectra/preprocess/filter/precursor/RemoveWindowAroundTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * To change this license header, choose License Headers in Project Properties.
3 | * To change this template file, choose Tools | Templates
4 | * and open the template in the editor.
5 | */
6 | package spectra.preprocess.filter.precursor;
7 |
8 | import com.compomics.util.experiment.massspectrometry.MSnSpectrum;
9 | import com.compomics.util.experiment.massspectrometry.SpectrumFactory;
10 | import com.compomics.util.gui.waiting.waitinghandlers.WaitingHandlerCLIImpl;
11 | import java.io.File;
12 | import java.io.IOException;
13 | import junit.framework.TestCase;
14 | import preprocess.filter.precursor.RemoveWindowAround;
15 | import uk.ac.ebi.jmzml.xml.io.MzMLUnmarshallerException;
16 |
17 | /**
18 | *
19 | * @author Sule
20 | */
21 | public class RemoveWindowAroundTest extends TestCase {
22 |
23 | public RemoveWindowAroundTest(String testName) {
24 | super(testName);
25 | }
26 |
27 | @Override
28 | protected void setUp() throws Exception {
29 | super.setUp();
30 | }
31 |
32 | @Override
33 | protected void tearDown() throws Exception {
34 | super.tearDown();
35 | }
36 |
37 | /**
38 | * Test of removePrecursor method, of class RemoveWindowAround.
39 | */
40 | public void testRemovePrecursor() throws IOException, MzMLUnmarshallerException {
41 | MSnSpectrum ms = null;
42 | String mgfFileName = "C:\\Users\\Sule\\Desktop\\BOOK_CHAPTER\\mgf/TEST_BESTANDROMEDA_FORSEQUEST.mgf";
43 | SpectrumFactory fct = SpectrumFactory.getInstance();
44 | File f = new File(mgfFileName);
45 | if (mgfFileName.endsWith(".mgf")) {
46 | fct.addSpectra(f, new WaitingHandlerCLIImpl());
47 | for (String title : fct.getSpectrumTitles(f.getName())) {
48 | System.out.println(title);
49 | ms = (MSnSpectrum) fct.getSpectrum(f.getName(), title);
50 | }
51 | }
52 | System.out.println("removePrecursor");
53 | RemoveWindowAround instance = new RemoveWindowAround(ms, 0.5);
54 | instance.removePrecursor();
55 | assertEquals(229, ms.getPeakMap().size());
56 | }
57 |
58 | }
59 |
--------------------------------------------------------------------------------
/src/test/java/spectra/preprocess/precursor/PrecursorPeakRemovalTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * To change this license header, choose License Headers in Project Properties.
3 | * To change this template file, choose Tools | Templates
4 | * and open the template in the editor.
5 | */
6 | package spectra.preprocess.precursor;
7 |
8 | import preprocess.filter.precursor.RemovePrecursorRelatedPeaks;
9 | import com.compomics.util.experiment.massspectrometry.MSnSpectrum;
10 | import com.compomics.util.experiment.massspectrometry.Peak;
11 | import com.compomics.util.experiment.massspectrometry.SpectrumFactory;
12 | import java.io.File;
13 | import java.io.FileNotFoundException;
14 | import java.io.IOException;
15 | import java.util.ArrayList;
16 | import java.util.Collections;
17 | import junit.framework.TestCase;
18 | import uk.ac.ebi.jmzml.xml.io.MzMLUnmarshallerException;
19 |
20 | /**
21 | *
22 | * @author Sule
23 | */
24 | public class PrecursorPeakRemovalTest extends TestCase {
25 |
26 | public PrecursorPeakRemovalTest(String testName) {
27 | super(testName);
28 | }
29 |
30 | @Override
31 | protected void setUp() throws Exception {
32 | super.setUp();
33 | }
34 |
35 | @Override
36 | protected void tearDown() throws Exception {
37 | super.tearDown();
38 | }
39 |
40 | /**
41 | * Test of removePrecursor method, of class RemovePrecursorRelatedPeaks.
42 | */
43 | public void testRemovePrecursor() throws IOException, FileNotFoundException, ClassNotFoundException, MzMLUnmarshallerException {
44 | System.out.println("removePrecursor");
45 | File testFileFolder = new File("C:\\Users\\Sule\\Documents\\NetBeansProjects\\TapeWormAnalysis\\TestingData\\PrecursorPeakRemoval");
46 | for (File testFile : testFileFolder.listFiles()) {
47 | if (testFile.getName().endsWith(".mgf")) {
48 | SpectrumFactory fct = SpectrumFactory.getInstance();
49 | fct.addSpectra(testFile);
50 | System.out.println(testFile.getName());
51 | for (String title : fct.getSpectrumTitles(testFile.getName())) {
52 | MSnSpectrum ms = (MSnSpectrum) fct.getSpectrum(testFile.getName(), title);
53 | assertEquals(84, ms.getPeakList().size());
54 |
55 | ArrayList tmpPeaks = new ArrayList(ms.getPeakList());
56 | Collections.sort(tmpPeaks, Peak.AscendingMzComparator);
57 | assertEquals(tmpPeaks.get(37).getMz(), 436.441101, 0.01);
58 | assertEquals(tmpPeaks.get(54).getMz(), 581.136267, 0.01);
59 | assertEquals(tmpPeaks.get(83).getMz(),871.1807631, 0.01);
60 |
61 | RemovePrecursorRelatedPeaks instance = new RemovePrecursorRelatedPeaks(ms, 0.5);
62 | instance.removePrecursor();
63 | assertEquals(81, ms.getPeakList().size());
64 |
65 | ArrayList actualPeaks = new ArrayList(ms.getPeakList());
66 | Collections.sort(actualPeaks, Peak.AscendingMzComparator);
67 | assertEquals(actualPeaks.get(37).getMz(), 437.388, 0.01);
68 | assertEquals(actualPeaks.get(53).getMz(), 599.5991, 0.01);
69 | assertEquals(actualPeaks.get(actualPeaks.size() - 1).getMz(), 849.78491, 0.01);
70 | }
71 | }
72 | }
73 | }
74 |
75 | }
76 |
--------------------------------------------------------------------------------