|
13 | 13 | from qiita_core.util import execute_as_transaction |
14 | 14 |
|
15 | 15 | from qiita_db.software import Software |
| 16 | +from qiita_db.study import Study |
16 | 17 |
|
17 | 18 | from json import dumps |
18 | 19 |
|
@@ -91,3 +92,40 @@ def get(self): |
91 | 92 |
|
92 | 93 | # return the json in compact form to save transmit size |
93 | 94 | self.write(dumps(results, separators=(',', ':'))) |
| 95 | + |
| 96 | + |
| 97 | +class SampleValidation(AdminProcessingJobBaseClass): |
| 98 | + @coroutine |
| 99 | + @execute_as_transaction |
| 100 | + def get(self): |
| 101 | + self._check_access() |
| 102 | + |
| 103 | + self.render("sample_validation.html", input=True) |
| 104 | + |
| 105 | + @execute_as_transaction |
| 106 | + def post(self): |
| 107 | + |
| 108 | + # Get user-inputted qiita id and sample names |
| 109 | + qid = self.get_argument("qid") |
| 110 | + snames = self.get_argument("snames").split() |
| 111 | + |
| 112 | + # Stripping leading qiita id from sample names |
| 113 | + # Example: 1.SKB1.640202 -> SKB1.640202 |
| 114 | + qsnames = list(Study(qid).sample_template) |
| 115 | + for i, qsname in enumerate(qsnames): |
| 116 | + if qsname.startswith(qid): |
| 117 | + qsnames[i] = qsname.replace(f'{qid}.', "", 1) |
| 118 | + |
| 119 | + # Remove blank samples from sample names |
| 120 | + blank = [x for x in snames if x.lower().startswith('blank')] |
| 121 | + snames = [x for x in snames if 'blank' not in x.lower()] |
| 122 | + |
| 123 | + # Validate user's sample names against qiita study |
| 124 | + qsnames = set(qsnames) |
| 125 | + snames = set(snames) |
| 126 | + matching = qsnames.intersection(snames) |
| 127 | + missing = qsnames.difference(snames) |
| 128 | + extra = snames.difference(qsnames) |
| 129 | + |
| 130 | + self.render("sample_validation.html", input=False, matching=matching, |
| 131 | + missing=missing, extra=extra, blank=blank) |
0 commit comments