Skip to content

Commit

Permalink
Merge pull request #139 from bfrgoncalves/flowcraft_reports
Browse files Browse the repository at this point in the history
Flowcraft reports
  • Loading branch information
bfrgoncalves authored Sep 14, 2018
2 parents 34e8139 + e5f873f commit 935de62
Show file tree
Hide file tree
Showing 44 changed files with 1,327 additions and 1,049 deletions.
4 changes: 2 additions & 2 deletions app/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
from resources.postgres.reports import ReportsResource, \
CombinedReportsResource, ReportsStrainResource, ReportsByProjectResource, \
ReportInfoResource, ReportFilterResource, \
ReportsFileStrainResource, FilePathOnZipResource, SavedReportsResource
ReportsFileStrainResource, FilePathOnZipResource, SavedReportsResource, ReportByIdResource
from resources.postgres.uploads import GetFilesResource, DownloadFilesResource
from resources.ngs_onto.ngs_onto_projects import NGSOnto_ProjectUserResource, \
NGSOnto_ProjectListUserResource
Expand Down Expand Up @@ -176,7 +176,7 @@
api.add_resource(FilePathOnZipResource, '/api/v1.0/reports/files/')
api.add_resource(CombinedReportsResource, '/api/v1.0/reports/combined')
api.add_resource(SavedReportsResource, '/api/v1.0/reports/saved/')

api.add_resource(ReportByIdResource, '/api/v1.0/reports/ids/')

################################# USER FILES ##################################

Expand Down
3 changes: 2 additions & 1 deletion app/app_configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import ldap

from flask_security import Security, SQLAlchemyUserDatastore, login_required,\
current_user, utils, roles_required, user_registered, login_user, utils
current_user, utils, roles_required, user_registered, login_user
from app import app, db, user_datastore, dbconAg,\
security
from app.models.models import Specie, User
Expand Down Expand Up @@ -77,6 +77,7 @@ def change_password():
return {"status": False}

except ldap.INVALID_CREDENTIALS, e:
print e
do_flash(*get_message('INVALID_PASSWORD'))
return {"status": False}

Expand Down
1 change: 1 addition & 0 deletions app/models/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ def try_login(email, password):
try:
conn.simple_bind_s("cn="+email+",ou=users,"+baseDN, password)
except Exception as e:
print e
return False

search_filter = "uid="+email
Expand Down
30 changes: 19 additions & 11 deletions app/resources/jobs/jobs.py
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,8 @@ def post(self):
user_id, json_data["task"],
parameters_json["species"], overwrite)

print is_added

return True


Expand Down Expand Up @@ -559,6 +561,7 @@ def get(self):
file2Path.append(
'/'.join(r["file_4"].split("/")[-3:-1]))
except Exception as p:
print p
file2Path = []

except Exception as e:
Expand Down Expand Up @@ -719,9 +722,6 @@ def get(self):

args = nextflow_logs_get_parser.parse_args()

til_storage = "/".join(current_user.homedir.split("/")[0:-3])
content = ""

project = db.session.query(Project).filter(
Project.id == args.project_id).first()

Expand Down Expand Up @@ -770,15 +770,23 @@ def get(self):

args = inspect_get_parser.parse_args()

request = requests.get(os.path.join(JOBS_ROOT, "inspect"),
params={
'homedir': current_user.homedir,
'pipeline_id': args.pipeline_id,
'project_id': args.project_id,
}
)
out = {"message": "Inspect feature for this strain."}

out = request.json()
projectObject = db.session.query(Project).filter(args.project_id == Project.id).first()

if projectObject:
userObject = db.session.query(User).filter(User.id == projectObject.user_id).first()

if userObject:
request = requests.get(os.path.join(JOBS_ROOT, "inspect"),
params={
'homedir': userObject.homedir,
'pipeline_id': args.pipeline_id,
'project_id': args.project_id,
}
)

out = request.json()

return out

Expand Down
3 changes: 2 additions & 1 deletion app/resources/ngs_onto/ngs_onto_users.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,8 @@ def post(self):
dedicateddbconAg.commit()
dedicateddbconAg.close()
return 201
except:
except Exception as e:
print e
dedicateddbconAg.rollback()
dedicateddbconAg.close()
return 404
Expand Down
47 changes: 47 additions & 0 deletions app/resources/postgres/reports.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,12 @@
report_get_parser.add_argument('species_id', dest='species_id', type=str,
required=False, help="Species ID")

# Defining post arguments parser
report_post_id_parser = reqparse.RequestParser()

report_post_id_parser.add_argument('job_ids', dest='job_ids', type=str,
required=False, help="job identifier")

# Defining projects get arguments parser
report_get_project_parser = reqparse.RequestParser()

Expand Down Expand Up @@ -293,11 +299,52 @@ def post(self):
.all()

for x in reports:
if "reportJson" in x.report_data.keys():
if "cagao" in x.report_data["reportJson"]:
del x.report_data["reportJson"]["cagao"]

reports_to_send.append(x.report_data)

return reports_to_send, 200


class ReportByIdResource(Resource):
"""
Class to get reports by applying filters
"""

# @login_required
def post(self):
"""Reports with filters
Returns the projects filtered according to a list of selected projet
identifiers and strain identifiers.
Returns
-------
list: list of reports
"""

args = report_post_id_parser.parse_args()

job_ids = args.job_ids.split(",")

reports_to_send = []

for job in job_ids:
j = job.split("-")

report = db.session.query(Report)\
.filter(Report.project_id == j[0],
Report.pipeline_id == j[1],
Report.process_position == j[2]).first()

if report:
reports_to_send.append(report.report_data)

return reports_to_send, 200


class ReportsByProjectResource(Resource):
"""
Class to get reports by project
Expand Down
1 change: 1 addition & 0 deletions app/resources/postgres/uploads.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ def get(self):
try:
return request.json(), 200
except Exception as e:
print e
return False, 200


Expand Down
3 changes: 1 addition & 2 deletions app/resources/postgres/users.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,8 +189,6 @@ def get(self):
project_dir = os.path.join(current_user.homedir, "jobs",
project_id+"-*")

print instStorage

# Get size of homedir
proc = subprocess.Popen(["du", "-sh", "-B1", current_user.homedir],
stdout=subprocess.PIPE, stderr=subprocess.PIPE)
Expand All @@ -209,6 +207,7 @@ def get(self):
try:
out3 += os.path.getsize(fp)
except Exception as e:
print e
print "error loading " + fp

proc = subprocess.Popen(["df", "-Ph", "-B1", current_user.homedir],
Expand Down
3 changes: 2 additions & 1 deletion app/resources/postgres/workflows.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ def get(self):
workflows = db.session.query(Workflow).all()

if not workflows:
abort(404, message="No workflows are available".format(id))
abort(404, message="No workflows are available")
return workflows, 200


Expand Down Expand Up @@ -253,6 +253,7 @@ def post(self):
loaded_steps = json.loads(protocol.steps.replace("'", '"'))
list_tags.append(loaded_steps["Nextflow Tag"])
except Exception as e:
print e
return {"content": "Protocol with errors. Please create "
"another protocol to use when building this workflow."}

Expand Down
Loading

0 comments on commit 935de62

Please sign in to comment.