Matrix Science header

resfile_info.java

Example program for retrieving general search information.

/*
##############################################################################
# file: resfile_info.java                                                    #
# 'msparser' toolkit                                                         #
# Test harness / example code                                                #
##############################################################################
# COPYRIGHT NOTICE                                                           #
# Copyright 1998-2003 Matrix Science Limited  All Rights Reserved.           #
#                                                                            #
##############################################################################
#    $Archive:: /MowseBranches/ms_mascotresfile_1.2/test_java/test_searchi $ #
#     $Author: villek@matrixscience.com $ #
#       $Date: 2018-07-30 16:23:53 +0100 $ #
#   $Revision: 1b450440f9c97e1e41d0fc6016a27d68951d4532 | MSPARSER_REL_2_8_1-0-gea32989045 $ #
# $NoKeywords::                                                            $ #
##############################################################################
*/

import java.util.Date;
import matrix_science.msparser.*;

public class resfile_info {
    static {
        try {
            System.loadLibrary("msparserj");
        } catch (UnsatisfiedLinkError e) {
            System.err.println("Native code library failed to load. "
                               + "Is msparserj.dll on the path?\n" + e);
            System.exit(0);
        }
    }

    public static void main(String argv[]) 
    {
        // ----- Object creation -----
        if(argv.length < 1) {
            System.out.println("Must specify results filename as parameter");
            System.exit(0);
        }

        ms_mascotresfile file = new ms_mascotresfile(argv[0], 0, "");
        if (file.isValid()) {
            searchInformation(file);
        } else {
            System.out.println("Error number: "+file.getLastError());
            System.out.println("Error string: "+file.getLastErrorString());
            System.exit(0);
        }
    }
  
      
  
    private static void searchInformation(ms_mascotresfile file) {
        Date searchDate = null;                       // Java.util.date object
        int seconds = file.getDate();                 // get date of search in seconds since midnight GMT Jan 1st 1970
        long milliseconds = (long) seconds * 1000;    // convert to milliseconds
        searchDate=new Date(milliseconds);            // create the date object

        System.out.println("Search information from ms_mascotresfile");
        System.out.println("========================================");

        System.out.println("Number of queries   : "+file.getNumQueries());
        System.out.println("Number of hits      : "+file.getNumHits());
        System.out.println("Number of sequences : "+file.getNumSeqs());
        System.out.println("Sequences after tax : "+file.getNumSeqsAfterTax());
        System.out.println("Number of residues  : "+(int)file.getNumResidues());
        System.out.println("Execution time      : "+file.getExecTime());
        System.out.println("Date (seconds)      : "+file.getDate());


        // make java output identical to perl output
        System.out.print("Date                : "); 
        String toPerlDate = searchDate.toString();
        if(toPerlDate.indexOf("GMT ") > -1) {
            String beforeGMT = toPerlDate.substring(0,toPerlDate.indexOf("GMT"));
            String afterGMT = toPerlDate.substring(toPerlDate.indexOf("GMT ")+4,toPerlDate.length());
            System.out.println(beforeGMT+afterGMT);
        } else {
            System.out.println(searchDate);
        }

        System.out.println("Mascot version      : "+file.getMascotVer());
        System.out.println("Fasta version       : "+file.getFastaVer());
        // make java output identical to perl output

        System.out.println("Is PMF?             : "+toBinary(file.isPMF()));
        System.out.println("Is MSMS?            : "+toBinary(file.isMSMS()));
        System.out.println("Is SQ?              : "+toBinary(file.isSQ()));
        System.out.println("Is Error tolerant   : "+toBinary(file.isErrorTolerant()));
        System.out.println("Any PMF?            : "+toBinary(file.anyPMF()));
        System.out.println("Any MSMS?           : "+toBinary(file.anyMSMS()));
        System.out.println("Any SQ?             : "+toBinary(file.anySQ()));
        System.out.println("Any peptides section: "+toBinary(file.doesSectionExist(ms_mascotresfile.SEC_PEPTIDES)));
        System.out.println("Any peptide matches : "+toBinary(file.anyPeptideSummaryMatches()));
        System.out.println();
    }


    private static int toBinary(boolean bool) {
        if(bool) return 1;
        return 0;
    }
}

/*
will give the output: 



C:>java -classpath .;../java/msparser.jar resfile_info F981123.dat
Search information from ms_mascotresfile
========================================
Number of queries   : 4
Number of hits      : 50
Number of sequences : 820227
Sequences after tax : 820227
Number of residues  : 255696937
Execution time      : 14
Date (seconds)      : 1014568786
Date                : Sun Feb 24 16:39:46 2002
Mascot version      : 1.7.17
Fasta version       : MSDB_20020121.fasta
Is PMF?             : 0
Is MSMS?            : 1
Is SQ?              : 0
Is Error tolerant   : 0
Any PMF?            : 0
Any MSMS?           : 1
Any SQ?             : 0
Any peptides section: 1
Any peptide matches : 1


*/

Copyright © 2022 Matrix Science Ltd.  All Rights Reserved. Generated on Thu Mar 31 2022 01:12:29