Esempio n. 1
0
def parse_json_file(file):
    # returns a tuple:  (species,reactions,compartments)
    #   species:  { 'id' : Species(...) }
    #   reactions:  { 'id' : Reaction(...) }
    #   compartments { 'id' : ('name','outside') }

    model = util.parse_json_file(file)

    compartments = {}
    for compartment in model['compartments']:
        compartments[compartment['id']] = (compartment['name'],
                                           compartment['outside'])

    species = {}
    for sp in model['species']:
        species[sp['id']] = Species(sp['id'],
                                    name=sp['name'],
                                    compartment=sp['compartment'])

    reactions = {}
    for reaction in model['reactions']:
        reactants = [copy.deepcopy(species[s]) for s in reaction['reactants']]
        products = [copy.deepcopy(species[s]) for s in reaction['products']]
        reactions[reaction['id']] = Reaction(reaction['id'],
                                             reactants=reactants,
                                             products=products,
                                             reversible=reaction['reversible'],
                                             subsystem=reaction['subsystem'])

    return species, reactions, compartments
Esempio n. 2
0
 def buildPopulationList(population_list):
     states = SateList()
     for i in population_list:
         tokens = i.split("=")
         s = Species(tokens[0])
         states.updateSpeciesPopulation(s, int(tokens[1]))
     return states
Esempio n. 3
0
def addSpecies2(session, species_input):
    genus_id = addGenus(session, species_input["genus"])
    print("creating new Species:" + species_input)
    species = Species()
    species.scientific_name = species_input["scientific_name"]
    species.common_name = species_input["common_name"]
    species.genus = genus_id
    session.add(species)
    session.commit()
Esempio n. 4
0
def addSpecimen(session, specimen_input):
    try:  # Lets check if we can retreive the species matching the specimen record.
        species = session.query(Species).filter(
            Species.scientific_name == specimen_input["species"]
            ["scientific_name"]).one()
    except:
        species = Species()
        species.scientific_name = specimen_input["species"]["scientific_name"]
        session.add(species)
    specimen = Specimen()
    specimen.name = specimen_input["name"]
    specimen.birth_date_time = specimen_input["birth_date_time"]
    specimen.species = species
    session.add(specimen)
    session.commit()
Esempio n. 5
0
def add_species():
    session = dbconnect()
    request_dict = request.get_json()
    try:
        genus_instance = session.query(Genus).filter(
            Genus.scientific_name == request_dict["genus"]
            ["scientific_name"]).one()
    except:
        return "Genus does not exist, please add it", 400
    species = Species()
    species.scientific_name = request_dict["scientific_name"]
    species.common_name = request_dict["common_name"]
    species.genus_id = genus_instance.id
    session.add(species)
    session.commit()
    return "ok"
Esempio n. 6
0
def load_species():
    """Load species from u.species into database."""

    print "Species"

    Species.query.delete()

    for row in open('seed_data/u.species'):
        row = row.rstrip()
        species_id, name = row.split('|')

        species = Species(species_id=species_id, name=name)

        db.session.add(species)

    db.session.commit()
Esempio n. 7
0
def addSpecies(session, species_input):
    genus = Genus()
    try:
        genus = session.query(Genus).filter(
            Genus.scientific_name == species_input["genus"]
            ["scientific_name"]).one()
    except:
        genus = Genus()
        genus.scientific_name = species_input["genus"]["scientific_name"]
        session.add(genus)
    species = Species()
    species.scientific_name = species_input["scientific_name"]
    species.common_name = species_input["common_name"]
    species.genus = genus
    session.add(species)
    session.commit()
Esempio n. 8
0
def load_birds():
    """Load bird common names with corresponding species codes into database"""

    for i, row in enumerate(open('seed_data/species.csv')):
        data = row.rstrip().split(",")
        common_name, species_code = data

        bird = Species(common_name=common_name,
                    species_code=species_code)

        db.session.add(bird)

        # For testing, just to see it was happening
        if i % 100 == 0:
            print i

    db.session.commit()
Esempio n. 9
0
def _pSpecies(cls, delayedInits=None):
    xml = xmlutils.parseAndValidateXML('species.xml')
    sl = xml.xpath('/species-list/species')
    assert len(sl) > 0

    def resolveTrait(ref_xml, trait_type):
        key = ref_xml.get('ref')
        assert key
        trait = trait_type.db.get(key)
        assert trait, key
        assert trait.name, key
        # print(trait.name)
        return trait

    for xml in sl:
        name = xml.get('name')
        s = Species(parent=g.getApp(), identifier=Id(name))

        def resolveList(modelType, xp):
            l = [resolveTrait(x, modelType) for x in xml.xpath(xp)]
            # for ll in l:
            #    print(ll.value)
            return QQmlListProperty(modelType, s, l)

        s.name = name
        s.cost = int(xml.get('cost'))
        s.baseLE = int(xml.xpath('./point-modifiers/LE-base/@value')[0])
        s.baseSK = int(xml.xpath('./point-modifiers/SK-base/@value')[0])
        s.baseZ = int(xml.xpath('./point-modifiers/Z-base/@value')[0])
        s.baseGS = int(xml.xpath('./point-modifiers/GS-base/@value')[0])
        s.unusualPerkList = resolveList(Perk, './unusual-perks/*')
        s.unusualQuirkList = []  # resolveList(Quirk, './unusual-quirks/*')
        s.perkList = resolveList(Perk, './usual-perks/*')
        s.quirkList = []  # resolveList(Quirk, './usual-quirks/*')

        #TODO
        s.eyeColorList = xml.xpath('./eye_colors/eye_color/@name')
        s.hairColorList = xml.xpath('./hair-colors/hair-color/@name')
        s.weightLimits = xml.xpath('./weight/range/@*')
        s.heightLimits = xml.xpath('./height/range/@*')
        s.talentBoniList = xml.xpath('./talent-bonus/*')
        s.cultureList = xml.xpath('./cultures/*')
        # todo starting ages
        s.assertFrozenAttrs()
        yield s
Esempio n. 10
0
def add_species():
    session = dbconnect()
    request_dict = request.get_json()
    try:
        genus_instance = session.query(Genus).filter(Genus.id == request_dict["genus"]["id"]).one()
    except:
        return "Genus does not exist, please add it", 400
    
    try:
        species = Species() 
        species.scientific_name = request_dict["scientific_name"]
        species.common_name = request_dict["common_name"]
        species.genus_id = genus_instance.id
        session.add(species)
        session.commit()
        return jsonify(species.id)
    except exc.IntegrityError:
        session.rollback()
        return "already exists", 400
Esempio n. 11
0
def load_species(species_filename):
    """Load species from seed_data/species into database."""

    # Delete all rows in table, so if we need to run this a second time,
    # we won't be trying to add duplicate users
    Species.query.delete()

    #Read species file and insert data
    for row in open(species_filename):
        row = row.rstrip()
        species_id, species = row.split("|")

        the_species = Species(species=species)

        # We need to add to the session or it won't ever be stored
        db.session.add(the_species)

    # Once we're done, we should commit our work
    db.session.commit()

    #finished the function
    print("Species inserted")
Esempio n. 12
0
 def parse_species(sp):
     return Species(sp.get('id'),
                    name=sp.get('name'),
                    compartment=sp.get('compartment'))