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

Code
Comments
Other
Rev Date Author Line
3034 12 Dec 14 nicklas 1 package net.sf.basedb.reggie.autoconfirm;
3034 12 Dec 14 nicklas 2
3034 12 Dec 14 nicklas 3 import java.util.Iterator;
3070 09 Jan 15 nicklas 4 import java.util.List;
3034 12 Dec 14 nicklas 5
3070 09 Jan 15 nicklas 6 import org.slf4j.LoggerFactory;
3070 09 Jan 15 nicklas 7
4602 29 Sep 17 nicklas 8 import net.sf.basedb.core.Annotatable;
3034 12 Dec 14 nicklas 9 import net.sf.basedb.core.DbControl;
3034 12 Dec 14 nicklas 10 import net.sf.basedb.core.DerivedBioAssay;
4599 28 Sep 17 nicklas 11 import net.sf.basedb.core.ItemList;
3034 12 Dec 14 nicklas 12 import net.sf.basedb.core.ItemQuery;
3034 12 Dec 14 nicklas 13 import net.sf.basedb.core.ItemSubtype;
3034 12 Dec 14 nicklas 14 import net.sf.basedb.core.Job;
3070 09 Jan 15 nicklas 15 import net.sf.basedb.core.Protocol;
3055 19 Dec 14 nicklas 16 import net.sf.basedb.core.SessionControl;
3070 09 Jan 15 nicklas 17 import net.sf.basedb.core.Software;
3724 27 Jan 16 nicklas 18 import net.sf.basedb.core.query.Annotations;
3724 27 Jan 16 nicklas 19 import net.sf.basedb.core.query.Expressions;
3034 12 Dec 14 nicklas 20 import net.sf.basedb.core.query.Hql;
3034 12 Dec 14 nicklas 21 import net.sf.basedb.core.query.Restrictions;
4599 28 Sep 17 nicklas 22 import net.sf.basedb.opengrid.JobDefinition;
4306 17 Jan 17 nicklas 23 import net.sf.basedb.opengrid.OpenGridCluster;
6674 11 Apr 22 nicklas 24 import net.sf.basedb.opengrid.config.BatchConfig;
4306 17 Jan 17 nicklas 25 import net.sf.basedb.opengrid.service.OpenGridService;
3034 12 Dec 14 nicklas 26 import net.sf.basedb.reggie.Reggie;
5384 26 Apr 19 nicklas 27 import net.sf.basedb.reggie.activity.ActivityDef;
3034 12 Dec 14 nicklas 28 import net.sf.basedb.reggie.dao.Annotationtype;
4547 29 Jun 17 nicklas 29 import net.sf.basedb.reggie.dao.Arraydesign;
4599 28 Sep 17 nicklas 30 import net.sf.basedb.reggie.dao.BiomaterialList;
3049 17 Dec 14 nicklas 31 import net.sf.basedb.reggie.dao.DemuxedSequences;
3070 09 Jan 15 nicklas 32 import net.sf.basedb.reggie.dao.MergedSequences;
5494 14 Jun 19 nicklas 33 import net.sf.basedb.reggie.dao.Pipeline;
4667 01 Feb 18 nicklas 34 import net.sf.basedb.reggie.dao.Rawdatatype;
3049 17 Dec 14 nicklas 35 import net.sf.basedb.reggie.dao.Rna;
3034 12 Dec 14 nicklas 36 import net.sf.basedb.reggie.dao.Subtype;
4547 29 Jun 17 nicklas 37 import net.sf.basedb.reggie.grid.CufflinksJobCreator;
6814 26 Aug 22 nicklas 38 import net.sf.basedb.reggie.grid.Hisat2023AlignJobCreator;
4599 28 Sep 17 nicklas 39 import net.sf.basedb.reggie.grid.HisatAlignJobCreator;
4599 28 Sep 17 nicklas 40 import net.sf.basedb.reggie.grid.ScriptUtil;
7077 27 Mar 23 nicklas 41 import net.sf.basedb.util.extensions.logging.ExtensionsLog;
7077 27 Mar 23 nicklas 42 import net.sf.basedb.util.extensions.logging.ExtensionsLogger;
4602 29 Sep 17 nicklas 43 import net.sf.basedb.util.filter.Filter;
3034 12 Dec 14 nicklas 44
3034 12 Dec 14 nicklas 45 /**
3034 12 Dec 14 nicklas 46   Auto-confirm implementation for demuxed sequences. The base item
3034 12 Dec 14 nicklas 47   is a job since there are typically multiple demuxed sequences
3034 12 Dec 14 nicklas 48   in a single job.
3034 12 Dec 14 nicklas 49
3034 12 Dec 14 nicklas 50   The rules are:
3034 12 Dec 14 nicklas 51   
3571 30 Oct 15 nicklas 52      * {@link Job#getStatus()} job status must be {@link net.sf.basedb.core.Job.Status#DONE}.
3034 12 Dec 14 nicklas 53     * {@link Annotationtype#DEMUX_WARNINGS} must be empty for all demuxed sequences
3034 12 Dec 14 nicklas 54     * {@link Annotationtype#PT_READS} must be >10M for all merged sequences
3034 12 Dec 14 nicklas 55     * {@link Annotationtype#FRAGMENT_SIZE_AVG} and {@link Annotationtype#FRAGMENT_SIZE_STDEV}
3034 12 Dec 14 nicklas 56       must be >0 for all merged sequences
3034 12 Dec 14 nicklas 57   
3724 27 Jan 16 nicklas 58   The first two rules are hard rules that must be met or all libraries will be stopped.
3724 27 Jan 16 nicklas 59   The last two rules are applied per library and only those libraries that doesn't pass
3724 27 Jan 16 nicklas 60   are stopped. The {@link Annotationtype#ANALYSIS_RESULT} on the demuxed sequences
3724 27 Jan 16 nicklas 61   can take the following values:
3724 27 Jan 16 nicklas 62   
3724 27 Jan 16 nicklas 63     * null: If no libraries pass
3724 27 Jan 16 nicklas 64     * Partial: If some but not all libraries pass
3724 27 Jan 16 nicklas 65     * Successful: If all libraries pass
3724 27 Jan 16 nicklas 66   
4547 29 Jun 17 nicklas 67   Auto-confirmation will then continue with Tophat alignment and Cufflinks for all passed 
4547 29 Jun 17 nicklas 68   libraries that are not external and not stratagene.
3049 17 Dec 14 nicklas 69   
3034 12 Dec 14 nicklas 70   @author nicklas
3045 16 Dec 14 nicklas 71   @since 3.0
3034 12 Dec 14 nicklas 72 */
3034 12 Dec 14 nicklas 73 public class DemuxAutoConfirmer 
3034 12 Dec 14 nicklas 74   extends AutoConfirmer<Job>
3034 12 Dec 14 nicklas 75 {
3070 09 Jan 15 nicklas 76   
7077 27 Mar 23 nicklas 77   private static final ExtensionsLogger logger = 
7077 27 Mar 23 nicklas 78     ExtensionsLog.getLogger(AutoConfirmService.ID, true).wrap(LoggerFactory.getLogger(DemuxAutoConfirmer.class));
3034 12 Dec 14 nicklas 79   
3049 17 Dec 14 nicklas 80   /**
3049 17 Dec 14 nicklas 81     At least 10 million reads passed trimmomatic is required for
3049 17 Dec 14 nicklas 82     auto-confirmation.
3049 17 Dec 14 nicklas 83   */
3049 17 Dec 14 nicklas 84   public static final long MIN_PT_READS = 10*M;
3034 12 Dec 14 nicklas 85   
3049 17 Dec 14 nicklas 86   /**
3049 17 Dec 14 nicklas 87     At least 250k reads passed trimmomatic is required when debugging.
3049 17 Dec 14 nicklas 88   */
3049 17 Dec 14 nicklas 89   public static final long MIN_PT_READS_DEBUG = 250*k;
3049 17 Dec 14 nicklas 90   
3034 12 Dec 14 nicklas 91   public DemuxAutoConfirmer(Job job)
3034 12 Dec 14 nicklas 92   {
3055 19 Dec 14 nicklas 93     super(job, job);
3034 12 Dec 14 nicklas 94   }
3034 12 Dec 14 nicklas 95
3034 12 Dec 14 nicklas 96   @Override
3049 17 Dec 14 nicklas 97   public boolean checkRules(DbControl dc, AutoConfirmManager manager) 
3034 12 Dec 14 nicklas 98   {
3034 12 Dec 14 nicklas 99     Job job = item(dc);
3034 12 Dec 14 nicklas 100     if (job.getStatus() != Job.Status.DONE) return false;
3034 12 Dec 14 nicklas 101     
3724 27 Jan 16 nicklas 102     // Get all DemuxedSequences items
3034 12 Dec 14 nicklas 103     ItemQuery<DerivedBioAssay> query = DerivedBioAssay.getQuery();
3724 27 Jan 16 nicklas 104     Subtype.DEMUXED_SEQUENCES.addFilter(dc, query);
3034 12 Dec 14 nicklas 105     query.setIncludes(Reggie.INCLUDE_IN_CURRENT_PROJECT);
3034 12 Dec 14 nicklas 106     query.restrict(Restrictions.eq(Hql.property("job"), Hql.entity(job)));
3034 12 Dec 14 nicklas 107
3724 27 Jan 16 nicklas 108     // The demux passes if there are no warnings on the demuxed sequences items
3034 12 Dec 14 nicklas 109     boolean passes = true;
3034 12 Dec 14 nicklas 110     Iterator<DerivedBioAssay> it = query.iterate(dc);
3034 12 Dec 14 nicklas 111     while (passes && it.hasNext())
3034 12 Dec 14 nicklas 112     {
3034 12 Dec 14 nicklas 113       DerivedBioAssay dba = it.next();
3724 27 Jan 16 nicklas 114       passes = Annotationtype.DEMUX_WARNINGS.getAnnotationValues(dc, dba).isEmpty();
3034 12 Dec 14 nicklas 115     }
3034 12 Dec 14 nicklas 116     
3034 12 Dec 14 nicklas 117     return passes;
3034 12 Dec 14 nicklas 118   }
3049 17 Dec 14 nicklas 119
3049 17 Dec 14 nicklas 120   @Override
3049 17 Dec 14 nicklas 121   public boolean autoConfirm(DbControl dc, AutoConfirmManager manager) 
3049 17 Dec 14 nicklas 122   {
3049 17 Dec 14 nicklas 123     Job job = item(dc);
3049 17 Dec 14 nicklas 124     
5494 14 Jun 19 nicklas 125     // TODO -- implement support for auto-confirming MIPs demux
5494 14 Jun 19 nicklas 126     Pipeline pipeline = Pipeline.getByCName(job.getParameterValue("pipeline"));
5494 14 Jun 19 nicklas 127     if (pipeline != Pipeline.RNA_SEQ) return false;
5494 14 Jun 19 nicklas 128     
3049 17 Dec 14 nicklas 129     ItemSubtype demuxType = Subtype.DEMUXED_SEQUENCES.get(dc);
3049 17 Dec 14 nicklas 130     ItemSubtype mergeType = Subtype.MERGED_SEQUENCES.get(dc);
3724 27 Jan 16 nicklas 131
4599 28 Sep 17 nicklas 132     // Pipelines for further processing
4599 28 Sep 17 nicklas 133     ItemList hisatPipeline = BiomaterialList.HISAT_PIPELINE.load(dc);
6811 25 Aug 22 nicklas 134     ItemList hisat2023Pipeline = BiomaterialList.HISAT_2023_PIPELINE.load(dc);
4599 28 Sep 17 nicklas 135     ItemList legacyPipeline = BiomaterialList.LEGACY_PIPELINE.load(dc);
4599 28 Sep 17 nicklas 136
3724 27 Jan 16 nicklas 137     boolean debug = Boolean.TRUE.equals(job.getParameterValue("debug"));
3724 27 Jan 16 nicklas 138     long minPtReads = debug ? MIN_PT_READS_DEBUG : MIN_PT_READS;
3724 27 Jan 16 nicklas 139
3724 27 Jan 16 nicklas 140     // Get all MergedSequences items
3049 17 Dec 14 nicklas 141     ItemQuery<DerivedBioAssay> query = DerivedBioAssay.getQuery();
3049 17 Dec 14 nicklas 142     query.setIncludes(Reggie.INCLUDE_IN_CURRENT_PROJECT);
3049 17 Dec 14 nicklas 143     query.restrict(Restrictions.eq(Hql.property("job"), Hql.entity(job)));
3724 27 Jan 16 nicklas 144     Subtype.MERGED_SEQUENCES.addFilter(dc, query);
3049 17 Dec 14 nicklas 145
3049 17 Dec 14 nicklas 146     Iterator<DerivedBioAssay> it = query.iterate(dc);
3724 27 Jan 16 nicklas 147     int numMerged = 0;
3724 27 Jan 16 nicklas 148     int numMergedPassed = 0;
3049 17 Dec 14 nicklas 149     while (it.hasNext())
3049 17 Dec 14 nicklas 150     {
3724 27 Jan 16 nicklas 151       numMerged++;
3049 17 Dec 14 nicklas 152       DerivedBioAssay dba = it.next();
3724 27 Jan 16 nicklas 153       Long ptReads = (Long)Annotationtype.PT_READS.getAnnotationValue(dc, dba);
3724 27 Jan 16 nicklas 154       Integer fragmentSizeAvg = (Integer)Annotationtype.FRAGMENT_SIZE_AVG.getAnnotationValue(dc, dba);
3724 27 Jan 16 nicklas 155       Integer fragmentSizeStd = (Integer)Annotationtype.FRAGMENT_SIZE_STDEV.getAnnotationValue(dc, dba);
3724 27 Jan 16 nicklas 156         
3724 27 Jan 16 nicklas 157       boolean passes = ptReads != null && fragmentSizeAvg != null && fragmentSizeStd != null;
3724 27 Jan 16 nicklas 158       passes &= ptReads > minPtReads;
3724 27 Jan 16 nicklas 159       passes &= fragmentSizeAvg > 0;
3724 27 Jan 16 nicklas 160       passes &= fragmentSizeStd > 0;
3724 27 Jan 16 nicklas 161         
3724 27 Jan 16 nicklas 162       if (passes)
3049 17 Dec 14 nicklas 163       {
3049 17 Dec 14 nicklas 164         Annotationtype.ANALYSIS_RESULT.setAnnotationValue(dc, dba, DemuxedSequences.DEMUX_SUCCESSFUL);
5553 12 Aug 19 nicklas 165         boolean isStratagene = Rna.isStratagene(dba.getName());
5553 12 Aug 19 nicklas 166         Annotationtype.AUTO_PROCESSING.setAnnotationValue(dc, dba, isStratagene ? "Disable" : null);
5553 12 Aug 19 nicklas 167         if (!isStratagene)
4599 28 Sep 17 nicklas 168         {
4599 28 Sep 17 nicklas 169           // Add to pipeline processing lists
4599 28 Sep 17 nicklas 170           // Not really needed for auto-confirm, but in case startNextStep() fails
4599 28 Sep 17 nicklas 171           // we want the bioassays to show up in the manual lists
4599 28 Sep 17 nicklas 172           hisatPipeline.add(dba);
6809 24 Aug 22 nicklas 173           hisat2023Pipeline.add(dba);
4599 28 Sep 17 nicklas 174           legacyPipeline.add(dba);
4599 28 Sep 17 nicklas 175         }
3724 27 Jan 16 nicklas 176         numMergedPassed++;
3049 17 Dec 14 nicklas 177       }
3724 27 Jan 16 nicklas 178     }
3724 27 Jan 16 nicklas 179     
3724 27 Jan 16 nicklas 180     if (numMergedPassed > 0)
3724 27 Jan 16 nicklas 181     {
5580 20 Aug 19 nicklas 182       ActivityDef.DEMUX_AUTOCONFIRMED.merge(dc, pipeline.getName(), numMergedPassed).setUser("Auto-confirm");
5384 26 Apr 19 nicklas 183       
3724 27 Jan 16 nicklas 184       // If all libs passed we set AnalysisResult=Successful otherwise we set AnalysisResult=Partial
3724 27 Jan 16 nicklas 185       String analysisResult = numMerged > numMergedPassed ? DemuxedSequences.DEMUX_PARTIAL : DemuxedSequences.DEMUX_SUCCESSFUL;
3724 27 Jan 16 nicklas 186       
3724 27 Jan 16 nicklas 187       // Get all DemuxedSequences items
3724 27 Jan 16 nicklas 188       query = DerivedBioAssay.getQuery();
3724 27 Jan 16 nicklas 189       query.setIncludes(Reggie.INCLUDE_IN_CURRENT_PROJECT);
3724 27 Jan 16 nicklas 190       query.restrict(Restrictions.eq(Hql.property("job"), Hql.entity(job)));
3724 27 Jan 16 nicklas 191       Subtype.DEMUXED_SEQUENCES.addFilter(dc, query);
3724 27 Jan 16 nicklas 192       
3724 27 Jan 16 nicklas 193       it = query.iterate(dc);
3724 27 Jan 16 nicklas 194       while (it.hasNext())
3049 17 Dec 14 nicklas 195       {
3724 27 Jan 16 nicklas 196         DerivedBioAssay dba = it.next();
3724 27 Jan 16 nicklas 197         Annotationtype.ANALYSIS_RESULT.setAnnotationValue(dc, dba, analysisResult);
3724 27 Jan 16 nicklas 198         Annotationtype.AUTO_PROCESSING.setAnnotationValue(dc, dba, null);
3049 17 Dec 14 nicklas 199       }
3049 17 Dec 14 nicklas 200     }
3049 17 Dec 14 nicklas 201     
3724 27 Jan 16 nicklas 202     // Move on to the next step if at least one library passed
3724 27 Jan 16 nicklas 203     return numMergedPassed > 0;
3049 17 Dec 14 nicklas 204   }
3055 19 Dec 14 nicklas 205
3055 19 Dec 14 nicklas 206   @Override
3055 19 Dec 14 nicklas 207   public boolean startNextStep(SessionControl sc, AutoConfirmManager manager) 
3055 19 Dec 14 nicklas 208   {
3070 09 Jan 15 nicklas 209     DbControl dc = null;
3070 09 Jan 15 nicklas 210     try
3070 09 Jan 15 nicklas 211     {
6599 22 Feb 22 nicklas 212       dc = sc.newDbControl("Reggie: Auto-confirm demux");
3070 09 Jan 15 nicklas 213       
3070 09 Jan 15 nicklas 214       Job job = item(dc);
3070 09 Jan 15 nicklas 215       
3724 27 Jan 16 nicklas 216       // Get all merged sequences from this job that have AnalysisResult=Successful
3070 09 Jan 15 nicklas 217       ItemQuery<DerivedBioAssay> query = DerivedBioAssay.getQuery();
3070 09 Jan 15 nicklas 218       Subtype.MERGED_SEQUENCES.addFilter(dc, query);
3070 09 Jan 15 nicklas 219       query.setIncludes(Reggie.INCLUDE_IN_CURRENT_PROJECT);
3070 09 Jan 15 nicklas 220       query.restrict(Restrictions.eq(Hql.property("job"), Hql.entity(job)));
3724 27 Jan 16 nicklas 221       // AnalysisResult==Successful
3724 27 Jan 16 nicklas 222       query.join(Annotations.leftJoin(null, Annotationtype.ANALYSIS_RESULT.load(dc), "ar"));
3724 27 Jan 16 nicklas 223       query.restrict(Restrictions.eq(Hql.alias("ar"), Expressions.string(DemuxedSequences.DEMUX_SUCCESSFUL)));
3070 09 Jan 15 nicklas 224       List<MergedSequences> mergedSequences = MergedSequences.toList(query.list(dc));
3724 27 Jan 16 nicklas 225       
3724 27 Jan 16 nicklas 226       if (mergedSequences.size() == 0) return false;
3070 09 Jan 15 nicklas 227
3070 09 Jan 15 nicklas 228       boolean debug = Boolean.TRUE.equals(job.getParameterValue("debug"));
3071 12 Jan 15 nicklas 229       Integer priority = (Integer)job.getParameterValue("priority");
6982 17 Jan 23 nicklas 230       String partition = job.getParameterValue("partition");
6982 17 Jan 23 nicklas 231     
4306 17 Jan 17 nicklas 232       String clusterId = job.getServer();
4306 17 Jan 17 nicklas 233       OpenGridCluster cluster = OpenGridService.getInstance().getClusterById(dc, clusterId);
3070 09 Jan 15 nicklas 234       if (cluster == null)
3070 09 Jan 15 nicklas 235       {
3070 09 Jan 15 nicklas 236         // If we don't have required items, abort and revert to manual start
3070 09 Jan 15 nicklas 237         return false;
3070 09 Jan 15 nicklas 238       }
4624 17 Nov 17 nicklas 239       
4624 17 Nov 17 nicklas 240       // Pipelines for further processing
4624 17 Nov 17 nicklas 241       ItemList hisatPipeline = BiomaterialList.HISAT_PIPELINE.load(dc);
4624 17 Nov 17 nicklas 242       boolean hisatDisabled = "Disable".equals(Annotationtype.AUTO_PROCESSING.getAnnotationValue(dc, hisatPipeline));
6811 25 Aug 22 nicklas 243       ItemList hisat2023Pipeline = BiomaterialList.HISAT_2023_PIPELINE.load(dc);
6809 24 Aug 22 nicklas 244       boolean hisat2023Disabled = "Disable".equals(Annotationtype.AUTO_PROCESSING.getAnnotationValue(dc, hisat2023Pipeline));
4624 17 Nov 17 nicklas 245       ItemList legacyPipeline = BiomaterialList.LEGACY_PIPELINE.load(dc);
4624 17 Nov 17 nicklas 246       boolean legacyDisabled = "Disable".equals(Annotationtype.AUTO_PROCESSING.getAnnotationValue(dc, legacyPipeline));
4624 17 Nov 17 nicklas 247       
6809 24 Aug 22 nicklas 248       if (legacyDisabled && hisatDisabled && hisat2023Disabled) return false;
4624 17 Nov 17 nicklas 249       
4623 17 Nov 17 nicklas 250       dc.close();
6674 11 Apr 22 nicklas 251
6674 11 Apr 22 nicklas 252       BatchConfig batchConfig = new BatchConfig();
6436 07 Oct 21 nicklas 253       if (!hisatDisabled)
4623 17 Nov 17 nicklas 254       {
6436 07 Oct 21 nicklas 255         // Create Hisat jobs
4624 17 Nov 17 nicklas 256         try
4623 17 Nov 17 nicklas 257         {
6599 22 Feb 22 nicklas 258           dc = sc.newDbControl("Reggie: Auto-confirm demux - start Hisat pipeline");
6635 09 Mar 22 nicklas 259           // Select a cluster that has been configured for Hisat
6635 09 Mar 22 nicklas 260           OpenGridCluster hisatCluster = ScriptUtil.autoSelectClusterWithConfig(dc, "align-hisat", cluster);
6982 17 Jan 23 nicklas 261           submitHisatJobs(dc, mergedSequences, hisatCluster, batchConfig, debug, priority, cluster == hisatCluster ? partition : null);
4624 17 Nov 17 nicklas 262           dc.commit();
4623 17 Nov 17 nicklas 263         }
4624 17 Nov 17 nicklas 264         catch (RuntimeException ex)
4624 17 Nov 17 nicklas 265         {
6436 07 Oct 21 nicklas 266           logger.error("Could not create Hisat jobs", ex);
4624 17 Nov 17 nicklas 267         }
4623 17 Nov 17 nicklas 268       }
3070 09 Jan 15 nicklas 269       
6809 24 Aug 22 nicklas 270       if (!hisat2023Disabled)
6809 24 Aug 22 nicklas 271       {
6809 24 Aug 22 nicklas 272         // Create Hisat2023 jobs
6809 24 Aug 22 nicklas 273         try
6809 24 Aug 22 nicklas 274         {
6809 24 Aug 22 nicklas 275           dc = sc.newDbControl("Reggie: Auto-confirm demux - start Hisat/2023 pipeline");
6809 24 Aug 22 nicklas 276           // Select a cluster that has been configured for Hisat
6811 25 Aug 22 nicklas 277           OpenGridCluster hisatCluster = ScriptUtil.autoSelectClusterWithConfig(dc, "align-hisat-2023", cluster);
6982 17 Jan 23 nicklas 278           submitHisat2023Jobs(dc, mergedSequences, hisatCluster, batchConfig, debug, priority, cluster == hisatCluster ? partition : null);
6809 24 Aug 22 nicklas 279           dc.commit();
6809 24 Aug 22 nicklas 280         }
6809 24 Aug 22 nicklas 281         catch (RuntimeException ex)
6809 24 Aug 22 nicklas 282         {
6809 24 Aug 22 nicklas 283           logger.error("Could not create Hisat/2023 jobs", ex);
6809 24 Aug 22 nicklas 284         }
6809 24 Aug 22 nicklas 285       }
6809 24 Aug 22 nicklas 286       
6436 07 Oct 21 nicklas 287       // Create Tophat/Cufflinks jobs
6436 07 Oct 21 nicklas 288       // We use separate transactions so that if one pipeline can fail without affecting the other
6436 07 Oct 21 nicklas 289       if (!legacyDisabled)
4623 17 Nov 17 nicklas 290       {
4624 17 Nov 17 nicklas 291         try
4623 17 Nov 17 nicklas 292         {
6599 22 Feb 22 nicklas 293           dc = sc.newDbControl("Reggie: Auto-confirm demux - start Legacy pipeline");
6675 13 Apr 22 nicklas 294           OpenGridCluster legacyCluster = ScriptUtil.autoSelectClusterWithConfig(dc, "legacy", cluster);
6982 17 Jan 23 nicklas 295           submitLegacyJobs(dc, mergedSequences, legacyCluster, batchConfig, debug, -1023, cluster == legacyCluster ? partition : null);
4624 17 Nov 17 nicklas 296           dc.commit();
4623 17 Nov 17 nicklas 297         }
4624 17 Nov 17 nicklas 298         catch (RuntimeException ex)
4624 17 Nov 17 nicklas 299         {
6436 07 Oct 21 nicklas 300           logger.error("Could not create Tophat/Cufflinks jobs", ex);
4624 17 Nov 17 nicklas 301         }
4623 17 Nov 17 nicklas 302       }
3070 09 Jan 15 nicklas 303     }
3070 09 Jan 15 nicklas 304     finally
3070 09 Jan 15 nicklas 305     {
3070 09 Jan 15 nicklas 306       if (dc != null) dc.close();
3070 09 Jan 15 nicklas 307     }
3070 09 Jan 15 nicklas 308     return true;
3055 19 Dec 14 nicklas 309   }
3034 12 Dec 14 nicklas 310   
6184 26 Mar 21 nicklas 311   
6982 17 Jan 23 nicklas 312   public static List<Job> submitLegacyJobs(DbControl dc, List<MergedSequences> mergedSequences, OpenGridCluster cluster, BatchConfig batchConfig, boolean debug, Integer priority, String partition)
6184 26 Mar 21 nicklas 313   {
6812 25 Aug 22 nicklas 314     Filter<Annotatable> legacyPipeline = Annotationtype.PIPELINE.createFilter(Pipeline.RNASEQ_LEGACY.getName());
6812 25 Aug 22 nicklas 315     Protocol maskingProtocol = (Protocol)Subtype.MASKING_PROTOCOL.getLatestProjectDefault(dc, legacyPipeline);
6812 25 Aug 22 nicklas 316     Software maskingSoftware = (Software)Subtype.MASKING_SOFTWARE.getLatestProjectDefault(dc, legacyPipeline);
6812 25 Aug 22 nicklas 317     Protocol tophatAlignProtocol = (Protocol)Subtype.ALIGNMENT_PROTOCOL.getLatestProjectDefault(dc, legacyPipeline);
6812 25 Aug 22 nicklas 318     Software tophatAlignSoftware = (Software)Subtype.ALIGNMENT_SOFTWARE.getLatestProjectDefault(dc, legacyPipeline);
6819 26 Aug 22 nicklas 319     Arraydesign design = Arraydesign.getLatestProjectDefault(dc, Rawdatatype.CUFFLINKS.getVariantId(), legacyPipeline);
6812 25 Aug 22 nicklas 320     Protocol protocol = (Protocol)Subtype.FEATURE_EXTRACTION_PROTOCOL.getLatestProjectDefault(dc, legacyPipeline);
6812 25 Aug 22 nicklas 321     Software software = (Software)Subtype.FEATURE_EXTRACTION_SOFTWARE.getLatestProjectDefault(dc, legacyPipeline);
6184 26 Mar 21 nicklas 322
6184 26 Mar 21 nicklas 323     if (logger.isDebugEnabled())
6184 26 Mar 21 nicklas 324     {
6184 26 Mar 21 nicklas 325       logger.debug("Starting Tophat mask/align jobs on cluster: " + cluster.getId());
6184 26 Mar 21 nicklas 326       logger.debug("Mask software/protocol: " + maskingSoftware + "/" + maskingProtocol);
6184 26 Mar 21 nicklas 327       logger.debug("Tophat align software/protocol: " + tophatAlignSoftware + "/" + tophatAlignProtocol);
6184 26 Mar 21 nicklas 328       logger.debug("Cufflinks Software/protocol: " + software + "/" + protocol);
6184 26 Mar 21 nicklas 329       logger.debug("Array design: " + design);
6184 26 Mar 21 nicklas 330     }
6184 26 Mar 21 nicklas 331     
6184 26 Mar 21 nicklas 332     CufflinksJobCreator jobCreator = new CufflinksJobCreator();
7341 11 Sep 23 nicklas 333     jobCreator.setBatchConfig(batchConfig);
6184 26 Mar 21 nicklas 334     jobCreator.setMaskingProtocol(maskingProtocol);
6184 26 Mar 21 nicklas 335     jobCreator.setMaskingSoftware(maskingSoftware);
6184 26 Mar 21 nicklas 336     jobCreator.setAlignProtocol(tophatAlignProtocol);
6184 26 Mar 21 nicklas 337     jobCreator.setAlignSoftware(tophatAlignSoftware);
6184 26 Mar 21 nicklas 338     jobCreator.setArrayDesign(design == null ? null : design.getItem());
6184 26 Mar 21 nicklas 339     jobCreator.setProtocol(protocol);
6184 26 Mar 21 nicklas 340     jobCreator.setSoftware(software);
6184 26 Mar 21 nicklas 341     jobCreator.setAutoConfirm(true);
6184 26 Mar 21 nicklas 342     jobCreator.setDebug(debug);
6184 26 Mar 21 nicklas 343     jobCreator.setPriority(priority);
6982 17 Jan 23 nicklas 344     jobCreator.setPartition(partition);
6184 26 Mar 21 nicklas 345     
6184 26 Mar 21 nicklas 346     List<JobDefinition> jobDefs = jobCreator.createTophatCufflinkJobs(dc, cluster, mergedSequences);
6184 26 Mar 21 nicklas 347     
6184 26 Mar 21 nicklas 348     return ScriptUtil.submitJobs(dc, cluster, jobDefs);
6184 26 Mar 21 nicklas 349   }
6184 26 Mar 21 nicklas 350   
6982 17 Jan 23 nicklas 351   public static List<Job> submitHisatJobs(DbControl dc, List<MergedSequences> mergedSequences, OpenGridCluster cluster, BatchConfig batchConfig, boolean debug, Integer priority, String partition)
6184 26 Mar 21 nicklas 352   {
6812 25 Aug 22 nicklas 353     Filter<Annotatable> hisatFilter = Annotationtype.PIPELINE.createFilter(Pipeline.RNASEQ_HISAT_STRINGTIE.getName());
6812 25 Aug 22 nicklas 354     Protocol maskingProtocol = (Protocol)Subtype.MASKING_PROTOCOL.getLatestProjectDefault(dc, hisatFilter);
6812 25 Aug 22 nicklas 355     Software maskingSoftware = (Software)Subtype.MASKING_SOFTWARE.getLatestProjectDefault(dc, hisatFilter);
6184 26 Mar 21 nicklas 356     Protocol hisatAlignProtocol = (Protocol)Subtype.ALIGNMENT_PROTOCOL.getLatestProjectDefault(dc, hisatFilter);
6184 26 Mar 21 nicklas 357     Software hisatAlignSoftware = (Software)Subtype.ALIGNMENT_SOFTWARE.getLatestProjectDefault(dc, hisatFilter);
6184 26 Mar 21 nicklas 358
6184 26 Mar 21 nicklas 359     if (logger.isDebugEnabled())
6184 26 Mar 21 nicklas 360     {
6184 26 Mar 21 nicklas 361       logger.debug("Starting Hisat mask/align jobs on cluster: " + cluster.getId());
6184 26 Mar 21 nicklas 362       logger.debug("Hisat align software/protocol: " + hisatAlignSoftware + "/" + hisatAlignProtocol);
6184 26 Mar 21 nicklas 363     }
6184 26 Mar 21 nicklas 364
6184 26 Mar 21 nicklas 365     HisatAlignJobCreator hisatJobCreator = new HisatAlignJobCreator();
7341 11 Sep 23 nicklas 366     hisatJobCreator.setBatchConfig(batchConfig);
6184 26 Mar 21 nicklas 367     hisatJobCreator.setAutoConfirm(true);
6184 26 Mar 21 nicklas 368     hisatJobCreator.setDebug(debug);
6184 26 Mar 21 nicklas 369     hisatJobCreator.setPriority(priority);
6982 17 Jan 23 nicklas 370     hisatJobCreator.setPartition(partition);
6184 26 Mar 21 nicklas 371     hisatJobCreator.setMaskingProtocol(maskingProtocol);
6184 26 Mar 21 nicklas 372     hisatJobCreator.setMaskingSoftware(maskingSoftware);
6184 26 Mar 21 nicklas 373     hisatJobCreator.setAlignProtocol(hisatAlignProtocol);
6184 26 Mar 21 nicklas 374     hisatJobCreator.setAlignSoftware(hisatAlignSoftware);
6184 26 Mar 21 nicklas 375     
6184 26 Mar 21 nicklas 376     List<JobDefinition> jobDefs = hisatJobCreator.createHisatAlignJobs(dc, cluster, mergedSequences);
6184 26 Mar 21 nicklas 377
6184 26 Mar 21 nicklas 378     return ScriptUtil.submitJobs(dc, cluster, jobDefs);
6184 26 Mar 21 nicklas 379   }
6809 24 Aug 22 nicklas 380   
6982 17 Jan 23 nicklas 381   public static List<Job> submitHisat2023Jobs(DbControl dc, List<MergedSequences> mergedSequences, OpenGridCluster cluster, BatchConfig batchConfig, boolean debug, Integer priority, String partition)
6809 24 Aug 22 nicklas 382   {
6814 26 Aug 22 nicklas 383     Filter<Annotatable> hisatFilter = Annotationtype.PIPELINE.createFilter(Pipeline.RNASEQ_HISAT_2023.getName());
6814 26 Aug 22 nicklas 384     Protocol maskingProtocol = (Protocol)Subtype.MASKING_PROTOCOL.getLatestProjectDefault(dc, hisatFilter);
6814 26 Aug 22 nicklas 385     Software maskingSoftware = (Software)Subtype.MASKING_SOFTWARE.getLatestProjectDefault(dc, hisatFilter);
6814 26 Aug 22 nicklas 386     Protocol hisatAlignProtocol = (Protocol)Subtype.ALIGNMENT_PROTOCOL.getLatestProjectDefault(dc, hisatFilter);
6814 26 Aug 22 nicklas 387     Software hisatAlignSoftware = (Software)Subtype.ALIGNMENT_SOFTWARE.getLatestProjectDefault(dc, hisatFilter);
6814 26 Aug 22 nicklas 388
6814 26 Aug 22 nicklas 389     if (logger.isDebugEnabled())
6814 26 Aug 22 nicklas 390     {
6814 26 Aug 22 nicklas 391       logger.debug("Starting Hisat/2023 mask/align jobs on cluster: " + cluster.getId());
6814 26 Aug 22 nicklas 392       logger.debug("Hisat/2023 align software/protocol: " + hisatAlignSoftware + "/" + hisatAlignProtocol);
6814 26 Aug 22 nicklas 393     }
6814 26 Aug 22 nicklas 394
6814 26 Aug 22 nicklas 395     Hisat2023AlignJobCreator hisatJobCreator = new Hisat2023AlignJobCreator();
7341 11 Sep 23 nicklas 396     hisatJobCreator.setBatchConfig(batchConfig);
6814 26 Aug 22 nicklas 397     hisatJobCreator.setAutoConfirm(true);
6814 26 Aug 22 nicklas 398     hisatJobCreator.setDebug(debug);
6814 26 Aug 22 nicklas 399     hisatJobCreator.setPriority(priority);
6982 17 Jan 23 nicklas 400     hisatJobCreator.setPartition(partition);
6814 26 Aug 22 nicklas 401     hisatJobCreator.setMaskingProtocol(maskingProtocol);
6814 26 Aug 22 nicklas 402     hisatJobCreator.setMaskingSoftware(maskingSoftware);
6814 26 Aug 22 nicklas 403     hisatJobCreator.setAlignProtocol(hisatAlignProtocol);
6814 26 Aug 22 nicklas 404     hisatJobCreator.setAlignSoftware(hisatAlignSoftware);
6814 26 Aug 22 nicklas 405     
6814 26 Aug 22 nicklas 406     List<JobDefinition> jobDefs = hisatJobCreator.createHisatAlignJobs(dc, cluster, mergedSequences);
6814 26 Aug 22 nicklas 407
6814 26 Aug 22 nicklas 408     return ScriptUtil.submitJobs(dc, cluster, jobDefs);
6809 24 Aug 22 nicklas 409   }
3034 12 Dec 14 nicklas 410 }