Mercurial > repos > shellac > guppy_basecaller
comparison env/lib/python3.7/site-packages/gxformat2/_labels.py @ 2:6af9afd405e9 draft
"planemo upload commit 0a63dd5f4d38a1f6944587f52a8cd79874177fc1"
| author | shellac |
|---|---|
| date | Thu, 14 May 2020 14:56:58 -0400 |
| parents | 26e78fe6e8c4 |
| children |
comparison
equal
deleted
inserted
replaced
| 1:75ca89e9b81c | 2:6af9afd405e9 |
|---|---|
| 1 """Utilities for handling unlabelled objects when translating workflow formats.""" | |
| 2 | |
| 3 | |
| 4 class Labels(object): | |
| 5 """Track labels assigned and generate anonymous ones.""" | |
| 6 | |
| 7 def __init__(self): | |
| 8 """Initialize labels that have been encountered or generated.""" | |
| 9 self.seen_labels = set() | |
| 10 self.anonymous_labels = 0 | |
| 11 | |
| 12 def ensure_new_output_label(self, label): | |
| 13 """Ensure supplied label has value or generate an anonymous one.""" | |
| 14 if label is None: | |
| 15 self.anonymous_labels += 1 | |
| 16 label = "_anonymous_output_%d" % self.anonymous_labels | |
| 17 assert label not in self.seen_labels | |
| 18 self.seen_labels.add(label) | |
| 19 return label | |
| 20 | |
| 21 @staticmethod | |
| 22 def is_anonymous_output_label(label): | |
| 23 """Predicate determining if supplied label was generated for anonymous output.""" | |
| 24 # label likely can't be null according to the schema definition - but we've got a test | |
| 25 # in Galaxy that doesn't define a label in order to great a .ga file without output | |
| 26 # labels (which is completely normal). | |
| 27 return not label or label.startswith("_anonymous_output_") |
