-
-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a prototype of Sample::developmental_stage backfill script
- Loading branch information
Showing
3 changed files
with
65 additions
and
0 deletions.
There are no files selected for viewing
18 changes: 18 additions & 0 deletions
18
common/data_refinery_common/migrations/0075_sample_last_refreshed.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# Generated by Django 3.2.18 on 2023-12-08 00:45 | ||
|
||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
("data_refinery_common", "0074_sample_developmental_stage"), | ||
] | ||
|
||
operations = [ | ||
migrations.AddField( | ||
model_name="sample", | ||
name="last_refreshed", | ||
field=models.DateTimeField(auto_now=True, null=True), | ||
), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
foreman/data_refinery_foreman/foreman/management/commands/refresh_sample_metadata.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import time | ||
|
||
from django.core.management.base import BaseCommand | ||
|
||
from data_refinery_common.logging import get_and_configure_logger | ||
from data_refinery_common.models import Sample | ||
from data_refinery_foreman.surveyor.sra import SraSurveyor | ||
|
||
logger = get_and_configure_logger(__name__) | ||
|
||
|
||
class Command(BaseCommand): | ||
def add_arguments(self, parser): | ||
parser.add_argument( | ||
"--limit", | ||
default=1000, | ||
type=int, | ||
help="Number of samples to refresh", | ||
) | ||
parser.add_argument( | ||
"--source", | ||
choices=("SRA",), | ||
required=True, | ||
type=str, | ||
help="Source name (ARRAY_EXPRESS, GEO, SRA)", | ||
) | ||
|
||
def handle(self, *args, **options): | ||
for sample in Sample.objects.filter( | ||
developmental_stage__isnull=True, | ||
last_refreshed__isnull=True, | ||
source_database=options["source"], | ||
).order_by("id")[: options["limit"]]: | ||
logger.info(f"Refreshing metadata for a sample {sample.accession_code}") | ||
try: | ||
_, sample_metadata = SraSurveyor.gather_all_metadata(sample.accession_code) | ||
SraSurveyor._apply_harmonized_metadata_to_sample(sample_metadata) | ||
except Exception as e: | ||
logger.exception(e) | ||
finally: | ||
sample.save() | ||
|
||
time.sleep(1) |