Ejemplo n.º 1
0
 def test_taxonomy(self):
     tax = taxonomy.Taxonomy()
     self.assertIsInstance(tax, taxonomy.Taxonomy)
     self.assertIsInstance(tax.semantic, taxonomy_semantic.TaxonomySemantic)
     self.assertIsInstance(tax.types, taxonomy_types.TaxonomyTypes)
     self.assertIsInstance(tax.units, taxonomy_units.TaxonomyUnits)
     self.assertIsInstance(tax.misc, taxonomy_misc.TaxonomyMisc)
Ejemplo n.º 2
0
 def test_taxonomy(self):
     tax = taxonomy.Taxonomy()
     self.assertIsInstance(tax, taxonomy.Taxonomy)
     self.assertIsInstance(tax.semantic, taxonomy_semantic.TaxonomySemantic)
     self.assertIsInstance(tax.types, taxonomy_types.TaxonomyTypes)
     self.assertIsInstance(tax.units, taxonomy_units.TaxonomyUnits)
     self.assertIsInstance(tax.numeric_types, taxonomy_misc.TaxonomyNumericTypes)
     self.assertIsInstance(tax.generic_roles, taxonomy_misc.TaxonomyGenericRoles)
     self.assertIsInstance(tax.ref_parts, taxonomy_misc.TaxonomyRefParts)
     self.assertIsInstance(tax.documentation, taxonomy_misc.TaxonomyDocstrings)
Ejemplo n.º 3
0
#    http://www.apache.org/licenses/LICENSE-2.0

# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import unittest

import taxonomy
#import taxonomy_semantic
from six import string_types

taxonomy_obj = taxonomy.Taxonomy()
tax = taxonomy_obj.semantic


class TestTaxonomySemantic(unittest.TestCase):

    def test_concept_details(self):

        # Data type checks
        ci = tax.get_concept_details("solar:ACDisconnectSwitchMember")
        self.assertIsNotNone(ci)
        self.assertIsInstance(ci.abstract, bool)
        self.assertIsInstance(ci.id, string_types)
        # 'six.string_types' is equivalent to "str or unicode" in python2, "str" in python3
        self.assertIsInstance(ci.name, string_types)
        self.assertIsInstance(ci.nillable, bool)
Ejemplo n.º 4
0
Orange Button Overview: https://sunspec.org/orange-button-initiative/
Orange Button GitHUb: https://github.com/SunSpecOrangeButton
Orange Button CLI GitHub: https://github.com/SunSpecOrangeButton/core
"""

DASHES = "---------------------------------------------------------------------------------------"

# The following line will cause pyinstaller to work correctly.
# In all likelihood it is sub-optimal however because it would
# preclude adding file input or output as CLI arguments (since
# the working directory changes to the wrong value).
if getattr(sys, 'frozen', False):
    os.chdir(sys._MEIPASS)

tax = taxonomy.Taxonomy()


def info(args):
    print(INFO)


def generate_identifier(args):
    print(identifier.identifier())


def list_concept_info(args):
    print()
    c = tax.semantic.concept_info(args.concept)
    print(c)
    if c is not None:
Ejemplo n.º 5
0
#    http://www.apache.org/licenses/LICENSE-2.0

# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import unittest
import parser
import taxonomy

from jsondiff import diff

taxonomy = taxonomy.Taxonomy()
parser = parser.Parser(taxonomy)


class TestParser(unittest.TestCase):
    # Note: this module is tested differently than others.  Sample JSON and XML
    # files are imported and then exported and later compared using the string
    # methods.  Thereafter files are loaded and created but the files contents
    # themselves are not examined (it is assumed that this would be picked up
    # in the comparisons of the strings).

    def test_json(self):

        entrypoint = parser.from_JSON_string(TEST_JSON)
        out = parser.to_JSON_string(entrypoint)
        d = diff(TEST_JSON, out)
Ejemplo n.º 6
0
import taxonomy

# Create a TCP/IP socket
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)

if len(sys.argv) != 2:
    print 'Usage: python server.py <port number>'
    sys.exit(0)

portNum = int(sys.argv[1])

# Bind the socket to the port
server_address = ('nike.cs.uga.edu', portNum)
print >>sys.stderr, 'starting up on %s port %s' % server_address
sock.bind(server_address)
tester = taxonomy.Taxonomy('')
while True:
    #print >>sys.stderr, '\nwasiting to receive message'
    data, address = sock.recvfrom(4096)
    
    print >>sys.stderr, 'received %s bytes from %s' % (data, address)
    print >>sys.stderr, data

    commandList = data.split(' ')
    for str in commandList:
        print str

    if commandList[0] == 'insert' and len(commandList) == 2:
        tester.insert(commandList[1])
        # sent = sock.sendto('Inserted ' + data, address)
    elif commandList[0] == 'list':
Ejemplo n.º 7
0
class Taxonomy:
    '''
    Taxonomy represents a Linnean category (order, family, or genus)
    If a Taxonomy object's level is 'genus', then its item list contains
    strings of the form <species-name> [(<common-name>)]
    If the Taxonomy object's level is 'Order' or 'Family', then its item
    list contains Taxonomy objects of the next level down.
    '''
    def __init__(self, category, level='Order'):
        import pickle
        import os.path
        '''
        Create a new Taxonomy based on 'category'
        if 'level' is 'Order' and a serialization file
        for this order exists, then populate this object from
        that file; otherwise, create an empty Taxonomy

        category: the name of an order, a family, or a genus
        level: one of 'Order', 'Family', or 'Genus'
        '''
        self.errorMessageStatement = 'Insertion OK'
        if level == 'Order':
            # does the file already exist?
            if (os.path.isfile(category + ".p")):
                self.itemList = pickle.load(open(category + ".p", "rb"))
            self.level = 'Order'
            self.itemList = []
            self.categoryName = category
        else:
            # just make an empty taxonomy object
            self.categoryName = category
            self.level = level
            self.itemList = []

    def addSpecies(self, species):
        '''
        Add a species to this taxonomy and return True. The level of this
        taxonomy must be 'genus'. If not, set an error message and return False.
        '''
        if self.level != 'Genus':
            self.errorMessageStatement = 'Taxonomy is not of level Genus.'
            return False
        else:
            self.itemList.append(species)
            self.serialize()
            return True

    def addTaxonomy(self, subTaxonomy):
        '''
        Add a sub-taxonomy to this taxonomy and return True. The sub-taxonomy must
        be at one level below this taxonomy. If not, set an error message and return False.
        '''
        # checks to see one level below
        if self.level == 'Order' and subTaxonomy.level != 'Family':
            self.errorMessageStatement = 'Subtaxonomy was not one level below.'
            return False
        if self.level == 'Family' and subTaxonomy.level != 'Genus':
            self.errorMessageStatement = 'Subtaxonomy was not one level below.'
            return False
        self.itemList.append(subTaxonomy)
        self.serialize()
        return True

    def errorMessage(self):
        '''
        Return the error message generated by the last insertion, or
        'Insertion OK' if the last insertion did not create an error
        '''
        return self.errorMessageStatement

    def insert(self, path):
        '''
        Insert the species that is the last element of 'path' into
        this object,creating order, family, or genus Taxonomy objects
        as needed. If the length of path does not match the level of this
        Taxonomy object, set an error message ,abort the insertion,  and
        return False; otherwise return True after successful insertion.

        This Taxonomy Level  Expected path length
        Order                3
        Family               2
        Genus                1

        path: front-slash-separated list of categories.
        '''
        # to see if there is an existing species, otherwise add it
        temp = path.split('/')
        if self.level == 'Genus':
            if len(temp) != 1:
                self.errorMessageStatement = 'Error inserting ' + path + ' into ' + self.categoryName + ': wrong length'
                return False
            else:
                self.itemList.append(temp[0])
                self.serialize()
                return True

        if self.level == 'Family':
            if len(temp) != 2:
                self.errorMessageStatement = 'Error inserting ' + path + ' into ' + self.categoryName + ': wrong length'
                return False

            for item in self.itemList:
                if item.categoryName == temp[0]:
                    # in the event genus already exists
                    for _item in item.itemList:
                        if _item == temp[1]:
                            # species already exists in heirarchy
                            return True

                    # species does not exist, but the genus does
                    item.itemList.append(temp[0])
                    return True

            # in the event no genus exists in the family
            newGenus = Taxonomy(temp[0], 'Genus')
            newGenus.itemList.append(temp[1])
            self.itemList.append(newGenus)
            self.serialize()
            return True

        # error check on order
        if self.level == 'Order':
            if len(temp) != 3:
                self.errorMessageStatement = 'Error inserting ' + path + ' into ' + self.categoryName + ': wrong length'
                return False
            print '\n'
            # iterate through family objects in order to see match
            for item in self.itemList:
                # check if there is a family that already exists
                if item.categoryName == temp[0]:
                    # there is already a family object with the same category name
                    for _item in item.itemList:
                        # for every genus in this family object
                        if _item.categoryName == temp[1]:
                            # genus already exists in this family object
                            for _item_ in _item.itemList:
                                # for every species string in this genus
                                if _item_ == temp[2]:
                                    # this species already exists in the genus
                                    return True
                            # genus exists but the species does not
                            _item.itemList.append(temp[2])
                            return True
                    # there is a family object, but no genus or therefore species
                    newGenus = Taxonomy(temp[1], 'Genus')
                    newGenus.itemList.append(temp[2])
                    _item.itemList.append(newGenus)
                    return True
            # adds a family with a new genus and new species in that genus
            newFamily = Taxonomy(temp[0], 'Family')
            _newGenus = Taxonomy(temp[1], 'Genus')
            _newGenus.itemList.append(temp[2])
            self.itemList.append(newFamily)
            newFamily.itemList.append(_newGenus)
            self.serialize()
            return True

    def list(self):
        '''
        Return a string representing the contents of this Taxonomy
        and its sub-Taxonomies, in the format
        top-category-name (subitem1, subitem2,...),
        where subitem1, subitem2... are either strings representing species,
        in the  form <latin-name> [(common-name)], or sublists representing
        Taxonomies.
        '''
        # iterates through objects in an order's item list
        if self.level == 'Order':
            listSpecies = ""
            listSpecies += self.categoryName
            for family in self.itemList:
                listSpecies += " (" + family.categoryName
                for genus in family.itemList:
                    listSpecies += " (" + genus.categoryName
                    for species in genus.itemList:
                        listSpecies += " (" + species
                    listSpecies += ")"
                listSpecies += ")"
            listSpecies += ")"
            return listSpecies
        # iteratees through the items of a family
        if self.level == 'Family':
            listSpecies = ""
            listSpecies += self.categoryName
            for genus in self.itemList:
                listSpecies += " (" + genus.categoryName
                for species in genus.itemList:
                    listSpecies += " (" + species
                listSpecies += ")"
            listSpecies += ")"
            return listSpecies
        # iterates through items in a genus
        if self.level == 'Genus':
            listSpecies = ""
            listSpecies += self.categoryName
            for species in self.itemList:
                listSpecies += " (" + species
            listSpecies += ")"
            return listSpecies

    def serialize(self):
        import pickle
        '''
        Save contents of this object using pickle
        '''
        pickle.dump(self.itemList, open(self.categoryName + ".p", "wb"))

    if __name__ == "__main__":
        import taxonomy
        import unittest
        import sys
        '''Test adding a species to a genus with no errors'''
        genus1 = taxonomy.Taxonomy('')
        while (1):
            userInput = raw_input('> ')
            commandList = []
            commandList = userInput.split(' ')
            for str in commandList:
                print(str + ' ')
                if userInput.strip() == 'quit' or userInput.strip() == 'exit':
                    print 'Closing application'
                    sys.exit(0)
                if commandList[0] == 'insert':
                    genus1.insert(commandList[1])
                if commandList[0] == 'list':
                    print(genus1.list())
                else:
                    print('The command ' + userInput + ' does not exist.')
Ejemplo n.º 8
0
From home run:
$ ssh -fNL 27028:localhost:27018 gbwl
$ ssh -fNL 27027:localhost:27017 gbwl
where gbwl is [email protected] -W wl-cmadmin.scripps.edu:22

"""

#HOST = 'localhost'
HOST = 'wl-cmadmin'

from pymongo import MongoClient
from itertools import chain
from collections import Counter
import taxonomy

t = taxonomy.Taxonomy(host=HOST, port=27017)

client = MongoClient(HOST, 27017)
taxDB = client.TaxDB_072114.TaxDB_072114
hashDB = client.HashDB_072114.HashDB_072114
domainDB = client.DomainDB_072114.DomainDB_072114

protDB = MongoClient(HOST, 27018).ProtDB_072114.ProtDB_072114

from file_processing import blazmass_tools
from file_processing.dta import build_proteins_from_peptides


def get_domains(p):
    hashes = [
        x['_id'] for x in hashDB.find({'pID': {