Repository: AlexsLemonade/refinebio

Issue:
Some samples have a typo on the manufacturer field
### Context

I was running some queries in the DB for #1391 

### Problem or idea

Noticed that some samples  have `AFFYMETRTIX` in the manufacturer field instead of `AFFYMETRIX`.

```
data_refinery=> select count(id), manufacturer from samples group by manufacturer;
 count  | manufacturer 
--------+--------------
  49906 | UNKNOWN
 532028 | ILLUMINA
   1351 | ION_TORRENT
  20858 | AFFYMETRTIX
    112 | NEXTSEQ
 607980 | AFFYMETRIX
(6 rows)
```

### Solution or next step

Not sure if it's better to fix this with a migration or a management command.



Discussion:
Once we know where this is coming in from and we have a fix deployed, that seems like the right time to write a migration and fix the previously imported data as well.
NEXTSEQ is a type of Illumina machine. I’m fairly sure where this issue is coming from was fixed months ago, so we might want to fix this while we’re at it.
These lines might be causing the problem:

https://github.com/AlexsLemonade/refinebio/blob/bbb45aa44673382eb61ab8318308f68356b19780/workers/data_refinery_workers/processors/management/commands/correct_affy_samples.py#L130

https://github.com/AlexsLemonade/refinebio/blob/1b3e65574f9c4ecf6fc7eccb8ecd2ff7906cf214/workers/data_refinery_workers/downloaders/utils.py#L212

https://github.com/AlexsLemonade/refinebio/blob/da9300e33eac74601c1958dad05d029abb78a805/foreman/data_refinery_foreman/surveyor/geo.py#L378
It looks like the NEXTSEQ issue was fixed in this commit, but I should also add it to the migration: https://github.com/AlexsLemonade/refinebio/commit/6a081be926c1fba85de3c68655a57e378acf6771
https://github.com/AlexsLemonade/refinebio/pull/1463 Should have fixed the samples that are mislabeled, is there a way to check if the migration ran correctly? @kurtwheeler 

Seems that we now have more samples labeled with the typo than when the issue was created:

```sql
data_refinery=> select count(id), manufacturer from samples group by manufacturer;
 count  | manufacturer 
--------+--------------
 595038 | ILLUMINA
  49789 | UNKNOWN
   1911 | ION_TORRENT
  97500 | AFFYMETRTIX
    112 | NEXTSEQ
 531810 | AFFYMETRIX
(6 rows)
```
Hmm... that's really weird! I don't actually really know how to check the output of a migration, the database has a record of it running and presumably a migration that fails would stop things:
```
AFFYMETRTIX
```43 | data_refinery_common | 0026_fix_typo_in_sample_manufacturer     | 2019-08-08 19:45:10.584936+00
```


Resolving patch:
diff --git a/common/data_refinery_common/migrations/0030_update_sample_manufacturer.py b/common/data_refinery_common/migrations/0030_update_sample_manufacturer.py
new file mode 100644
--- /dev/null
+++ b/common/data_refinery_common/migrations/0030_update_sample_manufacturer.py
@@ -0,0 +1,19 @@
+# Generated by Django 2.1.8 on 2019-08-09 16:48
+
+from django.db import migrations, models
+
+def fix_typo_in_sample_manufacturer(apps, schema_editor):
+    """ Fixes affymetrix samples that have their manufacturer set to "AFFYMETRTIX" or "NEXTSEQ" """
+    Sample = apps.get_model('data_refinery_common', 'Sample')
+    Sample.objects.all().filter(manufacturer="AFFYMETRTIX").update(manufacturer="AFFYMETRIX")
+    Sample.objects.all().filter(manufacturer="NEXTSEQ").update(manufacturer="ILLUMINA")
+
+class Migration(migrations.Migration):
+
+    dependencies = [
+        ('data_refinery_common', '0029_auto_20190809_1648'),
+    ]
+
+    operations = [
+        migrations.RunPython(fix_typo_in_sample_manufacturer),
+    ]


Test patch: