Skip to content

Commit

Permalink
some changes
Browse files Browse the repository at this point in the history
  • Loading branch information
antgonza committed Dec 10, 2024
1 parent edd3eed commit db968c3
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 25 deletions.
16 changes: 15 additions & 1 deletion qiita_db/metadata_template/prep_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
from iteration_utilities import duplicates

from qiita_core.exceptions import IncompetentQiitaDeveloperError
from qiita_ware.private_plugin import _delete_analysis_artifacts
import qiita_db as qdb
from .constants import (PREP_TEMPLATE_COLUMNS, TARGET_GENE_DATA_TYPES,
PREP_TEMPLATE_COLUMNS_TARGET_GENE)
Expand Down Expand Up @@ -135,7 +136,7 @@ def create(cls, md_template, study, data_type, investigation_type=None,
# data_type being created - if possible
if investigation_type is None:
if data_type_str in TARGET_GENE_DATA_TYPES:
investigation_type = 'Amplicon'
investigation_type = 'AMPLICON'
elif data_type_str == 'Metagenomic':
investigation_type = 'WGS'
elif data_type_str == 'Metatranscriptomic':
Expand Down Expand Up @@ -282,6 +283,19 @@ def delete(cls, id_):
qdb.sql_connection.TRN.execute_fetchflatten())
if archived_artifacts:
for aid in archived_artifacts:
# before we can delete the archived artifact, we need
# to delete the analyses where they were used.
sql = """SELECT analysis_id
FROM qiita.analysis
WHERE analysis_id IN (
SELECT DISTINCT analysis_id
FROM qiita.analysis_sample
WHERE artifact_id IN %s)"""
qdb.sql_connection.TRN.add(sql, [aid])
analyses = set(
qdb.sql_connection.TRN.execute_fetchflatten())
for _id in analyses:
_delete_analysis_artifacts(qdb.analysis.Analysis(_id))
qdb.artifact.Artifact.delete(aid)

# Delete the prep template filepaths
Expand Down
12 changes: 7 additions & 5 deletions qiita_db/processing_job.py
Original file line number Diff line number Diff line change
Expand Up @@ -2053,23 +2053,25 @@ def complete_processing_job(self):
def trace(self):
""" Returns as a text array the full trace of the job, from itself
to validators and complete jobs"""
lines = [f'{self.id} [{self.external_id}]: '
lines = [f'{self.id} [{self.external_id}] ({self.status}): '
f'{self.command.name} | {self.resource_allocation_info}']
cjob = self.complete_processing_job
if cjob is not None:
lines.append(f' {cjob.id} [{cjob.external_id}] | '
lines.append(f' {cjob.id} [{cjob.external_id}] ({cjob.status})| '
f'{cjob.resource_allocation_info}')
vjob = self.release_validator_job
if vjob is not None:
lines.append(f' {vjob.id} [{vjob.external_id}] '
f'| {vjob.resource_allocation_info}')
f' ({vjob.status}) | '
f'{vjob.resource_allocation_info}')
for v in self.validator_jobs:
lines.append(f' {v.id} [{v.external_id}]: '
lines.append(f' {v.id} [{v.external_id}] ({v.status}): '
f'{v.command.name} | {v.resource_allocation_info}')
cjob = v.complete_processing_job
if cjob is not None:
lines.append(f' {cjob.id} [{cjob.external_id}] '
f'| {cjob.resource_allocation_info}')
f'({cjob.status}) | '
f'{cjob.resource_allocation_info}')
return lines


Expand Down
7 changes: 7 additions & 0 deletions qiita_db/support_files/patches/93.sql
Original file line number Diff line number Diff line change
Expand Up @@ -55,3 +55,10 @@ CREATE INDEX IF NOT EXISTS processing_job_command_parameters_payload ON qiita.pr

-- After the changes
-- 18710.404 ms

--

-- Nov 5, 2024
-- Addding contraints for the slurm_reservation column
ALTER TABLE qiita.analysis DROP CONSTRAINT IF EXISTS analysis_slurm_reservation_valid_chars;
ALTER TABLE qiita.analysis ADD CONSTRAINT analysis_slurm_reservation_valid_chars CHECK ( slurm_reservation ~ '^[a-zA-Z0-9_]*$' );
14 changes: 10 additions & 4 deletions qiita_db/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -2334,7 +2334,7 @@ def send_email(to, subject, body):
msg = MIMEMultipart()
msg['From'] = qiita_config.smtp_email
msg['To'] = to
msg['Subject'] = subject
msg['Subject'] = subject.replace('\n', '')
msg.attach(MIMEText(body, 'plain'))

# connect to smtp server, using ssl if needed
Expand Down Expand Up @@ -2496,9 +2496,9 @@ def _resource_allocation_plot_helper(
ax.set_ylabel(curr)
ax.set_xlabel(col_name)

# 100 - number of maximum iterations, 3 - number of failures we tolerate
# 50 - number of maximum iterations, 3 - number of failures we tolerate
best_model, options = _resource_allocation_calculate(
df, x_data, y_data, models, curr, col_name, 100, 3)
df, x_data, y_data, models, curr, col_name, 50, 3)
k, a, b = options.x
x_plot = np.array(sorted(df[col_name].unique()))
y_plot = best_model(x_plot, k, a, b)
Expand Down Expand Up @@ -2593,6 +2593,8 @@ def _resource_allocation_calculate(
failures_df = _resource_allocation_failures(
df, k, a, b, model, col_name, type_)
y_plot = model(x, k, a, b)
if not any(y_plot):
continue
cmax = max(y_plot)
cmin = min(y_plot)
failures = failures_df.shape[0]
Expand Down Expand Up @@ -2834,13 +2836,17 @@ def merge_rows(rows):
wait_time = (
datetime.strptime(rows.iloc[0]['Start'], date_fmt)
- datetime.strptime(rows.iloc[0]['Submit'], date_fmt))
tmp = rows.iloc[1].copy()
if rows.shape[0] >= 2:
tmp = rows.iloc[1].copy()
else:
tmp = rows.iloc[0].copy()
tmp['WaitTime'] = wait_time
return tmp

slurm_data['external_id'] = slurm_data['JobID'].apply(
lambda x: int(x.split('.')[0]))
slurm_data['external_id'] = slurm_data['external_id'].ffill()

slurm_data = slurm_data.groupby(
'external_id').apply(merge_rows).reset_index(drop=True)

Expand Down
24 changes: 10 additions & 14 deletions qiita_pet/templates/resources.html
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,14 @@ <h3>Please choose software, version, and command to view the data.</h3>
<option value="">Select Software</option>
</select>
</div>

<div class="form-group">
<label for="version">Version:</label>
<select id="version" name="version" class="form-control">
<option value="">Select Version</option>
</select>
</div>

<div class="form-group">
<label for="command">Command:</label>
<select id="command" name="command" class="form-control">
Expand Down Expand Up @@ -89,15 +89,15 @@ <h3>Generated on: {{time}} </h3>
</tr>
</table>
</div>

</div>

<script>

function toggleDataVisibility(showData) {
const defaultMessage = document.getElementById('default-message');
const dataContainer = document.getElementById('data-container');

if (showData) {
defaultMessage.style.display = 'none';
dataContainer.style.display = 'block';
Expand All @@ -106,17 +106,15 @@ <h3>Generated on: {{time}} </h3>
dataContainer.style.display = 'none';
}
}

// Call this function on initial load
{% if initial_load %}
toggleDataVisibility(false);
{% else %}
toggleDataVisibility(true);
{% end %}

const commandsConst = JSON.parse('{% raw commands %}');
console.log(commandsConst);

const commandsConst = JSON.parse(`{% raw commands %}`);
const softwareSelect = document.getElementById('software');
const versionSelect = document.getElementById('version');
const commandSelect = document.getElementById('command');
Expand All @@ -133,7 +131,7 @@ <h3>Generated on: {{time}} </h3>
function populateVersions(software) {
versionSelect.innerHTML = '<option value="">Select Version</option>';
commandSelect.innerHTML = '<option value="">Select Command</option>';

if (software && commandsConst[software]) {
for (const version in commandsConst[software]) {
const option = document.createElement('option');
Expand All @@ -147,7 +145,7 @@ <h3>Generated on: {{time}} </h3>

function populateCommands(software, version) {
commandSelect.innerHTML = '<option value="">Select Command</option>';

if (software && version && commandsConst[software][version]) {
commandsConst[software][version].forEach(command => {
const option = document.createElement('option');
Expand All @@ -167,7 +165,6 @@ <h3>Generated on: {{time}} </h3>

$.post(window.location.href, JSON.stringify(data), function(response, textStatus, jqXHR) {
if (response.status === "success") {
console.log(response.time)
// Toggle visibility based on the response
toggleDataVisibility(true);

Expand Down Expand Up @@ -227,7 +224,7 @@ <h3>Generated on: {{time}} </h3>
}

bootstrapAlert("Data updated successfully", "success", 2200);
}
}
else if (response.status === "no_data") {
toggleDataVisibility(false);
$('#default-message').html('<h3>No data available for the selected options.</h3>');
Expand All @@ -238,7 +235,6 @@ <h3>Generated on: {{time}} </h3>
}
}, 'json')
.fail(function(jqXHR, textStatus, errorThrown) {
console.error('Error:', errorThrown);
toggleDataVisibility(false);
bootstrapAlert("An error occurred while processing your request", "danger", 2200);
});
Expand Down Expand Up @@ -269,4 +265,4 @@ <h3>Generated on: {{time}} </h3>
}
});
</script>
{% end %}
{% end %}
3 changes: 2 additions & 1 deletion scripts/qiita-recover-jobs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@ def _retrieve_queue_jobs():

# ignore the merge-jobs and get unique values
qiita_jids = jobs.NAME.str.replace('merge-', '').unique()
qiita_jids = [x.replace('.txt', '') for x in qiita_jids]
qiita_jids = [x.replace(
'finish-', '').replace('.txt', '') for x in qiita_jids]

return set(qiita_jids)

Expand Down

0 comments on commit db968c3

Please sign in to comment.