Matrix Science header

config_taxonomy.py

Read in the taxonomy file.

#!/usr/bin/python
##############################################################################
# file: config_taxonomy.py                                                   #
# 'msparser' toolkit example code                                            #
##############################################################################
# COPYRIGHT NOTICE                                                           #
# Copyright 1998-2010 Matrix Science Limited  All Rights Reserved.           #
#                                                                            #
##############################################################################
#     $Source: /vol/cvsroot/parser/examples/test_python/config_taxonomy.py,v $ #
#     $Author: neilr $                                                      #
#       $Date: 2016/03/22 10:13:16 $                                        #
#   $Revision: 1.3 $                                                         #
# $NoKeywords::                                                            $ #
##############################################################################

import msparser
import sys

if len(sys.argv) < 2 :
    print("""
The location of taxonomy file has to be specified as a parameter.
The location should either be the full path to the taxonomy file
or a URL to a Mascot server - e.g. http://mascot-server/mascot/cgi
""")
    sys.exit(1)

# A sessionID can optionally be passed as the second parameter.
# This will only be required if the 'file' is a URL.
if len(sys.argv) > 2 :
    cs = msparser.ms_connection_settings()
    cs.setSessionID(sys.argv[2])
    file = msparser.ms_taxonomyfile(sys.argv[1], cs)
else :
    file = msparser.ms_taxonomyfile(sys.argv[1])

if not file.isValid() :
    print("There are errors. Cannot continue. The last error description:")
    print(file.getLastErrorString())
    sys.exit(1)

n = file.getNumberOfEntries()
print("There are %d taxonomy choice entries configured:" % n)

for i in range(n) :
    entry = file.getEntryByNumber(i)
    print(entry.getTitle())

    tax = []
    for i in range(entry.getNumberOfIncludeTaxonomies()) :
        tax.append("%d" % entry.getIncludeTaxonomy(i))

    print("Include: " + ', '.join(tax))

    tax = []
    for i in range(entry.getNumberOfExcludeTaxonomies()) :
        tax.append("%d" % entry.getExcludeTaxonomy(i))

    print("Exclude: " + ', '.join(tax))



"""

Running the program as 

python config_taxonomy.pl /usr/local/mascot/config/taxonomy

will give the following output under Mascot Server 2.3:


There are 65 taxonomy choice entries configured:
All entries
Include: 1
Exclude:  0
. . Archaea (Archaeobacteria)
Include: 2157
Exclude:  
. . Eukaryota (eucaryotes)
Include: 2759
Exclude:  
. . . . Alveolata (alveolates)
Include: 33630
Exclude:  
. . . . . . Plasmodium falciparum (malaria parasite)
Include: 5833
Exclude:  
. . . . . . Other Alveolata
    [ ... ]

"""

Copyright © 2016 Matrix Science Ltd.  All Rights Reserved. Generated on Fri Jun 2 2017 01:44:50