|
21 | 21 | import org.apache.commons.lang3.StringUtils; |
22 | 22 | import org.apache.logging.log4j.LogManager; |
23 | 23 | import org.apache.logging.log4j.Logger; |
| 24 | +import org.jetbrains.annotations.NotNull; |
24 | 25 | import org.json.JSONArray; |
| 26 | +import org.json.JSONObject; |
25 | 27 | import org.labkey.api.action.ApiResponse; |
26 | 28 | import org.labkey.api.action.ApiSimpleResponse; |
27 | 29 | import org.labkey.api.action.ApiUsageException; |
| 30 | +import org.labkey.api.action.ConfirmAction; |
28 | 31 | import org.labkey.api.action.ExportAction; |
29 | 32 | import org.labkey.api.action.MutatingApiAction; |
30 | 33 | import org.labkey.api.action.ReadOnlyApiAction; |
|
45 | 48 | import org.labkey.api.module.Module; |
46 | 49 | import org.labkey.api.module.ModuleHtmlView; |
47 | 50 | import org.labkey.api.module.ModuleLoader; |
| 51 | +import org.labkey.api.pipeline.PipelineJobException; |
48 | 52 | import org.labkey.api.query.BatchValidationException; |
49 | 53 | import org.labkey.api.query.FieldKey; |
50 | 54 | import org.labkey.api.query.QueryService; |
|
58 | 62 | import org.labkey.api.sequenceanalysis.pipeline.PipelineStepProvider; |
59 | 63 | import org.labkey.api.sequenceanalysis.pipeline.SequencePipelineService; |
60 | 64 | import org.labkey.api.util.FileUtil; |
| 65 | +import org.labkey.api.util.HtmlString; |
61 | 66 | import org.labkey.api.util.JsonUtil; |
62 | 67 | import org.labkey.api.util.PageFlowUtil; |
63 | 68 | import org.labkey.api.util.Path; |
64 | 69 | import org.labkey.api.util.URLHelper; |
| 70 | +import org.labkey.api.view.HtmlView; |
65 | 71 | import org.labkey.api.view.NavTree; |
66 | 72 | import org.labkey.api.view.template.ClientDependency; |
| 73 | +import org.labkey.singlecell.analysis.AbstractSingleCellHandler; |
67 | 74 | import org.labkey.singlecell.run.CellRangerWrapper; |
68 | 75 | import org.springframework.validation.BindException; |
| 76 | +import org.springframework.validation.Errors; |
69 | 77 | import org.springframework.web.servlet.ModelAndView; |
70 | 78 |
|
71 | 79 | import java.io.File; |
@@ -558,4 +566,94 @@ public void setCombineHashingCite(boolean combineHashingCite) |
558 | 566 | _combineHashingCite = combineHashingCite; |
559 | 567 | } |
560 | 568 | } |
| 569 | + |
| 570 | + @RequiresPermission(AdminPermission.class) |
| 571 | + public static class UpdatePrototypeDescriptionsAction extends ConfirmAction<Object> |
| 572 | + { |
| 573 | + @Override |
| 574 | + public void validateCommand(Object form, Errors errors) |
| 575 | + { |
| 576 | + |
| 577 | + } |
| 578 | + |
| 579 | + @Override |
| 580 | + public @NotNull URLHelper getSuccessURL(Object form) |
| 581 | + { |
| 582 | + return getContainer().getStartURL(getUser()); |
| 583 | + } |
| 584 | + |
| 585 | + @Override |
| 586 | + public ModelAndView getConfirmView(Object form, BindException errors) throws Exception |
| 587 | + { |
| 588 | + return new HtmlView(HtmlString.unsafe("This will update the description field for all seurat prototypes. Do you want to continue?")); |
| 589 | + } |
| 590 | + |
| 591 | + @Override |
| 592 | + public boolean handlePost(Object form, BindException errors) throws Exception |
| 593 | + { |
| 594 | + UserSchema sa = QueryService.get().getUserSchema(getUser(), getContainer(), SingleCellSchema.SEQUENCE_SCHEMA_NAME); |
| 595 | + new TableSelector(sa.getTable("outputfiles"), PageFlowUtil.set("rowid"), new SimpleFilter(FieldKey.fromString("category"), "Seurat Object Prototype"), null).forEach(Integer.class, rowId -> { |
| 596 | + SequenceOutputFile so = SequenceOutputFile.getForId(rowId); |
| 597 | + if (so == null) |
| 598 | + { |
| 599 | + throw new IllegalStateException("Unable to create SequenceOutputFile for: " + rowId); |
| 600 | + } |
| 601 | + |
| 602 | + try |
| 603 | + { |
| 604 | + JSONObject params = new JSONObject(); |
| 605 | + |
| 606 | + String oldDescription = so.getDescription(); |
| 607 | + if (oldDescription.contains("SoupX: true")) |
| 608 | + { |
| 609 | + params.put("singleCellRawData.PrepareRawCounts.useSoupX", true); |
| 610 | + } |
| 611 | + |
| 612 | + if (oldDescription.contains("Hashing: ")) |
| 613 | + { |
| 614 | + List<String> matching = Arrays.stream(oldDescription.split("\n")).filter(x -> x.contains("Hashing: ")).toList(); |
| 615 | + if (!matching.isEmpty()) |
| 616 | + { |
| 617 | + if (matching.size() == 1) |
| 618 | + { |
| 619 | + params.put("singleCell.RunCellHashing.consensusMethods", matching.get(0).replaceFirst("Hashing: ", "")); |
| 620 | + } |
| 621 | + else |
| 622 | + { |
| 623 | + _log.error("Expected single match for Hashing on rowId: "+ rowId); |
| 624 | + } |
| 625 | + } |
| 626 | + } |
| 627 | + |
| 628 | + if (oldDescription.contains("Cite-seq Normalization: ")) |
| 629 | + { |
| 630 | + List<String> matching = Arrays.stream(oldDescription.split("\n")).filter(x -> x.contains("Cite-seq Normalization: ")).toList(); |
| 631 | + if (!matching.isEmpty()) |
| 632 | + { |
| 633 | + if (matching.size() == 1) |
| 634 | + { |
| 635 | + params.put("singleCell.AppendCiteSeq.normalizeMethod", matching.get(0).replaceFirst("Cite-seq Normalization: ", "")); |
| 636 | + } |
| 637 | + else |
| 638 | + { |
| 639 | + _log.error("Expected single match for Cite-seq Normalization on rowId: "+ rowId); |
| 640 | + } |
| 641 | + } |
| 642 | + } |
| 643 | + |
| 644 | + String description = AbstractSingleCellHandler.getOutputDescription(params, _log, so.getFile(), null); |
| 645 | + so.setDescription(description); |
| 646 | + |
| 647 | + _log.info(rowId); |
| 648 | + _log.info(description); |
| 649 | + } |
| 650 | + catch (PipelineJobException e) |
| 651 | + { |
| 652 | + _log.error("Error generating description for: " + rowId, e); |
| 653 | + } |
| 654 | + }); |
| 655 | + |
| 656 | + return true; |
| 657 | + } |
| 658 | + } |
561 | 659 | } |
0 commit comments