-
Couldn't load subscription status.
- Fork 79
Add duplicates and tube_ids feature #3291
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
Changes from 2 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 |
|---|---|---|
|
|
@@ -105,28 +105,70 @@ def get(self): | |
|
|
||
| @execute_as_transaction | ||
| def post(self): | ||
|
|
||
| # Get user-inputted qiita id and sample names | ||
| # Get user-inputted qiita id and sample names / tube_ids | ||
| qid = self.get_argument("qid") | ||
| snames = self.get_argument("snames").split() | ||
|
|
||
| # Get study give qiita id | ||
| st = Study(qid).sample_template | ||
|
|
||
| # Stripping leading qiita id from sample names | ||
| # Example: 1.SKB1.640202 -> SKB1.640202 | ||
| qsnames = list(Study(qid).sample_template) | ||
| qsnames = list(st) | ||
| for i, qsname in enumerate(qsnames): | ||
| if qsname.startswith(qid): | ||
| qsnames[i] = qsname.replace(f'{qid}.', "", 1) | ||
|
|
||
| # Adds tube ids to a dict with key as tube id and value as qsname | ||
|
||
| tube_ids_dict = dict() | ||
|
||
| tube_ids_rev = dict() | ||
| tube_ids = set() | ||
| if "tube_id" in st.categories: | ||
| for qsname, tid in st.get_category("tube_id").items(): | ||
| formatted_name = qsname | ||
| if qsname.startswith(qid): | ||
| formatted_name = qsname.replace(f'{qid}.', "", 1) | ||
|
|
||
| tube_ids.add(tid) | ||
| tube_ids_dict[formatted_name] = tid | ||
| tube_ids_rev[tid] = formatted_name | ||
|
|
||
| # Adds tube ids after sample name in paranthesis | ||
| if len(tube_ids) > 0: | ||
| for i, sname in enumerate(snames): | ||
| if sname in qsnames: | ||
| snames[i] = f'{sname} ({tube_ids_dict[sname]})' | ||
| elif sname in tube_ids: | ||
| snames[i] = f'{tube_ids_rev[sname]} ({sname})' | ||
|
|
||
| # Finds duplicates in the samples | ||
| seen = dict() | ||
|
||
| for sample in snames: | ||
| if sample in seen: | ||
| seen[sample] += 1 | ||
| else: | ||
| seen[sample] = 1 | ||
|
|
||
| duplicates = [] | ||
| for sample, num in seen.items(): | ||
| if num > 1: | ||
| duplicates.append(f'{sample} \u00D7 {num}') | ||
| duplicates = set(duplicates) | ||
|
|
||
| # Remove blank samples from sample names | ||
| blank = [x for x in snames if x.lower().startswith('blank')] | ||
| blank = set([x for x in snames if x.lower().startswith('blank')]) | ||
| snames = [x for x in snames if 'blank' not in x.lower()] | ||
|
|
||
| # Validate user's sample names against qiita study | ||
| qsnames = set(qsnames) | ||
| if len(tube_ids) == 0: | ||
| qsnames = set(qsnames) | ||
| else: | ||
| qsnames = set([f'{x} ({tube_ids_dict[x]})' for x in qsnames]) | ||
| snames = set(snames) | ||
| matching = qsnames.intersection(snames) | ||
| missing = qsnames.difference(snames) | ||
| extra = snames.difference(qsnames) | ||
|
|
||
| self.render("sample_validation.html", input=False, matching=matching, | ||
| missing=missing, extra=extra, blank=blank) | ||
| missing=missing, extra=extra, blank=blank, | ||
| duplicates=duplicates) | ||
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.
st is a not a properly descriptive name for a variable, especially one that plays an important role some ten lines later in the code.
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.
Would changing the variable name to
studywork better, or would a variable name likeqt_studybe more appropriate?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.
study is fine.