Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Develop #152

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"python.pythonPath": "flask/bin/python2.7"
}
Binary file modified app/.DS_Store
Binary file not shown.
Binary file modified app/__init__.pyc
Binary file not shown.
Binary file modified app/adminutils.pyc
Binary file not shown.
Binary file modified app/api.pyc
Binary file not shown.
Binary file modified app/app_configuration.pyc
Binary file not shown.
Binary file modified app/models/__init__.pyc
Binary file not shown.
3 changes: 3 additions & 0 deletions app/models/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,7 @@ class Project(db.Model):
is_removed = db.Column(db.String(255))
description = db.Column(db.Text())
timestamp = db.Column(db.DateTime)
last_update_timestamp = db.Column(db.DateTime)
user_id = db.Column(db.Integer, db.ForeignKey('users.id'))
pipelines = db.relationship('Pipeline', backref='project', lazy='dynamic')
strains = db.relationship('Strain', secondary=projects_strains,
Expand Down Expand Up @@ -376,6 +377,8 @@ class Strain(db.Model):
id = db.Column(db.Integer(), primary_key=True)
name = db.Column(db.String(255), unique=True)
timestamp = db.Column(db.DateTime)
update_timestamp = db.Column(db.DateTime)
delete_timestamp = db.Column(db.DateTime)
strain_metadata = db.Column(JSON)
fields = db.Column(JSON)
species_id = db.Column(db.Integer, db.ForeignKey('species.id'))
Expand Down
Binary file modified app/models/models.pyc
Binary file not shown.
Binary file modified app/resources/__init__.pyc
Binary file not shown.
1 change: 1 addition & 0 deletions app/resources/jobs/checks.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ def get(self):
print e
return False


return True


Expand Down
14 changes: 13 additions & 1 deletion app/resources/postgres/projects.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,9 @@
'uri': fields.Url('user_single_project', absolute=True),
'species_id': fields.String,
'is_removed': fields.String,
'username': fields.String
'username': fields.String,
'number_strains_change': fields.Integer,
'strains_expire': fields.List(fields.String)
}

project_fields = {
Expand Down Expand Up @@ -303,6 +305,16 @@ def get(self, id):
.filter(project.user_id == User.id).first()

project.username = user.username
count = 0
project.strains_expire = []


for strain in project.strains:
if strain.delete_timestamp != None:
if strain.delete_timestamp > project.timestamp:
count+=1
project.strains_expire.append(strain.name)
project.number_strains_change = count

return projects, 200

Expand Down
75 changes: 74 additions & 1 deletion app/resources/postgres/strains.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

# Defining post arguments parser


strain_project_parser = reqparse.RequestParser()
strain_project_parser.add_argument('strainID', dest='strainID', type=str,
required=False, help="Strain identifier")
Expand Down Expand Up @@ -60,7 +61,10 @@
'classifier': fields.String,
'fq_location': fields.String,
'has_files': fields.String,
'Accession': fields.String
'Accession': fields.String,
'delete_timestamp': fields.String,
'update_timestamp': fields.String,
'strainsIDs': fields.List(fields.String)
}

strain_fields_project = {
Expand Down Expand Up @@ -160,6 +164,14 @@ def get(self):
else:
strains = db.session.query(Strain).all()

strains_aux = list(strains)

for strain in strains:
if strain.delete_timestamp != None:
strains_aux.remove(strain)

strains = strains_aux

for strain in strains:
strain.file_1 = json.loads(strain.strain_metadata)["File_1"]
strain.file_2 = json.loads(strain.strain_metadata)["File_2"]
Expand Down Expand Up @@ -288,11 +300,72 @@ def put(self):
for key, val in args.iteritems():
strain_metadata[key] = val

if "Accession" in args:

metadata = json.loads(strain.strain_metadata)

if metadata["Accession"] != args["Accession"]:

strain_specie_name = database_correspondece.keys()[strain.species_id - 1]

strain_specie = database_correspondece[strain_specie_name]

result = db.session.query(strain_specie).filter(strain_specie.strain_metadata['strainID'].astext == metadata["Accession"]).first()

if not result:
abort(404, message="An error as occurried")

strain.update_timestamp = datetime.datetime.utcnow()

strain.strain_metadata = json.dumps(strain_metadata)

db.session.commit()

return strain, 201

@login_required
@marshal_with(strain_fields)
def delete(self):
"""Remove strain

This method allows removing a strain. Requires the
strain name and the project id.

Parameters
----------
id: str
project identifier

Returns
-------

"""


args = request.data

obj = json.loads(args)

strains_ids = list(obj.values())[0]

if not current_user.is_authenticated:
abort(403, message="No permissions")

for strainId in strains_ids:
strain = db.session.query(Strain).filter(Strain.id == strainId).first()

if not strain:
abort(404, message="No strain available")

if strain.user_id != current_user.id:
abort(404, message="No permissions")

strain.delete_timestamp = datetime.datetime.utcnow()

db.session.commit()

return 200


class StrainsByNameResource(Resource):
"""
Expand Down
Binary file modified app/static/.DS_Store
Binary file not shown.
12 changes: 7 additions & 5 deletions app/static/controllers/js_objects/metadata.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@ const Metadata = () => {
"Project Name":"project_name",
"Classifier":"classifier",
"Accession": "Accession",
"Timestamp":"timestamp"
"Timestamp":"timestamp",
"Strain_State":"Strain_State"
};

//Conversion from the metadata fields stored in the db to how we want to see them on a table (Reverse)
Expand All @@ -76,18 +77,19 @@ const Metadata = () => {
"project_name": "Project Name",
"classifier": "Classifier",
"Accession": "Accession",
"timestamp": "Timestamp"
"timestamp": "Timestamp",
"Strain_State":"Strain_State"
};

//The minimum headers to be seen on a table
const minimal_headers = [
"Strain Name", "Received Date", "Source", "Additional Info", "File 1",
"Primary", "Sampling Date", "Owner", "Case ID", "Submitter", "File 2",
"Location", "Accession", "Timestamp"];
"Location", "Accession", "Timestamp", "Strain_State"];

const default_headers = [
"Strain Name", "Received Date", "Source", "Sampling Date", "Location",
"Sample", "Run Identifier", "Project Name", "Classifier", "Accession", "Timestamp"];
"Strain Name", "Received Date", "Source", "Sampling Date", "Location","Owner",
"Sample", "Run Identifier", "Project Name", "Classifier", "Accession", "Timestamp","Strain_State"];

return {

Expand Down
11 changes: 8 additions & 3 deletions app/static/controllers/js_objects/objects_utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,11 @@ const Objects_Utils = (single_project, $sc) => {
const format_analysis = (d, table_id) => {
// `d` is the original data object for the row

$("#" + d.strainID + "_table").remove();

let strain_id = d.strainID;
strain_id = strain_id.replace(/(.*?) <i.*/i, "$1") ;

$("#" + strain_id + "_table").remove();

let tr_string = "";

Expand Down Expand Up @@ -148,7 +152,8 @@ const Objects_Utils = (single_project, $sc) => {
}

if (table_id === "modify_strains_table" || table_id === "reports_trees_table") {
selection_style = "single";
//selection_style = "single";
selection_style = "multi";
}
else {
selection_style = "multi";
Expand Down Expand Up @@ -745,7 +750,7 @@ const Objects_Utils = (single_project, $sc) => {

$("#" + table_id + " thead").append(create_table_headers(table_headers, has_analysis, table_id));
$("#" + table_id + " tfoot > tr").remove();
$("#" + table_id + " tfoot").append(create_table_headers(table_headers, has_analysis, table_id));
//$("#" + table_id + " tfoot").append(create_table_headers(table_headers, has_analysis, table_id));


callback();
Expand Down
42 changes: 38 additions & 4 deletions app/static/controllers/js_objects/projects_table.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,13 +102,25 @@ const Projects_Table = (CURRENT_PROJECT_ID, CURRENT_PROJECT, $http) => {
' fa-unlock"></i></div>';
}

if(d.number_strains_change > 0)
{
icon = "<i class='fa fa-ban' style='color:#DC143C;'></i>";
d.Project_State= icon + "<strong style='color:#DC143C;'> - Outdated </strong>";

}else{
icon = "<i class='fa fa-check' style='color:#006400;'></i>";
d.Project_State= icon + "<strong style='color:#006400;'> - Up-to-date </strong>";
}


other_projects.push({
name: d.name,
description: d.description,
date: d.timestamp.split(" ").slice(0, 4).join(' '),
id: d.id,
username: d.username,
lockStatus: lockStatus
lockStatus: lockStatus,
Project_State:d.Project_State
});
}
});
Expand Down Expand Up @@ -138,13 +150,32 @@ const Projects_Table = (CURRENT_PROJECT_ID, CURRENT_PROJECT, $http) => {
' fa-unlock"></i></div>';
}


let strain_ex = d.name;
if(d.number_strains_change > 0)
{
icon = "<i class='fa fa-ban' style='color:#DC143C;'></i>";
d.Project_State= icon + "<strong style='color:#DC143C;'> - Outdated </strong>";
if(d.strains_expire.includes(d.name))
{

strain_ex += " " + "<i class=\"fa fa-exclamation-triangle\" title=\"Esta strain foi removida ou alterada.\" style=\"color:orange\"></i>";
}
}else{
icon = "<i class='fa fa-check' style='color:#006400;'></i>";
d.Project_State= icon + "<strong style='color:#006400;'> - Up-to-date </strong>";
}

projects.push({
name: d.name,
name: strain_ex,
description: d.description,
date: d.timestamp.split(" ").slice(0, 4).join(' '),
id: d.id,
username: d.username,
lockStatus: lockStatus
lockStatus: lockStatus,
number_strains_change: d.number_strains_change,
strains_expire: d.strains_expire,
Project_State:d.Project_State
});
}
});
Expand Down Expand Up @@ -180,13 +211,16 @@ const Projects_Table = (CURRENT_PROJECT_ID, CURRENT_PROJECT, $http) => {
' style="width:100%;text-align:center;"><i class="fa' +
' fa-unlock"></i></div>';

let icon = "<i class='fa fa-check' style='color:#006400;'></i>";

projects.push({
name: response.data.name,
description: response.data.description,
date: response.data.timestamp.split(" ").slice(0, 4).join(' '),
id: response.data.id,
username: response.data.username,
lockStatus: lockStatus
lockStatus: lockStatus,
Project_State:icon+ "<strong style='color:#006400;'> - Up-to-date </strong>"
});

$('#newProjectModal').modal('hide');
Expand Down
Loading