Example program for reading and manipulating the quantitation.xml file.
#!/usr/local/bin/perl ############################################################################## # file: config_quantitation.pl # # 'msparser' toolkit example code # ############################################################################## # COPYRIGHT NOTICE # # Copyright 1998-2010 Matrix Science Limited All Rights Reserved. # # # ############################################################################## # $Source: parser/examples/test_perl/config_quantitation.pl $ # # $Author: villek@matrixscience.com $ # # $Date: 2018-07-30 16:23:53 +0100 $ # # $Revision: 1b450440f9c97e1e41d0fc6016a27d68951d4532 | MSPARSER_REL_2_8_1-0-gea32989045 $ # # $NoKeywords:: $ # ############################################################################## use strict; ############################################################################## use msparser; if (!defined($ARGV[0])) { print <<EOF; The location of quantitation.xml file has to be specified as a parameter. The location should either be the full path to the quantitation.xml file or a URL to a Mascot server - e.g. http://mascot-server/mascot/cgi EOF exit 1; } if (!defined($ARGV[1])) { print <<EOF; The location of schema file quantitation_XXX.xsd has to be specified as the second parameter. The location should only be a full or relative path to the quantitation_XXX.xsd file. EOF exit 1; } # Note: $cs must not be lexically scoped; you need to keep it in scope # for as long as you use $file. See "Using the toolkit from Perl, Java and # Python" in Mascot Parser manual. my ($file, $cs); # A sessionID can optionally be passed as the third parameter. # This will only be required if the 'file' is a URL. if (defined($ARGV[2])) { $cs = new msparser::ms_connection_settings; $cs->setSessionID($ARGV[2]); $file = new msparser::ms_quant_configfile($ARGV[0], $ARGV[1], $cs); } else { $file = new msparser::ms_quant_configfile($ARGV[0], $ARGV[1]); } if (!$file->isValid) { print "There are errors. Cannot continue. The last error description:\n"; print $file->getLastErrorString(), "\n"; exit 1; } my $n = $file->getNumberOfMethods; print "There are ", $n, " quantitation methods available:\n"; for my $i (0 .. $n-1) { print $file->getMethodByNumber($i)->getName(), "\n"; } # Validate the original document. if (my $errs = $file->validateDocument()) { print "Initial document validation errors:\n"; print $errs, "\n"; } # Now try to read in the schema file. my $schemaFile = new msparser::ms_xml_schema; $schemaFile->setFileName($ARGV[1]); $schemaFile->read_file; if (!$schemaFile->isValid) { print "Errors while reading schema-file. The last error description:\n"; print $schemaFile->getLastErrorString(), "\n"; exit 1; } # The document can be validated programmatically, but this is different from # real validation against a schema. We'll validate each quantitation # method separately. for my $i (0 .. $n-1) { # Shallow validation: only check the presence of required attributes and # elements. my $pMethod = $file->getMethodByNumber($i); if (my $errs = $pMethod->validateShallow($schemaFile)) { print "Shallow validation errors (method ", $pMethod->getName, "): "; print $errs, "\n\n"; } # Deep validation: check attributes and elements recursively applying basic # constraints. if (my $errs = $pMethod->validateDeep($schemaFile)) { print "Deep validation errors (method ", $pMethod->getName, "): "; print $errs, "\n\n"; } } # We can validate objects as well. First, copy the first method from the # original file (method "null"). my $myMethodInvalid = new msparser::ms_quant_method($file->getMethodByNumber(0)); # And set an invalid name with less than allowed string length. $myMethodInvalid->setName(""); # First way: use shallow and deep validation as above. if (my $errs = $myMethodInvalid->validateShallow($schemaFile)) { print "Shallow validation of a method: ", $errs, "\n"; } if (my $errs = $myMethodInvalid->validateDeep($schemaFile)) { print "Deep validation of a method: ", $errs, "\n"; } # Second way: use the schema object. This is equivalent to the previous # two-step process as long as you pass 'true' as the second parameter # for deep validation. if (my $errs = $schemaFile->validateComplexObject($myMethodInvalid, 1)) { print "Deep validation using schema-object: ", $errs, "\n"; } # Third way: validate an attribute separately. Available validation methods # are validateSimpleInteger(), validateSimpleDouble(), validateSimpleBool() # and validateSimpleString(). if (my $errs = $schemaFile->validateSimpleString($myMethodInvalid->getName(), $myMethodInvalid->getNameSchemaType())) { print "Attribute validation: ", $errs, "\n"; } # Fourth way: validate an entire document. For this, we need to create # a new document and append the invalid method definition. my $configFileInvalid = new msparser::ms_quant_configfile; $configFileInvalid->appendMethod($myMethodInvalid); if (my $errs = $configFileInvalid->validateDocument()) { print "Document validation errors: ", $errs, "\n"; } # The config file object itself stays valid, even if it has an invalid # method definition. if ( !$configFileInvalid->isValid() ) { # Control flow never comes here! print "Errors in config file object. The last error description:\n"; print $configFileInvalid->getLastErrorString(), "\n"; } # The file can be saved even if it has invalid definitions. $configFileInvalid->setFileName("quantitation_temp.xml"); $configFileInvalid->save_file(); if ( !$configFileInvalid->isValid() ) { print "Failed to save: ", $configFileInvalid->getLastErrorString(), "\n"; } =pod Running the program as perl -I../bin config_quantitation.pl ../config/quantitation.xml ../html/xmlns/schema/quantitation_2/quantitation_2.xsd will give the following output under Mascot Server 2.3 (depending on how quantitation methods have been configured): There are 26 quantitation methods available: None iTRAQ 4plex iTRAQ 8plex TMT 6plex TMT 2plex 18O multiplex SILAC K+6 R+6 multiplex IPTL (Succinyl and IMID) multiplex ICPL duplex pre-digest [MD] ICPL duplex post-digest [MD] ICPL triplex pre-digest [MD] 18O corrected [MD] 15N Metabolic [MD] 15N + 13C Metabolic [MD] SILAC K+6 R+10 [MD] SILAC K+6 R+10 Arg-Pro [MD] SILAC K+6 R+6 [MD] SILAC R+6 R+10 [MD] SILAC K+8 R+10 [MD] SILAC K+4 K+8 R+6 R+10 [MD] ICAT ABI Cleavable [MD] ICAT D8 [MD] Dimethylation [MD] NBS Shimadzu [MD] Label-free [MD] Average [MD] Deep validation of a method: Attribute 'name' -> String is shorter than minLength-limit Deep validation using schema-object: Attribute 'name' -> String is shorter than minLength-limit Attribute validation: String is shorter than minLength-limit =cut
Copyright © 2022 Matrix Science Ltd. All Rights Reserved. Generated on Thu Mar 31 2022 01:12:29 |