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

Create an mgf file from a Mascot results file.

#!/usr/local/bin/perl
##############################################################################
# file: create_mgf.pl #
# 'msparser' toolkit #
# Test harness / example code #
##############################################################################
# COPYRIGHT NOTICE #
# Copyright 1998-2010 Matrix Science Limited All Rights Reserved. #
# #
##############################################################################
# $Source: parser/examples/test_perl/create_mgf.pl $ #
# $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:: $ #
##############################################################################
use strict;
##############################################################################
use msparser;
if (!defined($ARGV[0])) {
usage();
exit(1);
}
createMGF($ARGV[0]);
sub createMGF {
my ($filename) = @_;
my $resfile = msparser::ms_mascotresfilebase::createResfile($filename);
if (!$resfile->isValid) {
print STDERR "Cannot open results file ", $filename, ": ";
print STDERR $resfile->getLastErrorString(), "\n";
return;
}
my $output_filename = $filename.'.mgf';
if (-e $output_filename) {
print STDERR "$output_filename already exists; will not overwrite\n";
return;
}
open(my $fh, '>', $output_filename)
or die "Cannot open $output_filename for writing: $!";
for my $q (1 .. $resfile->getNumQueries) {
my $inp_query = new msparser::ms_inputquery($resfile, $q);
if ($inp_query->getNumberOfPeaks(1) == 0) {
# PMF - just the mass
print $fh $resfile->getObservedMass($q), "\n";
next;
}
print $fh "BEGIN_IONS\n";
print $fh "PEPMASS=", $resfile->getObservedMass($q), "\n";
if ($resfile->getObservedCharge($q) > 0) {
print $fh "CHARGE=", $resfile->getObservedCharge($q), "+\n";
} else {
print $fh "CHARGE=Mr\n";
}
if ($inp_query->getStringTitle(1)) {
print $fh "TITLE=", $inp_query->getStringTitle(1), "\n";
}
for my $i (1 .. $inp_query->getNumberOfPeaks(1)) {
print $fh $inp_query->getPeakMass(1, $i), " ", $inp_query->getPeakIntensity(1, $i), "\n";
}
print $fh "END IONS\n\n";
}
}
sub usage {
print <<EOF;
Usage: create_mgf.pl <results file>
Given an 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.
EOF
}