-
-
Notifications
You must be signed in to change notification settings - Fork 20
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
Add a prototype of Sample::developmental_stage backfill script #3461
base: dev
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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), | ||
), | ||
] |
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) | ||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This takes sample as the first argument There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. One more consideration here is that after updating the sample we will want to update the cached values on experiment. ie: refinebio/foreman/data_refinery_foreman/surveyor/external_source.py Lines 207 to 211 in 07d3759
|
||||||||||||
except Exception as e: | ||||||||||||
logger.exception(e) | ||||||||||||
finally: | ||||||||||||
sample.save() | ||||||||||||
|
||||||||||||
time.sleep(1) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
last_refreshed
on Experiment as well, since a sample could belong to more than one experiment.last_refresh_failure
as a timestamp on both as well to help with re-running