extensions/net.sf.basedb.reggie/trunk/src/net/sf/basedb/reggie/pdf/PdfReportTemplate.java

Code
Comments
Other
Rev Date Author Line
3506 23 Sep 15 nicklas 1 package net.sf.basedb.reggie.pdf;
3506 23 Sep 15 nicklas 2
3506 23 Sep 15 nicklas 3 import java.lang.reflect.Field;
3506 23 Sep 15 nicklas 4
3506 23 Sep 15 nicklas 5 import net.sf.basedb.reggie.Reggie;
5384 26 Apr 19 nicklas 6 import net.sf.basedb.reggie.activity.ActivityDef;
6023 26 Oct 20 nicklas 7 import net.sf.basedb.reggie.dao.BiomaterialList;
5666 14 Oct 19 nicklas 8 import net.sf.basedb.reggie.dao.Pipeline;
5650 09 Oct 19 nicklas 9 import net.sf.basedb.reggie.dao.Rawdatatype;
6035 29 Oct 20 nicklas 10 import net.sf.basedb.reggie.script.GeneReport;
6035 29 Oct 20 nicklas 11 import net.sf.basedb.reggie.script.PilotReport;
5647 08 Oct 19 nicklas 12 import net.sf.basedb.reggie.ssp.SspAnalysis;
3506 23 Sep 15 nicklas 13
3506 23 Sep 15 nicklas 14 /**
3506 23 Sep 15 nicklas 15   Starting point for report generation. Each template uses a
3506 23 Sep 15 nicklas 16   {@link PdfReportWorker} that is typically bound to some kind 
3506 23 Sep 15 nicklas 17   of script (eg. {@link GeneReport}) that performs the analysis 
3506 23 Sep 15 nicklas 18   of the data. The worker is then responsible for generating
3506 23 Sep 15 nicklas 19   a PDF of the result.
3506 23 Sep 15 nicklas 20   
3506 23 Sep 15 nicklas 21   @since 3.7
3506 23 Sep 15 nicklas 22 */
3506 23 Sep 15 nicklas 23 public abstract class PdfReportTemplate 
3506 23 Sep 15 nicklas 24 {
3506 23 Sep 15 nicklas 25
3506 23 Sep 15 nicklas 26   /**
3506 23 Sep 15 nicklas 27     Get the report by name of the static constant defined in this class.
3506 23 Sep 15 nicklas 28     
3571 30 Oct 15 nicklas 29     @param cName The name of the static constant
3506 23 Sep 15 nicklas 30     @return A report object or null if not found
3506 23 Sep 15 nicklas 31   */
3506 23 Sep 15 nicklas 32   public static PdfReportTemplate getByCName(String cName, PdfReportTemplate defaultReport)
3506 23 Sep 15 nicklas 33   {
3513 24 Sep 15 nicklas 34     if (cName == null) return defaultReport;
3506 23 Sep 15 nicklas 35     PdfReportTemplate report = null;
3506 23 Sep 15 nicklas 36     try
3506 23 Sep 15 nicklas 37     {
3506 23 Sep 15 nicklas 38       Field f = PdfReportTemplate.class.getDeclaredField(cName);
3506 23 Sep 15 nicklas 39       report = (PdfReportTemplate)f.get(null);
3506 23 Sep 15 nicklas 40     }
3506 23 Sep 15 nicklas 41     catch (NoSuchFieldException ex)
3506 23 Sep 15 nicklas 42     {}
3506 23 Sep 15 nicklas 43     catch (IllegalAccessException ex)
3506 23 Sep 15 nicklas 44     {}
3506 23 Sep 15 nicklas 45     catch (ClassCastException ex)
3506 23 Sep 15 nicklas 46     {}
3506 23 Sep 15 nicklas 47     return report == null ? defaultReport : report;
3506 23 Sep 15 nicklas 48   }
3506 23 Sep 15 nicklas 49
3506 23 Sep 15 nicklas 50   /**
3506 23 Sep 15 nicklas 51     The "Gene report" template. Uses the {@link GeneReport}
3506 23 Sep 15 nicklas 52     script for analysing the data and the {@link GeneReportWorker}
3506 23 Sep 15 nicklas 53     for creating the PDF.
3506 23 Sep 15 nicklas 54   */
3506 23 Sep 15 nicklas 55   public static final PdfReportTemplate GENE_REPORT = 
6033 29 Oct 20 nicklas 56     new PdfReportTemplate("Gene report", "rscript/gene-report", GeneReportWorker.DEFAULT_PDF_NAME, false, false, false,
6023 26 Oct 20 nicklas 57       Rawdatatype.CUFFLINKS, Pipeline.RNASEQ_LEGACY, null, BiomaterialList.GENE_REPORT_CREATE)
3506 23 Sep 15 nicklas 58     {
3506 23 Sep 15 nicklas 59       @Override
3620 24 Nov 15 nicklas 60       public PdfReportWorker getWorker(String parameterSet) 
3506 23 Sep 15 nicklas 61       {
3620 24 Nov 15 nicklas 62         return new GeneReportWorker(GENE_REPORT, config, parameterSet);
3506 23 Sep 15 nicklas 63       }
3506 23 Sep 15 nicklas 64     };
3506 23 Sep 15 nicklas 65   
3506 23 Sep 15 nicklas 66   /**
3506 23 Sep 15 nicklas 67     The "Pilot report" template. Uses the {@link PilotReport}
3506 23 Sep 15 nicklas 68     script for analysing the data and the {@link PilotReportWorker}
3506 23 Sep 15 nicklas 69     for creating the PDF.
3506 23 Sep 15 nicklas 70   */
3506 23 Sep 15 nicklas 71   public static final PdfReportTemplate PILOT_REPORT = 
6033 29 Oct 20 nicklas 72     new PdfReportTemplate("Pilot report", "rscript/pilot-report", PilotReportWorker.DEFAULT_PDF_NAME, true, true, false,
6023 26 Oct 20 nicklas 73       Rawdatatype.CUFFLINKS, Pipeline.RNASEQ_LEGACY, ActivityDef.PILOT_REPORT, BiomaterialList.PILOT_REPORT_CREATE)
3506 23 Sep 15 nicklas 74   {
3506 23 Sep 15 nicklas 75     @Override
3620 24 Nov 15 nicklas 76     public PdfReportWorker getWorker(String parameterSet) 
3506 23 Sep 15 nicklas 77     {
3620 24 Nov 15 nicklas 78       return new PilotReportWorker(PILOT_REPORT, config, parameterSet);
3506 23 Sep 15 nicklas 79     }
3506 23 Sep 15 nicklas 80   };
3506 23 Sep 15 nicklas 81   
5647 08 Oct 19 nicklas 82   /**
5647 08 Oct 19 nicklas 83     The "SCAN-B report template. Uses the {@link SspAnalysis}
5647 08 Oct 19 nicklas 84     script for analysing the data abd the {@link ScanBReportWorker}
5647 08 Oct 19 nicklas 85     for creating the PDF.
5647 08 Oct 19 nicklas 86     @since 4.24
5647 08 Oct 19 nicklas 87   */
5647 08 Oct 19 nicklas 88   public static final PdfReportTemplate SCANB_REPORT =
6092 14 Dec 20 nicklas 89     new PdfReportTemplate("SCAN-B report", "rscript/scanb-report", "scanbreport.pdf", true, false, true,
6023 26 Oct 20 nicklas 90       Rawdatatype.STRINGTIE, Pipeline.RNASEQ_HISAT_STRINGTIE, ActivityDef.SCANB_REPORT, BiomaterialList.SCANB_REPORT_CREATE)
5647 08 Oct 19 nicklas 91   {
5647 08 Oct 19 nicklas 92     @Override
5647 08 Oct 19 nicklas 93     public PdfReportWorker getWorker(String parameterSet) 
5647 08 Oct 19 nicklas 94     {
5647 08 Oct 19 nicklas 95       return new ScanBReportWorker(SCANB_REPORT, config, parameterSet);
5647 08 Oct 19 nicklas 96     }
5647 08 Oct 19 nicklas 97   };
5647 08 Oct 19 nicklas 98   
3506 23 Sep 15 nicklas 99   protected final String name;
3506 23 Sep 15 nicklas 100   protected final String config;
3506 23 Sep 15 nicklas 101   protected final String defaultFilename;
3506 23 Sep 15 nicklas 102   protected final boolean supportsPersonalInformation;
5669 15 Oct 19 nicklas 103   protected final boolean canUpdateAnnotations;
6033 29 Oct 20 nicklas 104   protected final boolean useExternalIds;
5384 26 Apr 19 nicklas 105   protected final ActivityDef activity;
5650 09 Oct 19 nicklas 106   protected final Rawdatatype rawDataType;
5666 14 Oct 19 nicklas 107   protected final Pipeline pipeline;
6023 26 Oct 20 nicklas 108   protected final BiomaterialList list;
3506 23 Sep 15 nicklas 109
5384 26 Apr 19 nicklas 110   private PdfReportTemplate(String name, String config, String defaultFilename, 
6033 29 Oct 20 nicklas 111     boolean supportsPersonalInformation, boolean canUpdateAnnotations, boolean useExternalIds,
6023 26 Oct 20 nicklas 112     Rawdatatype rawDataType, Pipeline pipeline, ActivityDef activity, BiomaterialList list)
3506 23 Sep 15 nicklas 113   {
3506 23 Sep 15 nicklas 114     this.name = name;
3506 23 Sep 15 nicklas 115     this.config = config;
3506 23 Sep 15 nicklas 116     this.defaultFilename = defaultFilename;
3506 23 Sep 15 nicklas 117     this.supportsPersonalInformation = supportsPersonalInformation;
5669 15 Oct 19 nicklas 118     this.canUpdateAnnotations = canUpdateAnnotations;
6033 29 Oct 20 nicklas 119     this.useExternalIds = useExternalIds;
5384 26 Apr 19 nicklas 120     this.activity = activity;
5650 09 Oct 19 nicklas 121     this.rawDataType = rawDataType;
5666 14 Oct 19 nicklas 122     this.pipeline = pipeline;
6023 26 Oct 20 nicklas 123     this.list = list;
3506 23 Sep 15 nicklas 124   }
3506 23 Sep 15 nicklas 125   
3506 23 Sep 15 nicklas 126   public String getReportName()
3506 23 Sep 15 nicklas 127   {
3506 23 Sep 15 nicklas 128     return name;
3506 23 Sep 15 nicklas 129   }
3506 23 Sep 15 nicklas 130   
3506 23 Sep 15 nicklas 131   /**
3616 23 Nov 15 nicklas 132     The the section in reggie-config.xml to read configuration
3616 23 Nov 15 nicklas 133     settings from.
3616 23 Nov 15 nicklas 134     @since 4.0
3616 23 Nov 15 nicklas 135   */
3616 23 Nov 15 nicklas 136   public String getConfigSection()
3616 23 Nov 15 nicklas 137   {
3616 23 Nov 15 nicklas 138     return config;
3616 23 Nov 15 nicklas 139   }
3616 23 Nov 15 nicklas 140   
3616 23 Nov 15 nicklas 141   /**
3506 23 Sep 15 nicklas 142     Get the default file name for this type of report. 
3506 23 Sep 15 nicklas 143     The method first checked the <pdf-name> tag in the 
3506 23 Sep 15 nicklas 144     reggie-config.xml file before using the default name.
3506 23 Sep 15 nicklas 145   */
3506 23 Sep 15 nicklas 146   public String getDefaultFilename()
3506 23 Sep 15 nicklas 147   {
3506 23 Sep 15 nicklas 148     return Reggie.getConfig().getConfig(config+"/pdf-name", null, defaultFilename);
3506 23 Sep 15 nicklas 149   }
3506 23 Sep 15 nicklas 150   
3506 23 Sep 15 nicklas 151   /**
3506 23 Sep 15 nicklas 152     Is is possible to add personal information to this report or not?
3506 23 Sep 15 nicklas 153   */
3506 23 Sep 15 nicklas 154   public boolean supportsPersonalInformation()
3506 23 Sep 15 nicklas 155   {
3506 23 Sep 15 nicklas 156     return supportsPersonalInformation;
3506 23 Sep 15 nicklas 157   }
3506 23 Sep 15 nicklas 158   
3506 23 Sep 15 nicklas 159   /**
5669 15 Oct 19 nicklas 160     Can the report update annotations on the raw bioassay or not?
5669 15 Oct 19 nicklas 161     @since 4.24
5669 15 Oct 19 nicklas 162   */
5669 15 Oct 19 nicklas 163   public boolean canUpdateAnnotations()
5669 15 Oct 19 nicklas 164   {
5669 15 Oct 19 nicklas 165     return canUpdateAnnotations;
5669 15 Oct 19 nicklas 166   }
5669 15 Oct 19 nicklas 167   
5669 15 Oct 19 nicklas 168   /**
6033 29 Oct 20 nicklas 169     A flag that indicates that external ID values should be used
6033 29 Oct 20 nicklas 170     in situations where there is a choice between using SCAN-B
6033 29 Oct 20 nicklas 171     or external ID. Example, when downloading a single PDF report
6033 29 Oct 20 nicklas 172     or when combining multiple reports in a ZIP file.
6033 29 Oct 20 nicklas 173     @since 4.28
6033 29 Oct 20 nicklas 174   */
6033 29 Oct 20 nicklas 175   public boolean useExternalIds()
6033 29 Oct 20 nicklas 176   {
6033 29 Oct 20 nicklas 177     return useExternalIds;
6033 29 Oct 20 nicklas 178   }
6033 29 Oct 20 nicklas 179   
6033 29 Oct 20 nicklas 180   /**
5384 26 Apr 19 nicklas 181     Get the activity definition that the number of created reports
5384 26 Apr 19 nicklas 182     should be logged under in the ActivityLog. May return null
5384 26 Apr 19 nicklas 183     if no activity logging should be done.
5384 26 Apr 19 nicklas 184     @since 4.23
5384 26 Apr 19 nicklas 185   */
5384 26 Apr 19 nicklas 186   public ActivityDef getActivityDef()
5384 26 Apr 19 nicklas 187   {
5384 26 Apr 19 nicklas 188     return activity;
5384 26 Apr 19 nicklas 189   }
5384 26 Apr 19 nicklas 190   
5384 26 Apr 19 nicklas 191   /**
5650 09 Oct 19 nicklas 192     Get the raw data type that is required for this report.
5650 09 Oct 19 nicklas 193     May return null if any raw data type is accepted.
5650 09 Oct 19 nicklas 194     @since 4.24
5650 09 Oct 19 nicklas 195   */
5650 09 Oct 19 nicklas 196   public Rawdatatype getRawDataType()
5650 09 Oct 19 nicklas 197   {
5650 09 Oct 19 nicklas 198     return rawDataType;
5650 09 Oct 19 nicklas 199   }
5650 09 Oct 19 nicklas 200   
5650 09 Oct 19 nicklas 201   /**
5666 14 Oct 19 nicklas 202     Get the pipeline that is required for this report.
5666 14 Oct 19 nicklas 203     May return null if any pipeline is accepted.
5666 14 Oct 19 nicklas 204     @since 4.24
5666 14 Oct 19 nicklas 205   */
5666 14 Oct 19 nicklas 206   public Pipeline getPipeline()
5666 14 Oct 19 nicklas 207   {
5666 14 Oct 19 nicklas 208     return pipeline;
5666 14 Oct 19 nicklas 209   }
5666 14 Oct 19 nicklas 210
6023 26 Oct 20 nicklas 211   /**
6023 26 Oct 20 nicklas 212     Get the item list that is keeping track of raw bioassays that
6023 26 Oct 20 nicklas 213     are ready for reporting.
6023 26 Oct 20 nicklas 214     @since 4.28
6023 26 Oct 20 nicklas 215   */
6023 26 Oct 20 nicklas 216   public BiomaterialList getItemList()
6023 26 Oct 20 nicklas 217   {
6023 26 Oct 20 nicklas 218     return list;
6023 26 Oct 20 nicklas 219   }
5666 14 Oct 19 nicklas 220   
5666 14 Oct 19 nicklas 221   /**
3506 23 Sep 15 nicklas 222     Create a worker for analysing the data and generate the PDF
3506 23 Sep 15 nicklas 223     report.
3506 23 Sep 15 nicklas 224   */
3620 24 Nov 15 nicklas 225   public abstract PdfReportWorker getWorker(String parameterSet);
3506 23 Sep 15 nicklas 226   
3506 23 Sep 15 nicklas 227 }