This is an ORM (Object-Relational Mapping) that uses the Mongoengine library to interact with a MongoDB database. This ORM has been designed to handle information related to accessions, crop groups, crops and countries.
- Built using Mongoengine for MongoDB
- Supports Python 3.x
To use this ORM, it is necessary to have an instance of MongoDB running.
- Python 3.x
- MongoDB
This ORM can be used as a library in other Python projects. The models are located in the my_orm/models folder, and can be imported like any other Python module. To install this orm as a library you need to execute the following command:
pip install git+https://github.com/CIAT-DAPA/spcat_ormIf you want to download a specific version of orm you can do so by indicating the version tag (@v0.0.0) at the end of the install command
pip install git+https://github.com/CIAT-DAPA/spcat_orm@v0.2.0To interact with the database, it is necessary to connect the ORM to the MongoDB database. This can be done using the connect() function of the mongoengine library, as shown in the following example:
from mongoengine import connect
from ormgap import *
# Connect to the database
connect(host='mongodb://localhost/gap_analysis')
# Perform database queries using the models defined in ormgap/models
# Query the Accession collection
accessions = Accession.objects(species_name='Solanum lycopersicum')
# Do something with the accessions
for accession in accessions:
print(accession.id, accession.species_name, accession.crop)Represents a country in the database.
Attributes:
- iso_2:
strTwo-letter ISO code for the country (ISO 3166-1 alpha-2). Mandatory and unique. - name:
strName of the country. Mandatory.
Represents a crop in the database.
Attributes:
- ext_id:
strExternal ID of the crop. Mandatory and unique. - name:
strName of the crop. Mandatory. - base_name:
strBase name of the crop. - app_name:
strApplication name of the crop. Mandatory.
Represents a group in the database.
Attributes:
- group_name:
strName of the group. Mandatory. - crop:
CropCrop object that the group belongs to. Mandatory. - ext_id:
strExternal identifier for the group. Mandatory and unique.
Represents an accession in the database.
Attributes:
- species_name:
strName of the species of the accession. Optional. - crop:
CropCrop object, Crop to which the accession belongs. Mandatory. - landrace_group:
GroupGroup object, Landrace group to which the accession belongs. Mandatory. - country:
CountryCountry object, country to which the accession belongs. Mandatory. - institution_name:
strName of the institution that holds the accession. Optional. - source_database:
strName of the database where the accession was originally stored. Optional. - latitude:
floatLatitude of the geographical location where the accession was collected. Mandatory. - longitude:
floatLongitude of the geographical location where the accession was collected. Mandatory. - accession_id:
strThe identifier of the accession in source database. Optional. - ext_id:
strExternal identifier for the accession. Mandatory and unique. - other_attributes:
dictAdditional attributes of the accession. Optional.