Matrix Science Mascot Parser toolkit
 
Loading...
Searching...
No Matches
create_mgf.cs

Create an mgf file from a Mascot results file.

/*
##############################################################################
# file: create_mgf.cs #
# 'msparser' toolkit example code #
##############################################################################
# COPYRIGHT NOTICE #
# Copyright 1998-2015 Matrix Science Limited All Rights Reserved. #
# #
##############################################################################
# $Source: parser/examples/test_csharp/create_mgf.cs $ #
# $Author: robertog@matrixscience.com $ #
# $Date: 2024-09-04 10:23:46 +0100 $ #
# $Revision: 526921a73137894bb1eae0b0fc8ccb4bb52ea662 | MSPARSER_REL_3_0_0-2024-09-24-0-g93ebaeb4f4 $ #
# $NoKeywords:: $ #
##############################################################################
*/
using System;
using System.IO;
using matrix_science.msparser;
namespace MsParserExamples
{
public class create_mgf
{
public static void Main(string[] argv)
{
if (argv.Length < 1)
{
usage();
return;
}
createMGF(argv[0]);
}
private static void createMGF(string filename)
{
ms_mascotresfilebase resfile = ms_mascotresfilebase.createResfile(filename);
if (!resfile.isValid())
{
Console.WriteLine("Cannot open results file {0}: {1}", filename, resfile.getLastErrorString());
return;
}
string outputFilename = filename + ".mgf";
// check if the mgf file already exists - do not overwrite if it does
if (File.Exists(outputFilename))
{
Console.WriteLine("{0} already exists; will not overwrite", outputFilename);
return;
}
// create the file
using (TextWriter tw = new StreamWriter(outputFilename))
{
for (int q = 1; q <= resfile.getNumQueries(); q++)
{
ms_inputquery inpQuery = new ms_inputquery(resfile, q);
if (inpQuery.getNumberOfPeaks(1) == 0)
{
// PMF - just the mass
tw.WriteLine(resfile.getObservedMass(q));
continue;
}
tw.WriteLine("BEGIN IONS");
tw.WriteLine("PEPMASS={0}", resfile.getObservedMass(q));
if (Math.Abs(resfile.getObservedCharge(q)) > 0)
{
tw.WriteLine("CHARGE={0}", resfile.getObservedCharge(q));
}
else
{
tw.WriteLine("CHARGE=Mr");
}
if (inpQuery.getStringTitle(true).Length > 0)
{
tw.WriteLine("TITLE={0}", inpQuery.getStringTitle(true));
}
for (int i = 1; i <= inpQuery.getNumberOfPeaks(1); i++)
{
tw.WriteLine("{0} {1}", inpQuery.getPeakMass(1, i), inpQuery.getPeakIntensity(1, i));
}
tw.WriteLine("END IONS");
}
}
}
private static void usage()
{
Console.WriteLine(@"Usage: create_mgf <results file>.
Given a mascot results file name, create an MGF file. The MGF file
will be named <results file>.mgf in the same directory where <results file>
is located.");
}
}
}