3034 |
12 Dec 14 |
nicklas |
1 |
package net.sf.basedb.reggie.autoconfirm; |
3034 |
12 Dec 14 |
nicklas |
2 |
|
3055 |
19 Dec 14 |
nicklas |
3 |
import java.util.Collections; |
3618 |
23 Nov 15 |
nicklas |
4 |
import java.util.HashMap; |
3618 |
23 Nov 15 |
nicklas |
5 |
import java.util.Map; |
3055 |
19 Dec 14 |
nicklas |
6 |
|
3034 |
12 Dec 14 |
nicklas |
7 |
import net.sf.basedb.core.DbControl; |
4547 |
29 Jun 17 |
nicklas |
8 |
import net.sf.basedb.core.DerivedBioAssay; |
6023 |
26 Oct 20 |
nicklas |
9 |
import net.sf.basedb.core.ItemList; |
3034 |
12 Dec 14 |
nicklas |
10 |
import net.sf.basedb.core.Job; |
3034 |
12 Dec 14 |
nicklas |
11 |
import net.sf.basedb.core.RawBioAssay; |
3055 |
19 Dec 14 |
nicklas |
12 |
import net.sf.basedb.core.SessionControl; |
3618 |
23 Nov 15 |
nicklas |
13 |
import net.sf.basedb.core.Software; |
5384 |
26 Apr 19 |
nicklas |
14 |
import net.sf.basedb.reggie.activity.ActivityDef; |
3049 |
17 Dec 14 |
nicklas |
15 |
import net.sf.basedb.reggie.dao.Annotationtype; |
6023 |
26 Oct 20 |
nicklas |
16 |
import net.sf.basedb.reggie.dao.BiomaterialList; |
4541 |
26 Jun 17 |
nicklas |
17 |
import net.sf.basedb.reggie.dao.Datafiletype; |
5544 |
06 Aug 19 |
nicklas |
18 |
import net.sf.basedb.reggie.dao.Pipeline; |
3049 |
17 Dec 14 |
nicklas |
19 |
import net.sf.basedb.reggie.dao.Rawbioassay; |
4547 |
29 Jun 17 |
nicklas |
20 |
import net.sf.basedb.reggie.dao.Rna; |
3618 |
23 Nov 15 |
nicklas |
21 |
import net.sf.basedb.reggie.dao.Subtype; |
3055 |
19 Dec 14 |
nicklas |
22 |
import net.sf.basedb.reggie.plugins.GeneReportPlugin; |
3034 |
12 Dec 14 |
nicklas |
23 |
|
3034 |
12 Dec 14 |
nicklas |
24 |
/** |
3051 |
17 Dec 14 |
nicklas |
Auto-confirm implementation for raw bioassays after cufflinks has been run. |
3034 |
12 Dec 14 |
nicklas |
The rules are simple: |
3034 |
12 Dec 14 |
nicklas |
27 |
|
3571 |
30 Oct 15 |
nicklas |
* {@link RawBioAssay#getJob()} job status must be {@link net.sf.basedb.core.Job.Status#DONE}. |
4541 |
26 Jun 17 |
nicklas |
* A {@link Datafiletype#FPKM} file must be attached to the {@link RawBioAssay}. |
3034 |
12 Dec 14 |
nicklas |
30 |
|
4541 |
26 Jun 17 |
nicklas |
Auto-confirmation will then continue with generating a Gene/Pilot report |
4541 |
26 Jun 17 |
nicklas |
for all cases. |
3049 |
17 Dec 14 |
nicklas |
33 |
|
3034 |
12 Dec 14 |
nicklas |
@author nicklas |
3045 |
16 Dec 14 |
nicklas |
@since 3.0 |
3034 |
12 Dec 14 |
nicklas |
36 |
*/ |
3051 |
17 Dec 14 |
nicklas |
37 |
public class CufflinksAutoConfirmer |
3034 |
12 Dec 14 |
nicklas |
38 |
extends AutoConfirmer<RawBioAssay> |
3034 |
12 Dec 14 |
nicklas |
39 |
{ |
3034 |
12 Dec 14 |
nicklas |
40 |
|
4547 |
29 Jun 17 |
nicklas |
41 |
/** |
4547 |
29 Jun 17 |
nicklas |
At least 5 million aligned pairs is required for |
4547 |
29 Jun 17 |
nicklas |
alignment to pass without flagging. |
4547 |
29 Jun 17 |
nicklas |
44 |
*/ |
4547 |
29 Jun 17 |
nicklas |
45 |
public static final long MIN_ALIGNED_PAIRS_FLAG = 5*M; |
4547 |
29 Jun 17 |
nicklas |
46 |
|
4547 |
29 Jun 17 |
nicklas |
47 |
/** |
4547 |
29 Jun 17 |
nicklas |
At least 1 million aligned pairs is required for |
4547 |
29 Jun 17 |
nicklas |
alignment to pass but with flagging RNA. |
4547 |
29 Jun 17 |
nicklas |
50 |
*/ |
4547 |
29 Jun 17 |
nicklas |
51 |
public static final long MIN_ALIGNED_PAIRS_STOP = 1*M; |
4547 |
29 Jun 17 |
nicklas |
52 |
|
4547 |
29 Jun 17 |
nicklas |
53 |
public static final long MIN_ALIGNED_PAIRS_FLAG_DEBUG = 200*k; |
4547 |
29 Jun 17 |
nicklas |
54 |
public static final long MIN_ALIGNED_PAIRS_STOP_DEBUG = 150*k; |
4547 |
29 Jun 17 |
nicklas |
55 |
|
3051 |
17 Dec 14 |
nicklas |
56 |
public CufflinksAutoConfirmer(RawBioAssay raw) |
3034 |
12 Dec 14 |
nicklas |
57 |
{ |
3055 |
19 Dec 14 |
nicklas |
58 |
super(raw, raw.getJob()); |
3034 |
12 Dec 14 |
nicklas |
59 |
} |
3034 |
12 Dec 14 |
nicklas |
60 |
|
3055 |
19 Dec 14 |
nicklas |
61 |
/** |
4541 |
26 Jun 17 |
nicklas |
Passes if the job ended successfully. |
3055 |
19 Dec 14 |
nicklas |
63 |
*/ |
3034 |
12 Dec 14 |
nicklas |
64 |
@Override |
3049 |
17 Dec 14 |
nicklas |
65 |
public boolean checkRules(DbControl dc, AutoConfirmManager manager) |
3034 |
12 Dec 14 |
nicklas |
66 |
{ |
3034 |
12 Dec 14 |
nicklas |
67 |
RawBioAssay raw = item(dc); |
3034 |
12 Dec 14 |
nicklas |
68 |
Job job = raw.getJob(); |
4541 |
26 Jun 17 |
nicklas |
69 |
return job.getStatus() == Job.Status.DONE; |
3034 |
12 Dec 14 |
nicklas |
70 |
} |
3034 |
12 Dec 14 |
nicklas |
71 |
|
3055 |
19 Dec 14 |
nicklas |
72 |
/** |
4547 |
29 Jun 17 |
nicklas |
Flag RNA if aligned pairs is less than 5 million. |
4547 |
29 Jun 17 |
nicklas |
Continue with Gene report if aligned pairs is more than 1 million |
4547 |
29 Jun 17 |
nicklas |
and a FPKM file is found. |
3055 |
19 Dec 14 |
nicklas |
76 |
*/ |
3049 |
17 Dec 14 |
nicklas |
77 |
@Override |
3049 |
17 Dec 14 |
nicklas |
78 |
public boolean autoConfirm(DbControl dc, AutoConfirmManager manager) |
3049 |
17 Dec 14 |
nicklas |
79 |
{ |
3049 |
17 Dec 14 |
nicklas |
80 |
RawBioAssay raw = item(dc); |
4541 |
26 Jun 17 |
nicklas |
81 |
Rawbioassay rba = Rawbioassay.get(raw); |
4547 |
29 Jun 17 |
nicklas |
82 |
Job job = raw.getJob(); |
4547 |
29 Jun 17 |
nicklas |
83 |
DerivedBioAssay aligned = raw.getParentBioAssay(); |
4547 |
29 Jun 17 |
nicklas |
84 |
boolean debug = Boolean.TRUE.equals(job.getParameterValue("debug")); |
4541 |
26 Jun 17 |
nicklas |
85 |
|
4547 |
29 Jun 17 |
nicklas |
86 |
long minAlignedPairsFlag = debug ? MIN_ALIGNED_PAIRS_FLAG_DEBUG : MIN_ALIGNED_PAIRS_FLAG; |
4547 |
29 Jun 17 |
nicklas |
87 |
long minAlignedPairsStop = debug ? MIN_ALIGNED_PAIRS_STOP_DEBUG : MIN_ALIGNED_PAIRS_STOP; |
4547 |
29 Jun 17 |
nicklas |
88 |
|
4547 |
29 Jun 17 |
nicklas |
89 |
Long alignedPairs = (Long)Annotationtype.ALIGNED_PAIRS.getAnnotationValue(dc, aligned); |
4547 |
29 Jun 17 |
nicklas |
90 |
|
4547 |
29 Jun 17 |
nicklas |
91 |
boolean flagRNA = false; |
4547 |
29 Jun 17 |
nicklas |
92 |
boolean stop = false; |
4547 |
29 Jun 17 |
nicklas |
93 |
if (alignedPairs == null || alignedPairs < minAlignedPairsStop) |
4547 |
29 Jun 17 |
nicklas |
94 |
{ |
4547 |
29 Jun 17 |
nicklas |
// Flag and stop |
4547 |
29 Jun 17 |
nicklas |
96 |
flagRNA = true; |
4547 |
29 Jun 17 |
nicklas |
97 |
stop = true; |
4547 |
29 Jun 17 |
nicklas |
98 |
} |
4547 |
29 Jun 17 |
nicklas |
99 |
else if (alignedPairs < minAlignedPairsFlag) |
4547 |
29 Jun 17 |
nicklas |
100 |
{ |
4547 |
29 Jun 17 |
nicklas |
// Flag and continue |
4547 |
29 Jun 17 |
nicklas |
102 |
flagRNA = true; |
4547 |
29 Jun 17 |
nicklas |
103 |
} |
4547 |
29 Jun 17 |
nicklas |
104 |
|
4547 |
29 Jun 17 |
nicklas |
105 |
if (rba.getFile(dc, Datafiletype.FPKM) == null) stop = true; |
4547 |
29 Jun 17 |
nicklas |
106 |
|
4547 |
29 Jun 17 |
nicklas |
107 |
if (flagRNA) |
4547 |
29 Jun 17 |
nicklas |
108 |
{ |
4547 |
29 Jun 17 |
nicklas |
109 |
manager.flagRna(dc, raw.getParentExtract(), Rna.FLAG_ALIGN_FAILED); |
4547 |
29 Jun 17 |
nicklas |
110 |
} |
4547 |
29 Jun 17 |
nicklas |
111 |
|
4541 |
26 Jun 17 |
nicklas |
112 |
if (stop) |
4541 |
26 Jun 17 |
nicklas |
113 |
{ |
4541 |
26 Jun 17 |
nicklas |
114 |
Annotationtype.ANALYSIS_RESULT.setAnnotationValue(dc, raw, Rawbioassay.FEATURE_EXTRACTION_FAILED); |
4541 |
26 Jun 17 |
nicklas |
115 |
} |
4541 |
26 Jun 17 |
nicklas |
116 |
else |
4541 |
26 Jun 17 |
nicklas |
117 |
{ |
4541 |
26 Jun 17 |
nicklas |
118 |
Annotationtype.ANALYSIS_RESULT.setAnnotationValue(dc, raw, Rawbioassay.FEATURE_EXTRACTION_SUCCESSFUL); |
5421 |
13 May 19 |
nicklas |
119 |
ActivityDef.LEGACY_PIPELINE_AUTOCONFIRMED.merge(dc, 1).setUser("Auto-confirm"); |
6023 |
26 Oct 20 |
nicklas |
120 |
BiomaterialList.GENE_REPORT_CREATE.load(dc).add(raw); |
6023 |
26 Oct 20 |
nicklas |
121 |
BiomaterialList.PILOT_REPORT_CREATE.load(dc).add(raw); |
4541 |
26 Jun 17 |
nicklas |
122 |
} |
4541 |
26 Jun 17 |
nicklas |
123 |
return !stop; |
3049 |
17 Dec 14 |
nicklas |
124 |
} |
3034 |
12 Dec 14 |
nicklas |
125 |
|
3055 |
19 Dec 14 |
nicklas |
126 |
/** |
3055 |
19 Dec 14 |
nicklas |
Start the {@link GeneReportPlugin} with this raw bioassay. |
3055 |
19 Dec 14 |
nicklas |
128 |
*/ |
3055 |
19 Dec 14 |
nicklas |
129 |
@Override |
3055 |
19 Dec 14 |
nicklas |
130 |
public boolean startNextStep(SessionControl sc, AutoConfirmManager manager) |
3055 |
19 Dec 14 |
nicklas |
131 |
{ |
3055 |
19 Dec 14 |
nicklas |
132 |
DbControl dc = null; |
3055 |
19 Dec 14 |
nicklas |
133 |
try |
3055 |
19 Dec 14 |
nicklas |
134 |
{ |
6599 |
22 Feb 22 |
nicklas |
135 |
dc = sc.newDbControl("Reggie: Auto-confirm Cufflinks - start reports"); |
5544 |
06 Aug 19 |
nicklas |
136 |
RawBioAssay cufflinks = item(dc); |
5544 |
06 Aug 19 |
nicklas |
137 |
|
5544 |
06 Aug 19 |
nicklas |
138 |
String pipelineName = (String)Annotationtype.PIPELINE.getAnnotationValue(dc, cufflinks); |
5544 |
06 Aug 19 |
nicklas |
139 |
Pipeline pipeline = Pipeline.getByName(pipelineName); |
5546 |
07 Aug 19 |
nicklas |
140 |
if (pipeline != Pipeline.RNASEQ_LEGACY) return false; |
6023 |
26 Oct 20 |
nicklas |
141 |
|
6023 |
26 Oct 20 |
nicklas |
// Pipelines for further processing |
6023 |
26 Oct 20 |
nicklas |
143 |
ItemList geneReportList = BiomaterialList.GENE_REPORT_CREATE.load(dc); |
6023 |
26 Oct 20 |
nicklas |
144 |
boolean geneReportDisabled = "Disable".equals(Annotationtype.AUTO_PROCESSING.getAnnotationValue(dc, geneReportList)); |
6023 |
26 Oct 20 |
nicklas |
145 |
ItemList pilotReportList = BiomaterialList.PILOT_REPORT_CREATE.load(dc); |
6023 |
26 Oct 20 |
nicklas |
146 |
boolean pilotReportDisabled = "Disable".equals(Annotationtype.AUTO_PROCESSING.getAnnotationValue(dc, pilotReportList)); |
5544 |
06 Aug 19 |
nicklas |
147 |
|
6023 |
26 Oct 20 |
nicklas |
148 |
if (geneReportDisabled && pilotReportDisabled) return false; |
6023 |
26 Oct 20 |
nicklas |
149 |
|
3618 |
23 Nov 15 |
nicklas |
150 |
Map<String, Software> reports = new HashMap<String, Software>(); |
3618 |
23 Nov 15 |
nicklas |
151 |
Software geneReport = Subtype.REPORT_SOFTWARE.getLatestProjectDefault(dc, Annotationtype.REPORT_TEMPLATE.createFilter("GENE_REPORT")); |
6023 |
26 Oct 20 |
nicklas |
152 |
if (!geneReportDisabled) reports.put("GENE_REPORT", geneReport); |
3618 |
23 Nov 15 |
nicklas |
153 |
Software pilotReport = Subtype.REPORT_SOFTWARE.getLatestProjectDefault(dc, Annotationtype.REPORT_TEMPLATE.createFilter("PILOT_REPORT")); |
6023 |
26 Oct 20 |
nicklas |
154 |
if (!pilotReportDisabled) reports.put("PILOT_REPORT", pilotReport); |
5615 |
19 Sep 19 |
nicklas |
155 |
GeneReportPlugin.createReportJob(dc, Collections.singletonList(cufflinks), reports, true); |
3055 |
19 Dec 14 |
nicklas |
156 |
dc.commit(); |
3055 |
19 Dec 14 |
nicklas |
157 |
} |
3055 |
19 Dec 14 |
nicklas |
158 |
finally |
3055 |
19 Dec 14 |
nicklas |
159 |
{ |
3055 |
19 Dec 14 |
nicklas |
160 |
if (dc != null) dc.close(); |
3055 |
19 Dec 14 |
nicklas |
161 |
} |
3055 |
19 Dec 14 |
nicklas |
162 |
return true; |
3055 |
19 Dec 14 |
nicklas |
163 |
} |
3034 |
12 Dec 14 |
nicklas |
164 |
|
3034 |
12 Dec 14 |
nicklas |
165 |
} |