7006 |
24 Jan 23 |
nicklas |
1 |
package net.sf.basedb.reggie.plugins.release; |
7006 |
24 Jan 23 |
nicklas |
2 |
|
7006 |
24 Jan 23 |
nicklas |
3 |
import java.util.Arrays; |
7006 |
24 Jan 23 |
nicklas |
4 |
import java.util.HashSet; |
7006 |
24 Jan 23 |
nicklas |
5 |
import java.util.List; |
7006 |
24 Jan 23 |
nicklas |
6 |
|
7006 |
24 Jan 23 |
nicklas |
7 |
import org.json.simple.JSONArray; |
7006 |
24 Jan 23 |
nicklas |
8 |
import org.json.simple.JSONObject; |
7006 |
24 Jan 23 |
nicklas |
9 |
|
7006 |
24 Jan 23 |
nicklas |
10 |
import net.sf.basedb.core.DbControl; |
7006 |
24 Jan 23 |
nicklas |
11 |
import net.sf.basedb.core.DerivedBioAssay; |
7006 |
24 Jan 23 |
nicklas |
12 |
import net.sf.basedb.core.File; |
7019 |
27 Jan 23 |
nicklas |
13 |
import net.sf.basedb.core.Hardware; |
7006 |
24 Jan 23 |
nicklas |
14 |
import net.sf.basedb.core.Item; |
7006 |
24 Jan 23 |
nicklas |
15 |
import net.sf.basedb.core.Location; |
7019 |
27 Jan 23 |
nicklas |
16 |
import net.sf.basedb.core.Type; |
7006 |
24 Jan 23 |
nicklas |
17 |
import net.sf.basedb.reggie.dao.Annotationtype; |
7010 |
25 Jan 23 |
nicklas |
18 |
import net.sf.basedb.reggie.dao.BeadChip; |
7013 |
26 Jan 23 |
nicklas |
19 |
import net.sf.basedb.reggie.dao.Datafiletype; |
7009 |
25 Jan 23 |
nicklas |
20 |
import net.sf.basedb.reggie.dao.Dna; |
7006 |
24 Jan 23 |
nicklas |
21 |
import net.sf.basedb.reggie.dao.Methylation; |
7019 |
27 Jan 23 |
nicklas |
22 |
import net.sf.basedb.reggie.dao.Scan; |
7006 |
24 Jan 23 |
nicklas |
23 |
import net.sf.basedb.reggie.json.FilteredJSONArray; |
7006 |
24 Jan 23 |
nicklas |
24 |
import net.sf.basedb.util.filter.Filter; |
7006 |
24 Jan 23 |
nicklas |
25 |
import net.sf.basedb.util.filter.NotNullFilter; |
7006 |
24 Jan 23 |
nicklas |
26 |
|
7006 |
24 Jan 23 |
nicklas |
27 |
/** |
7006 |
24 Jan 23 |
nicklas |
Cohort writer implementation for Methylation data. |
7006 |
24 Jan 23 |
nicklas |
@since 4.44 |
7006 |
24 Jan 23 |
nicklas |
30 |
*/ |
7006 |
24 Jan 23 |
nicklas |
31 |
public class MethylationWriter |
7006 |
24 Jan 23 |
nicklas |
32 |
extends CohortWriter |
7006 |
24 Jan 23 |
nicklas |
33 |
{ |
7006 |
24 Jan 23 |
nicklas |
34 |
|
7006 |
24 Jan 23 |
nicklas |
35 |
private final ScriptWriter scriptWriter; |
7006 |
24 Jan 23 |
nicklas |
36 |
private final Filter<File> fileFilterMethylation; |
7006 |
24 Jan 23 |
nicklas |
37 |
|
7006 |
24 Jan 23 |
nicklas |
38 |
public MethylationWriter(DbControl dc, ReleaseWriterOptions options, ScriptWriter scriptWriter) |
7006 |
24 Jan 23 |
nicklas |
39 |
{ |
7006 |
24 Jan 23 |
nicklas |
40 |
super(dc, options); |
7006 |
24 Jan 23 |
nicklas |
41 |
this.scriptWriter = scriptWriter; |
7006 |
24 Jan 23 |
nicklas |
42 |
this.fileFilterMethylation = new FileListFilter(new HashSet<String>(Arrays.asList( |
7013 |
26 Jan 23 |
nicklas |
43 |
"beta_normalized.tsv.gz", "beta_adjusted.tsv.gz", "adjustmentPlots.pdf" |
7013 |
26 Jan 23 |
nicklas |
44 |
)), true, new FileLocationFilter(Location.EXTERNAL, true)); |
7006 |
24 Jan 23 |
nicklas |
45 |
} |
7006 |
24 Jan 23 |
nicklas |
46 |
|
7006 |
24 Jan 23 |
nicklas |
47 |
@Override |
7006 |
24 Jan 23 |
nicklas |
48 |
public JSONArray toJSONObjects(CohortItem item) |
7006 |
24 Jan 23 |
nicklas |
49 |
{ |
7006 |
24 Jan 23 |
nicklas |
50 |
List<Methylation> methylation = item.getMethylationBioAssays(); |
7006 |
24 Jan 23 |
nicklas |
51 |
if (methylation.size() == 0) return null; |
7006 |
24 Jan 23 |
nicklas |
52 |
DbControl dc = item.getDbControl(); |
7006 |
24 Jan 23 |
nicklas |
53 |
|
7006 |
24 Jan 23 |
nicklas |
54 |
JSONArray json = new JSONArray(); |
7006 |
24 Jan 23 |
nicklas |
55 |
for (Methylation m : methylation) |
7006 |
24 Jan 23 |
nicklas |
56 |
{ |
7010 |
25 Jan 23 |
nicklas |
57 |
DerivedBioAssay meth = m.getDerivedBioAssay(); |
7010 |
25 Jan 23 |
nicklas |
58 |
BeadChip chip = m.getBeadChip(dc); |
7010 |
25 Jan 23 |
nicklas |
59 |
Dna dnaAliquot = m.getDnaAliquot(dc); |
7010 |
25 Jan 23 |
nicklas |
60 |
Dna dna = dnaAliquot.getTopDna(dc); |
7019 |
27 Jan 23 |
nicklas |
61 |
Scan scan = m.getScan(dc); |
7019 |
27 Jan 23 |
nicklas |
62 |
Hardware scanner = scan.getItem().getHardware(); |
7006 |
24 Jan 23 |
nicklas |
63 |
|
7006 |
24 Jan 23 |
nicklas |
64 |
JSONObject jsonMeth = new JSONObject(); |
7006 |
24 Jan 23 |
nicklas |
65 |
jsonMeth.put("name", item.toReleaseId(meth.getName())); |
7006 |
24 Jan 23 |
nicklas |
66 |
jsonMeth.put("type", meth.getType().name()); |
7006 |
24 Jan 23 |
nicklas |
67 |
jsonMeth.put("subtype", getName(meth.getItemSubtype())); |
7006 |
24 Jan 23 |
nicklas |
68 |
jsonMeth.put("extract", item.toReleaseId(dna.getName())); |
7006 |
24 Jan 23 |
nicklas |
69 |
|
7006 |
24 Jan 23 |
nicklas |
70 |
JSONArray jsonAnnotations = new FilteredJSONArray(new NotNullFilter<>(false)); |
7006 |
24 Jan 23 |
nicklas |
71 |
jsonMeth.put("annotations", jsonAnnotations); |
7006 |
24 Jan 23 |
nicklas |
72 |
jsonAnnotations.add(item.getAnnotationJSON(Annotationtype.PIPELINE, meth, null)); |
7020 |
27 Jan 23 |
nicklas |
73 |
jsonAnnotations.add(item.getAnnotationJSON(Annotationtype.MEDIAN_METH, meth, null)); |
7020 |
27 Jan 23 |
nicklas |
74 |
jsonAnnotations.add(item.getAnnotationJSON(Annotationtype.MEDIAN_UNMETH, meth, null)); |
7020 |
27 Jan 23 |
nicklas |
75 |
jsonAnnotations.add(item.getAnnotationJSON(Annotationtype.NUM_PROBES, meth, null)); |
7020 |
27 Jan 23 |
nicklas |
76 |
jsonAnnotations.add(item.getAnnotationJSON(Annotationtype.NUM_PROBES_BAD_PVAL, meth, null)); |
7020 |
27 Jan 23 |
nicklas |
77 |
jsonAnnotations.add(item.getAnnotationJSON(Annotationtype.NUM_PROBES_I, meth, null)); |
7020 |
27 Jan 23 |
nicklas |
78 |
jsonAnnotations.add(item.getAnnotationJSON(Annotationtype.NUM_PROBES_II, meth, null)); |
7020 |
27 Jan 23 |
nicklas |
79 |
jsonAnnotations.add(item.getAnnotationJSON(Annotationtype.PEAK_METH_I, meth, null)); |
7020 |
27 Jan 23 |
nicklas |
80 |
jsonAnnotations.add(item.getAnnotationJSON(Annotationtype.PEAK_METH_II, meth, null)); |
7020 |
27 Jan 23 |
nicklas |
81 |
jsonAnnotations.add(item.getAnnotationJSON(Annotationtype.PEAK_UNMETH_I, meth, null)); |
7020 |
27 Jan 23 |
nicklas |
82 |
jsonAnnotations.add(item.getAnnotationJSON(Annotationtype.PEAK_UNMETH_II, meth, null)); |
7020 |
27 Jan 23 |
nicklas |
83 |
|
7010 |
25 Jan 23 |
nicklas |
84 |
jsonAnnotations.add(item.getAnnotationJSON(Annotationtype.BEADCHIP_ID, chip, null)); |
7010 |
25 Jan 23 |
nicklas |
85 |
jsonAnnotations.add(item.getAnnotationJSON(Annotationtype.BEADCHIP_TYPE, chip, null)); |
7010 |
25 Jan 23 |
nicklas |
86 |
jsonAnnotations.add(item.getAnnotationJSON(Annotationtype.BEADCHIP_POSITION, dnaAliquot, null)); |
7019 |
27 Jan 23 |
nicklas |
87 |
jsonAnnotations.add(item.createAnnotationJSON("ScannerModel", Annotationtype.HARDWARE_MODEL.getAnnotationValue(dc, scanner))); |
7019 |
27 Jan 23 |
nicklas |
88 |
jsonAnnotations.add(item.createAnnotationJSON("ScannerSerial", Annotationtype.SERIAL_NUMBER.getAnnotationValue(dc, scanner))); |
7020 |
27 Jan 23 |
nicklas |
89 |
jsonAnnotations.add(item.createAnnotationJSON("MethylationSoftware", getName(meth.getSoftware()))); |
7006 |
24 Jan 23 |
nicklas |
90 |
|
7006 |
24 Jan 23 |
nicklas |
// Folders and files |
7006 |
24 Jan 23 |
nicklas |
92 |
String dataFilesFolder = (String)item.getAnnotationValue(Annotationtype.DATA_FILES_FOLDER, meth); |
7006 |
24 Jan 23 |
nicklas |
93 |
String releaseDataFilesFolder = item.toReleaseFolder(dataFilesFolder); |
7006 |
24 Jan 23 |
nicklas |
94 |
JSONObject jsonDataFilesFolder = item.createAnnotationJSON(Annotationtype.DATA_FILES_FOLDER.getName(), releaseDataFilesFolder); |
7006 |
24 Jan 23 |
nicklas |
95 |
jsonAnnotations.add(jsonDataFilesFolder); |
7006 |
24 Jan 23 |
nicklas |
96 |
|
7013 |
26 Jan 23 |
nicklas |
97 |
JSONArray jsonFiles = new FilteredJSONArray(new NotNullFilter<>(false)); |
7013 |
26 Jan 23 |
nicklas |
98 |
jsonFiles.addAll(item.getDataFilesJSON(Datafiletype.IDAT, meth, null, true)); |
7013 |
26 Jan 23 |
nicklas |
99 |
jsonFiles.addAll(item.getLinkedFilesJSON(meth, fileFilterMethylation, false)); |
7013 |
26 Jan 23 |
nicklas |
100 |
jsonMeth.put("files", jsonFiles); |
7013 |
26 Jan 23 |
nicklas |
101 |
if (scriptWriter != null) |
7013 |
26 Jan 23 |
nicklas |
102 |
{ |
7013 |
26 Jan 23 |
nicklas |
103 |
scriptWriter.addFiles(releaseDataFilesFolder, dataFilesFolder, null, jsonFiles); |
7013 |
26 Jan 23 |
nicklas |
104 |
} |
7006 |
24 Jan 23 |
nicklas |
105 |
|
7006 |
24 Jan 23 |
nicklas |
106 |
json.add(jsonMeth); |
7006 |
24 Jan 23 |
nicklas |
107 |
} |
7006 |
24 Jan 23 |
nicklas |
108 |
return json; |
7006 |
24 Jan 23 |
nicklas |
109 |
} |
7006 |
24 Jan 23 |
nicklas |
110 |
|
7006 |
24 Jan 23 |
nicklas |
111 |
@Override |
7006 |
24 Jan 23 |
nicklas |
112 |
public List<CohortTypeDef> getTypeDefsInJSON() |
7006 |
24 Jan 23 |
nicklas |
113 |
{ |
7006 |
24 Jan 23 |
nicklas |
114 |
DbControl dc = getDbControl(); |
7006 |
24 Jan 23 |
nicklas |
115 |
|
7006 |
24 Jan 23 |
nicklas |
116 |
CohortTypeDefFactory methFactory = new CohortTypeDefFactory(dc, Item.DERIVEDBIOASSAY, "Methylation"); |
7006 |
24 Jan 23 |
nicklas |
117 |
|
7006 |
24 Jan 23 |
nicklas |
118 |
methFactory.createAnnotationType(Annotationtype.PIPELINE); |
7020 |
27 Jan 23 |
nicklas |
119 |
methFactory.createAnnotationType(Annotationtype.MEDIAN_METH); |
7020 |
27 Jan 23 |
nicklas |
120 |
methFactory.createAnnotationType(Annotationtype.MEDIAN_UNMETH); |
7020 |
27 Jan 23 |
nicklas |
121 |
methFactory.createAnnotationType(Annotationtype.NUM_PROBES); |
7020 |
27 Jan 23 |
nicklas |
122 |
methFactory.createAnnotationType(Annotationtype.NUM_PROBES_BAD_PVAL); |
7020 |
27 Jan 23 |
nicklas |
123 |
methFactory.createAnnotationType(Annotationtype.NUM_PROBES_I); |
7020 |
27 Jan 23 |
nicklas |
124 |
methFactory.createAnnotationType(Annotationtype.NUM_PROBES_II); |
7020 |
27 Jan 23 |
nicklas |
125 |
methFactory.createAnnotationType(Annotationtype.PEAK_METH_I); |
7020 |
27 Jan 23 |
nicklas |
126 |
methFactory.createAnnotationType(Annotationtype.PEAK_METH_II); |
7020 |
27 Jan 23 |
nicklas |
127 |
methFactory.createAnnotationType(Annotationtype.PEAK_UNMETH_I); |
7020 |
27 Jan 23 |
nicklas |
128 |
methFactory.createAnnotationType(Annotationtype.PEAK_UNMETH_II); |
7006 |
24 Jan 23 |
nicklas |
129 |
|
7010 |
25 Jan 23 |
nicklas |
130 |
methFactory.createAnnotationType(Annotationtype.BEADCHIP_ID); |
7010 |
25 Jan 23 |
nicklas |
131 |
methFactory.createAnnotationType(Annotationtype.BEADCHIP_POSITION); |
7010 |
25 Jan 23 |
nicklas |
132 |
methFactory.createAnnotationType(Annotationtype.BEADCHIP_TYPE); |
7019 |
27 Jan 23 |
nicklas |
133 |
methFactory.createAnnotationType("ScannerModel", Type.STRING); |
7019 |
27 Jan 23 |
nicklas |
134 |
methFactory.createAnnotationType("ScannerSerial", Type.STRING); |
7020 |
27 Jan 23 |
nicklas |
135 |
methFactory.createAnnotationType("MethylationSoftware", Type.STRING); |
7010 |
25 Jan 23 |
nicklas |
136 |
|
7006 |
24 Jan 23 |
nicklas |
137 |
methFactory.createAnnotationType(Annotationtype.DATA_FILES_FOLDER).setProjectSpecificValues(true); |
7013 |
26 Jan 23 |
nicklas |
138 |
methFactory.createFileType(Datafiletype.IDAT); |
7006 |
24 Jan 23 |
nicklas |
139 |
|
7006 |
24 Jan 23 |
nicklas |
140 |
return methFactory.allCreated(); |
7006 |
24 Jan 23 |
nicklas |
141 |
} |
7006 |
24 Jan 23 |
nicklas |
142 |
|
7006 |
24 Jan 23 |
nicklas |
143 |
} |