extensions/net.sf.basedb.reggie/trunk/src/net/sf/basedb/reggie/autoconfirm/StringTieAutoConfirmer.java

Code
Comments
Other
Rev Date Author Line
4670 05 Feb 18 nicklas 1 package net.sf.basedb.reggie.autoconfirm;
4670 05 Feb 18 nicklas 2
5942 18 May 20 nicklas 3 import java.util.ArrayList;
5670 15 Oct 19 nicklas 4 import java.util.Collections;
5922 27 Apr 20 nicklas 5 import java.util.List;
5670 15 Oct 19 nicklas 6
4670 05 Feb 18 nicklas 7 import net.sf.basedb.core.DbControl;
5922 27 Apr 20 nicklas 8 import net.sf.basedb.core.ItemList;
4670 05 Feb 18 nicklas 9 import net.sf.basedb.core.Job;
4670 05 Feb 18 nicklas 10 import net.sf.basedb.core.RawBioAssay;
4670 05 Feb 18 nicklas 11 import net.sf.basedb.core.SessionControl;
5384 26 Apr 19 nicklas 12 import net.sf.basedb.reggie.activity.ActivityDef;
4670 05 Feb 18 nicklas 13 import net.sf.basedb.reggie.dao.Annotationtype;
5922 27 Apr 20 nicklas 14 import net.sf.basedb.reggie.dao.BiomaterialList;
4670 05 Feb 18 nicklas 15 import net.sf.basedb.reggie.dao.Datafiletype;
4670 05 Feb 18 nicklas 16 import net.sf.basedb.reggie.dao.Rawbioassay;
5922 27 Apr 20 nicklas 17 import net.sf.basedb.reggie.ssp.SspModel;
5922 27 Apr 20 nicklas 18 import net.sf.basedb.reggie.ssp.SspPlugin;
4670 05 Feb 18 nicklas 19
4670 05 Feb 18 nicklas 20 /**
4670 05 Feb 18 nicklas 21   Auto-confirm implementation for raw bioassays after StringTie has been run.
4670 05 Feb 18 nicklas 22   The rules are simple:
4670 05 Feb 18 nicklas 23   
4670 05 Feb 18 nicklas 24    * {@link RawBioAssay#getJob()} job status must be {@link net.sf.basedb.core.Job.Status#DONE}.
4670 05 Feb 18 nicklas 25    * A {@link Datafiletype#GENERIC_RAWDATA} file must be attached to the {@link RawBioAssay}.
4670 05 Feb 18 nicklas 26    * The {@link RawBioAssay#getNumFileSpots()} must have a value greater than 0.
4670 05 Feb 18 nicklas 27   
5922 27 Apr 20 nicklas 28   Since 4.27:
5922 27 Apr 20 nicklas 29   Auto-confirmation will then continue with running the SSP plug-in for all configured models.
5670 15 Oct 19 nicklas 30
4670 05 Feb 18 nicklas 31   @author nicklas
4670 05 Feb 18 nicklas 32   @since 4.15
4670 05 Feb 18 nicklas 33 */
4670 05 Feb 18 nicklas 34 public class StringTieAutoConfirmer 
4670 05 Feb 18 nicklas 35   extends AutoConfirmer<RawBioAssay> 
4670 05 Feb 18 nicklas 36 {
4670 05 Feb 18 nicklas 37   
4670 05 Feb 18 nicklas 38   public StringTieAutoConfirmer(RawBioAssay raw)
4670 05 Feb 18 nicklas 39   {
4670 05 Feb 18 nicklas 40     super(raw, raw.getJob());
4670 05 Feb 18 nicklas 41   }
4670 05 Feb 18 nicklas 42
4670 05 Feb 18 nicklas 43   /**
4670 05 Feb 18 nicklas 44     Passes if the rules described above are ok.
4670 05 Feb 18 nicklas 45   */
4670 05 Feb 18 nicklas 46   @Override
4670 05 Feb 18 nicklas 47   public boolean checkRules(DbControl dc, AutoConfirmManager manager) 
4670 05 Feb 18 nicklas 48   {
4670 05 Feb 18 nicklas 49     RawBioAssay raw = item(dc);
4670 05 Feb 18 nicklas 50     Job job = raw.getJob();
4670 05 Feb 18 nicklas 51     
4670 05 Feb 18 nicklas 52     if (job.getStatus() != Job.Status.DONE) return false;
4670 05 Feb 18 nicklas 53
4670 05 Feb 18 nicklas 54     if (raw.getNumFileSpots() == 0) return false;
4670 05 Feb 18 nicklas 55
4670 05 Feb 18 nicklas 56     if (Datafiletype.GENERIC_RAWDATA.getFile(dc, raw) == null) return false;
4670 05 Feb 18 nicklas 57     
4670 05 Feb 18 nicklas 58     return true;
4670 05 Feb 18 nicklas 59   }
4670 05 Feb 18 nicklas 60
4670 05 Feb 18 nicklas 61   /**
4670 05 Feb 18 nicklas 62     If we get here, the result should be accepted
4670 05 Feb 18 nicklas 63   */
4670 05 Feb 18 nicklas 64   @Override
4670 05 Feb 18 nicklas 65   public boolean autoConfirm(DbControl dc, AutoConfirmManager manager) 
4670 05 Feb 18 nicklas 66   {
4670 05 Feb 18 nicklas 67     RawBioAssay raw = item(dc);
4670 05 Feb 18 nicklas 68     Annotationtype.ANALYSIS_RESULT.setAnnotationValue(dc, raw, Rawbioassay.FEATURE_EXTRACTION_SUCCESSFUL);
5922 27 Apr 20 nicklas 69     BiomaterialList.SSP_PIPELINE.load(dc).add(raw);
5421 13 May 19 nicklas 70     ActivityDef.STRINGTIE_AUTOCONFIRMED.merge(dc, 1).setUser("Auto-confirm");
4670 05 Feb 18 nicklas 71     return true;
4670 05 Feb 18 nicklas 72   }
4670 05 Feb 18 nicklas 73
4670 05 Feb 18 nicklas 74   /**
5922 27 Apr 20 nicklas 75     Register a job for running the SSP analysis plug-in.
4670 05 Feb 18 nicklas 76   */
4670 05 Feb 18 nicklas 77   @Override
4670 05 Feb 18 nicklas 78   public boolean startNextStep(SessionControl sc, AutoConfirmManager manager)
4670 05 Feb 18 nicklas 79   {
5670 15 Oct 19 nicklas 80     DbControl dc = null;
5670 15 Oct 19 nicklas 81     try
5670 15 Oct 19 nicklas 82     {
6599 22 Feb 22 nicklas 83       dc = sc.newDbControl("Reggie: Auto-confirm StringTie - start SSP");
5670 15 Oct 19 nicklas 84       RawBioAssay raw = item(dc);
5922 27 Apr 20 nicklas 85
5922 27 Apr 20 nicklas 86       // Pipelines for further processing
5922 27 Apr 20 nicklas 87       ItemList sspPipeline = BiomaterialList.SSP_PIPELINE.load(dc);
5922 27 Apr 20 nicklas 88       boolean sspDisabled = "Disable".equals(Annotationtype.AUTO_PROCESSING.getAnnotationValue(dc, sspPipeline));
5670 15 Oct 19 nicklas 89       
5922 27 Apr 20 nicklas 90       if (sspDisabled) return false;
5670 15 Oct 19 nicklas 91       
5942 18 May 20 nicklas 92       List<String> models = new ArrayList<String>();
5942 18 May 20 nicklas 93       for (SspModel m : SspModel.getValidModels(dc))
5942 18 May 20 nicklas 94       {
5942 18 May 20 nicklas 95         models.add(m.getName());
5942 18 May 20 nicklas 96       }
5942 18 May 20 nicklas 97       if (models.isEmpty()) return false;
5922 27 Apr 20 nicklas 98       
6025 26 Oct 20 nicklas 99       SspPlugin.createAnalysisJob(dc, Collections.singletonList(raw), models, true);
5670 15 Oct 19 nicklas 100       dc.commit();
5670 15 Oct 19 nicklas 101     }
5670 15 Oct 19 nicklas 102     finally
5670 15 Oct 19 nicklas 103     {
5670 15 Oct 19 nicklas 104       if (dc != null) dc.close();
5670 15 Oct 19 nicklas 105     }
5670 15 Oct 19 nicklas 106     return true;
4670 05 Feb 18 nicklas 107   }
4670 05 Feb 18 nicklas 108
4670 05 Feb 18 nicklas 109 }