Usage And Examples


This library was developed as a tool for the large scale analysis of all data inside one or more complex Mascot MS/MS datfiles for a variety of purposes.

The main functionality consists of retrieving a Mascot datfile from multiple sources (a harddisk, database or MascotServer URL) and transforming into a functional object model.

A MascotDatfile instance captures all the data from PeptideHits and Queries into easy accessible objects. Standard methods are integrated into the objects to analyse small details like:

  • threshold calculation of an MS/MS spectrum versus ionscore of a peptide identification
  • sequence coverage of a peptide identification in a MS/MS spectrum
  • processing of modified aminoacid residues on peptide identifications
  • processing of MS/MS spectra
  • etc ..

In summary, this library makes the raw data inside Mascot datfiles easily accessible for research purposes.

The library was written by Kenny Helsens ( and you can contact the author for any questions concerning this library.

Also feel free to contact the developers if you have suggestions/enhancements/comments to library.

Go to top of page

How to parse the peptide hits


$ java -jar mascotdatfile-X.Y.Z.jar
	SimpleParser arguments:	 <alpha> <output> <input 1> [<input 2> <input 3> ... <input n>]
	Input Structure:
	<alpha> 	 alpha=0.05 reports peptide hits above 95% probability threshold
	<output> 	 output file
	<input> 	 one or more MascotDatfile input files

	Output structure:
	<MascotDatfile> <query number> <spectrum title> <charge state> <peptide> <peptide+PTM> <ionscore> <rank>

Example usage

$ java -jar mascotdatfile-X.Y.Z.jar 0.05 /tmp/test_peptidehitparser.txt /tmp/mascot/results/directory/F004071.dat

	Processing /tmp/mascot/results/directory/F004071.dat
	Successfully parsed 77 PSMs from 56 (1000) Queries above alpha 0.05

Example output



If you want to include -ALL- the PeptideHits, then set alpha to ‘100000000’ which will produce a negative confidence threshold. As the IonScore is by definition positive, all PeptideHits will be included.

Go to top of page

Running the SpectrumViewer graphical user interface (GUI)

$ java -cp mascotdatfile-X.Y.Z.jar com.compomics.mascotdatfile.research.tool.spectrumviewer.spectrumviewer_gui.Spectrumviewer_gui

Go to top of page

Using MascotDatfile as a Maven dependency

MascotDatfile is hosted at our public maven repository. Add the following code into your pom.xml file:


        <!-- Compomics Genesis Maven 2 repository -->
            <name>Genesis maven2 repository</name>
        <!-- old EBI repository -->
            <name>The EBI internal repository</name>

        <!-- EBI repository -->
            <name>EBI Nexus Repository</name>



Update the version number (X.Y.Z) to latest released version.

Note that the repository can be manually accessed to download the src or javadocs.

Go to top of page

Example code

public class ExampleWiki1 {
    public ExampleWiki1(String aFileName) {

        String file = aFileName;

        // Define the separator
        char separator = ',';

        // Ready to go!
        MascotDatfileInf iMascotDatfile = null;

        // log the status.
        System.out.println("Processing " + file);

        // Create a new MascotDatfile instance for each filename in the Input array.
        iMascotDatfile = MascotDatfileFactory.create(file, MascotDatfileType.MEMORY);

        // Fetch the QueryToPeptideMap. This indexes all queries.
        // From 1 to n number of spectra in the corresponding datfile.

        QueryToPeptideMapInf lQueryToPeptideMap = iMascotDatfile.getQueryToPeptideMap();
        // Also explore other methods on the QueryToPeptideMap!!!

        ArrayList list = null;

        // This Vector retrieves the best PeptideHit for each Query.
        // The Vector is zero based.
        // ex: Vector[0] contains the peptidehit of Query 1, etc.
        Vector lBestPeptideHits = lQueryToPeptideMap.getAllPeptideHitsAboveIdentityThreshold();

        // A - Iterate over all ProteinIDs
        Iterator iter = iMascotDatfile.getProteinMap().getProteinIDIterator();
        ProteinID lProteinID = null;
        while (iter.hasNext()) {
            String item = "";

            String lAccession =;
            lProteinID = iMascotDatfile.getProteinMap().getProteinID(lAccession);

            // Collect information for current protein.
            item = "PROTEIN" + separator
                    + lAccession + separator
                    + lProteinID.getQueryNumbers().length + separator
                    + lProteinID.getDescription();

            // Print to system outputstream

        // B - Iterate over all PeptideHits.
        for (int j = 0; j < lBestPeptideHits.size(); j++) {
            PeptideHit lPeptideHit = (PeptideHit) lBestPeptideHits.elementAt(j);
            // CSV output array.

            if (lPeptideHit != null) {
                // 1. MS/MS Spectrum filename.
                // 2. Modified PeptideSequence
                // 3. IonScore
                // 4. 95% Identity Threshold
                // 5. Number of ProteinHits
                // 6a. Protein i accession
                // 6b. Protein i description
                // etc. for n proteins.

                // As a Peptide can come from multiple proteins, it can have multiple proteinhits.
                ArrayList lProteins = lPeptideHit.getProteinHits();

                for (int k = 0; k < lProteins.size(); k++) {
                    list = new ArrayList();

                    ProteinHit lProteinHit = (ProteinHit) lProteins.get(k);
                    String lAccession = lProteinHit.getAccession();
                    // The protein description come from another part of the Mascot Result file.
                    // The ProteinMap also keeps track how many peptides refer to a Protein, mind that protein inference is not regarded at all!
                    // 6a.

                    // 1.
                    list.add(((Query) iMascotDatfile.getQueryList().get(j)).getFilename());

                    // 2.

                    // 3.

                    // 4.

                    String lResult = "";
                    for (Object item : list) {
                        lResult = lResult + item + separator;




    public static void main(String[] args) {
        new ExampleWiki1("/home/myfolder/mydatfile.dat");

Go to top of page