Skip to content

Commit

Permalink
Merge pull request #929 from IGS/hotfix-927
Browse files Browse the repository at this point in the history
Hotfix 927
  • Loading branch information
adkinsrs authored Oct 28, 2024
2 parents 6674458 + 03e948a commit dc649d4
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 44 deletions.
5 changes: 4 additions & 1 deletion www/api/resources/projectr.py
Original file line number Diff line number Diff line change
Expand Up @@ -497,7 +497,10 @@ def projectr_callback(dataset_id, genecart_id, projection_id, session_id, scope,
, "num_dataset_genes": num_target_genes
}

adata.close()
# Close adata so that we do not have a stale opened object
if adata.isbacked:
adata.file.close()

if dedup_copy.exists():
dedup_copy.unlink()

Expand Down
91 changes: 51 additions & 40 deletions www/cgi/process_uploaded_expression_dataset.cgi
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import pandas as pd
import scanpy as sc
from scipy import sparse
import anndata
import zipfile

# This has a huge dependency stack of libraries. Occasionally, one of them has methods
# which prints debugging information on STDOUT, killing this CGI. So here we redirect
Expand Down Expand Up @@ -305,48 +306,58 @@ def process_mex_3tab(upload_dir):

files_extracted = []

with tarfile.open(filename) as tf:
for entry in tf:
tf.extract(entry, path=upload_dir)

# Nemo suffixes
nemo_suffixes = ['DataMTX.tab', 'COLmeta.tab', 'ROWmeta.tab']
suffix_found = None
if compression_format == 'tarball':
try:
with tarfile.open(filename) as tf:
for entry in tf:
tf.extract(entry, path=upload_dir)

# Nemo suffixes
nemo_suffixes = ['DataMTX.tab', 'COLmeta.tab', 'ROWmeta.tab']
suffix_found = None

for suffix in nemo_suffixes:
if entry.name.endswith(suffix):
suffix_found = suffix
# Rename the file to the appropriate name
os.rename(os.path.join(upload_dir, entry.name),
os.path.join(upload_dir, suffix))

if suffix_found is not None:
files_extracted.append(suffix_found)
else:
files_extracted.append(entry.name)
except tarfile.ReadError:
write_status(upload_dir, 'error', "Bad tarball file. Couldn't extract the tarball.")
return

for suffix in nemo_suffixes:
if entry.name.endswith(suffix):
suffix_found = suffix
# Rename the file to the appropriate name
os.rename(os.path.join(upload_dir, entry.name),
os.path.join(upload_dir, suffix))

if suffix_found is not None:
files_extracted.append(suffix_found)
else:
files_extracted.append(entry.name)

with zipfile.ZipFile(filename) as zf:
for entry in zf.infolist():
zf.extract(entry, path=upload_dir)

# Nemo suffixes
nemo_suffixes = ['DataMTX.tab', 'COLmeta.tab', 'ROWmeta.tab']
suffix_found = None

for suffix in nemo_suffixes:
if entry.filename.endswith(suffix):
suffix_found = suffix
# Rename the file to the appropriate name
os.rename(os.path.join(upload_dir, entry.filename),
os.path.join(upload_dir, suffix))

if suffix_found is not None:
files_extracted.append(suffix_found)
else:
files_extracted.append(entry.filename)
if compression_format == 'zip':
try:
with zipfile.ZipFile(filename) as zf:
for entry in zf.infolist():
zf.extract(entry, path=upload_dir)

# Nemo suffixes
nemo_suffixes = ['DataMTX.tab', 'COLmeta.tab', 'ROWmeta.tab']
suffix_found = None

for suffix in nemo_suffixes:
if entry.filename.endswith(suffix):
suffix_found = suffix
# Rename the file to the appropriate name
os.rename(os.path.join(upload_dir, entry.filename),
os.path.join(upload_dir, suffix))

if suffix_found is not None:
files_extracted.append(suffix_found)
else:
files_extracted.append(entry.filename)
except zipfile.BadZipFile:
write_status(upload_dir, 'error', "Bad zip file. Couldn't extract the zip file.")
return

# Determine the dataset type
dataset_type = tarball_content_type(files_extracted)
dataset_type = package_content_type(files_extracted)

if dataset_type is None:
write_status(upload_dir, 'error', "Unsupported dataset format. Couldn't tell type from file names within the tarball")
Expand All @@ -363,7 +374,7 @@ def write_status(upload_dir, status_name, message):
with open(os.path.join(upload_dir, 'status.json'), 'w') as f:
f.write(json.dumps(status))

def tarball_content_type(filenames):
def package_content_type(filenames):
print("DEBUG: filenames", file=sys.stderr, flush=True)
print(filenames, file=sys.stderr, flush=True)
"""
Expand Down
11 changes: 10 additions & 1 deletion www/js/upload_dataset.js
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,6 @@ const populateMetadataFormFromFile = async () => {
if (data.success) {
document.getElementsByName('metadata-title')[0].value = data.metadata.title.value;
document.getElementsByName('metadata-summary')[0].value = data.metadata.summary.value;
document.getElementsByName('metadata-dataset-type')[0].value = data.metadata.dataset_type.value;
document.getElementsByName('metadata-annotation-source')[0].value = data.metadata.annotation_source.value;
document.getElementsByName('metadata-annotation-version')[0].value = data.metadata.annotation_release_number.value;
document.getElementsByName('metadata-geo-id')[0].value = data.metadata.geo_accession.value;
Expand All @@ -285,6 +284,16 @@ const populateMetadataFormFromFile = async () => {
document.getElementsByName('metadata-library-source')[0].value = data.metadata.library_source.value;
document.getElementsByName('metadata-library-strategy')[0].value = data.metadata.library_strategy.value;
document.getElementsByName('metadata-pubmed-id')[0].value = data.metadata.pubmed_id.value;

// Handle the metadata-dataset-type select box
let dataset_type_select = document.getElementsByName('metadata-dataset-type')[0];
for (let i = 0; i < dataset_type_select.options.length; i++) {
if (dataset_type_select.options[i].value === data.metadata.dataset_type.value) {
dataset_type_select.selectedIndex = i;
break;
}
}

document.getElementById('metadata-upload-status-message').textContent = "Form populated with uploaded metadata";
button.disabled = false;

Expand Down
4 changes: 2 additions & 2 deletions www/upload_dataset.html
Original file line number Diff line number Diff line change
Expand Up @@ -225,8 +225,8 @@ <h1>Step - Enter metadata (via form OR upload)</h1>
<div class="select">
<select name="metadata-dataset-type">
<option value="">Select one</option>
<option value="sc-rna-seq">Single-cell RNA-seq</option>
<option value="bulk-rna-seq">Bulk RNA-seq</option>
<option value="single-cell-rnaseq">Single-cell RNA-seq</option>
<option value="bulk-rnaseq">Bulk RNA-seq</option>
<option value="microarray">Microarray</option>
</select>
</div>
Expand Down

0 comments on commit dc649d4

Please sign in to comment.