org.ms2ms.io.PsmWriters.java Source code

Java tutorial

Introduction

Here is the source code for org.ms2ms.io.PsmWriters.java

Source

package org.ms2ms.io;

import com.google.common.collect.Multimap;
import org.expasy.mzjava.proteomics.ms.ident.PeptideMatch;
import org.expasy.mzjava.proteomics.ms.ident.SpectrumIdentifier;
import org.ms2ms.utils.Strs;
import org.ms2ms.utils.Tools;

import java.io.FileWriter;
import java.io.IOException;

/**
 * Created by yuw on 2/23/16.
 */
public class PsmWriters {
    // inputFile is the filename without mgf extension
    public static StringBuffer newNovorHeader(String inputFile) {
        StringBuffer buf = new StringBuffer();

        buf.append(":#=================== N-O-V-O-R ===================\n"
                + "#   NOVOR: Real-time Peptide de Novo Sequencing   \n" + "#              v1.03.0479 (stable)\n"
                + "#                 Trial License                   \n"
                + "#============== www.rapidnovor.org ===============\n" + "#\n"
                + "# This result file was generated by a trial license of Novor software at 2015-10-02 11:07:09\n"
                + "# which will expire on 2015-11-01\n\n");

        buf.append("# input file = " + inputFile + ".mgf\n");
        buf.append("# enzyme = Trypsin\n" + "# massAnalyzer = Trap\n" + "# fragmentIonErrorTol = 0.02Da\n"
                + "# precursorErrorTol = 15ppm\n" + "# fixedModifications = Carbamidomethyl (C)\n"
                + "# variableModifications = Oxidation (M)\n" + "# forbiddenResidues = I, U\n\n\n");

        return buf;
    }

    //  # id, scanNum, RT, mz(data), z, pepMass(denovo), err(data-denovo), ppm(1e6*err/(mz*z)), score, peptide, aaScore,
    //  1, 0, 1.1, 419.3200, 2, 836.5848, 0.0407, 48.5, 0.1, PLLLLLR, 1-1-1-1-1-1-32
    //  2, 0, 1.3, 596.7500, 4, 2383.0038, -0.0329, -13.8, 5.3, C(Cam)LC(Cam)MSSPDAWVSDRC(Cam)NRNR, 36-1-1-1-1-1-1-7-1-1-1-1-1-1-1-1-1-7-32
    //  3, 0, 7.6, 1550.4600, 3, 4648.6858, -0.3276, -70.4, 0.0, HGC(Cam)C(Cam)C(Cam)C(Cam)DYKKLFGENRM(O)HC(Cam)C(Cam)C(Cam)NFGQC(Cam)C(Cam)C(Cam)C(Cam)GVTYM(O)K, 3-1-3-1-1-1-1-2-1-1-1-1-1-1-1-1-1-1-1-2-2-2-1-1-1-1-1-1-1-2-1-1-1-9-4
    // TODO to be completed
    public static void writeNovor(String filename, Multimap<SpectrumIdentifier, PeptideMatch> id_match,
            String score, String input) throws IOException {
        if (!Tools.isSet(id_match) || !Strs.isSet(filename))
            return;

        System.out.print("Writing the PSMs to " + filename);

        FileWriter w = new FileWriter(filename);

        // write the header as required
        w.write(newNovorHeader(input).toString());

        int counts = 1;
        String delim = ", ";
        w.write("# id, scanNum, RT, mz(data), z, pepMass(denovo), err(data-denovo), ppm(1e6*err/(mz*z)), score, peptide, aaScore, \n");
        for (SpectrumIdentifier id : id_match.keySet()) {
            // only care about the run as indicated
            if (id.getSpectrum().indexOf(input) != 0)
                continue;

            for (PeptideMatch m : id_match.get(id)) {
                // let's fake an aaScore
                String aascore = null;
                for (int i = 0; i < m.size(); i++)
                    aascore = Strs.extend(aascore, "1", "-");

                w.write((counts++) + delim + id.getScanNumbers().getFirst().getValue() + delim
                        + (Tools.isSet(id.getRetentionTimes()) ? id.getRetentionTimes().getFirst().getTime() : 0)
                        + delim + id.getPrecursorMz().get() + delim + id.getAssumedCharge().get() + delim
                        + m.getNeutralPeptideMass() + delim + m.getMassDiff() + delim
                        + 1E6 * m.getMassDiff() / m.getNeutralPeptideMass() + delim + m.getScore(score) + delim
                        + m.toSymbolString() + delim + aascore + "\n");
            }
        }
        System.out.println(" --> " + counts);
        w.close();
    }
}