Skip to content

Commit

Permalink
fix computed tree logic
Browse files Browse the repository at this point in the history
  • Loading branch information
emiliorighi committed Sep 4, 2024
1 parent f16ed00 commit 457fcf0
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 8 deletions.
5 changes: 2 additions & 3 deletions server/jobs/taxonomy.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import json
from celery import shared_task
from helpers import taxonomy as taxonomy_helper


ROOT_NODE = os.getenv('ROOT_NODE')

@shared_task(name='helpers_handle_orphans', ignore_result=False)
Expand All @@ -14,15 +16,12 @@ def handle_orphan_organisms():
orphan.delete()


@shared_task(name="helpers_compute_tree", ignore_result=False)
def compute_tree():
node = TaxonNode.objects(taxid=ROOT_NODE).first()
if not node:
print(f"Taxon root with taxid: {ROOT_NODE} not found")
return

tree = taxonomy_helper.dfs_generator_iterative(node)

# Resolve the path to the static folder
current_dir = os.path.dirname(os.path.abspath(__file__))
static_dir = os.path.join(current_dir, '../static')
Expand Down
3 changes: 1 addition & 2 deletions server/rest/cronjob/cronjob_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@
},
'helpers':{
'handle_orphans':taxonomy.handle_orphan_organisms,
'add_lineage':taxonomy.add_lineage,
"tree":taxonomy.compute_tree
'add_lineage':taxonomy.add_lineage
},
'geo_locations':{
'create_from_local_samples':geolocation.create_local_sample_coordinates,
Expand Down
4 changes: 2 additions & 2 deletions server/rest/goat_report/goat_reports_service.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import csv
from db.enums import GoaTStatus,PublicationSource
from db.models import Organism,Publication, GoaTUpdateDate
from db.enums import GoaTStatus
from db.models import Organism, GoaTUpdateDate
from io import StringIO
from itertools import islice
from helpers import user as user_helper, taxonomy as taxonomy_helper
Expand Down
3 changes: 3 additions & 0 deletions server/rest/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ def initialize_routes(api):
##TAXONOMY
api.add_resource(taxonomy_controller.RootTreeApi, '/api/tree')


api.add_resource(sample_locations_controller.SampleLocations, '/api/coordinates')

##ORGANISMS
Expand All @@ -57,8 +58,10 @@ def initialize_routes(api):
api.add_resource(assemblies_controller.AssemblyChrAliasesApi, '/api/assemblies/<accession>/chr_aliases')

##CRONJOBS
api.add_resource(taxonomy_controller.GenerateTreeApi, '/api/cronjob/helpers/tree')
api.add_resource(cronjobs_controller.CronJobApi, '/api/cronjob', '/api/cronjob/<model>/<action>')


##GEOGRAPHIC LOCATIONS
api.add_resource(sample_locations_controller.SampleLocationsByTaxon, '/api/taxons/<taxid>/coordinates')
api.add_resource(sample_locations_controller.SampleLocationsByBioSample, '/api/biosamples/<accession>/coordinates' )
Expand Down
9 changes: 8 additions & 1 deletion server/rest/taxonomy/taxonomy_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
from flask import Response,request
from flask_restful import Resource
from extensions.cache import cache
from flask_jwt_extended import jwt_required
from jobs import taxonomy
import json

class TreeApi(Resource):
Expand All @@ -23,4 +25,9 @@ def get(self,taxid):

class RootTreeApi(Resource):
def get(self):
return taxonomy_service.get_root_tree()
return taxonomy_service.get_root_tree()

class GenerateTreeApi(Resource):
@jwt_required()
def post(self):
taxonomy.compute_tree()

0 comments on commit 457fcf0

Please sign in to comment.