extensions/net.sf.basedb.reggie/trunk/src/net/sf/basedb/reggie/plugins/release/OncoarrayWriter.java

Code
Comments
Other
Rev Date Author Line
7007 25 Jan 23 nicklas 1 package net.sf.basedb.reggie.plugins.release;
7007 25 Jan 23 nicklas 2
7007 25 Jan 23 nicklas 3 import java.util.Arrays;
7007 25 Jan 23 nicklas 4 import java.util.HashSet;
7007 25 Jan 23 nicklas 5 import java.util.List;
7007 25 Jan 23 nicklas 6
7007 25 Jan 23 nicklas 7 import org.json.simple.JSONArray;
7007 25 Jan 23 nicklas 8 import org.json.simple.JSONObject;
7007 25 Jan 23 nicklas 9
7007 25 Jan 23 nicklas 10 import net.sf.basedb.core.DbControl;
7007 25 Jan 23 nicklas 11 import net.sf.basedb.core.File;
7017 27 Jan 23 nicklas 12 import net.sf.basedb.core.Hardware;
7007 25 Jan 23 nicklas 13 import net.sf.basedb.core.Item;
7007 25 Jan 23 nicklas 14 import net.sf.basedb.core.Location;
7007 25 Jan 23 nicklas 15 import net.sf.basedb.core.RawBioAssay;
7007 25 Jan 23 nicklas 16 import net.sf.basedb.core.RawDataType;
7017 27 Jan 23 nicklas 17 import net.sf.basedb.core.Type;
7007 25 Jan 23 nicklas 18 import net.sf.basedb.reggie.dao.Annotationtype;
7011 25 Jan 23 nicklas 19 import net.sf.basedb.reggie.dao.BeadChip;
7007 25 Jan 23 nicklas 20 import net.sf.basedb.reggie.dao.BloodDna;
7014 26 Jan 23 nicklas 21 import net.sf.basedb.reggie.dao.Datafiletype;
7011 25 Jan 23 nicklas 22 import net.sf.basedb.reggie.dao.GenotypeCall;
7007 25 Jan 23 nicklas 23 import net.sf.basedb.reggie.dao.Rawbioassay;
7007 25 Jan 23 nicklas 24 import net.sf.basedb.reggie.dao.Rawdatatype;
7017 27 Jan 23 nicklas 25 import net.sf.basedb.reggie.dao.Scan;
7007 25 Jan 23 nicklas 26 import net.sf.basedb.reggie.json.FilteredJSONArray;
7007 25 Jan 23 nicklas 27 import net.sf.basedb.util.filter.Filter;
7007 25 Jan 23 nicklas 28 import net.sf.basedb.util.filter.NotNullFilter;
7007 25 Jan 23 nicklas 29
7007 25 Jan 23 nicklas 30 /**
7007 25 Jan 23 nicklas 31   Cohort writer implementation for Oncoarray data.
7007 25 Jan 23 nicklas 32   @since 4.44
7007 25 Jan 23 nicklas 33 */
7007 25 Jan 23 nicklas 34 public class OncoarrayWriter 
7007 25 Jan 23 nicklas 35   extends CohortWriter 
7007 25 Jan 23 nicklas 36 {
7007 25 Jan 23 nicklas 37
7007 25 Jan 23 nicklas 38   private final ScriptWriter scriptWriter;
7007 25 Jan 23 nicklas 39   private final Filter<File> fileFilterOncoarray;
7007 25 Jan 23 nicklas 40   
7007 25 Jan 23 nicklas 41   public OncoarrayWriter(DbControl dc, ReleaseWriterOptions options, ScriptWriter scriptWriter)
7007 25 Jan 23 nicklas 42   {
7007 25 Jan 23 nicklas 43     super(dc, options);
7007 25 Jan 23 nicklas 44     this.scriptWriter = scriptWriter;
7007 25 Jan 23 nicklas 45     this.fileFilterOncoarray = new FileListFilter(new HashSet<String>(Arrays.asList(
7014 26 Jan 23 nicklas 46       "genotypes_all.vcf.gz", "genotype_call.gtc"
7014 26 Jan 23 nicklas 47       )), true, new FileLocationFilter(Location.EXTERNAL, true));
7007 25 Jan 23 nicklas 48   }
7007 25 Jan 23 nicklas 49   
7007 25 Jan 23 nicklas 50   @Override
7007 25 Jan 23 nicklas 51   public JSONArray toJSONObjects(CohortItem item)
7007 25 Jan 23 nicklas 52   {
7007 25 Jan 23 nicklas 53     List<Rawbioassay> oncoArray = item.getOncoArrayBioAssays();
7007 25 Jan 23 nicklas 54     if (oncoArray.size() == 0) return null;
7007 25 Jan 23 nicklas 55     DbControl dc = item.getDbControl();
7007 25 Jan 23 nicklas 56     
7007 25 Jan 23 nicklas 57     JSONArray json = new JSONArray();
7007 25 Jan 23 nicklas 58     for (Rawbioassay raw : oncoArray)
7007 25 Jan 23 nicklas 59     {
7007 25 Jan 23 nicklas 60       RawBioAssay rba = raw.getItem();
7007 25 Jan 23 nicklas 61       RawDataType rawType = rba.getRawDataType();
7011 25 Jan 23 nicklas 62       BloodDna dnaAliquot = BloodDna.get(rba.getParentExtract());
7011 25 Jan 23 nicklas 63       BloodDna dna = dnaAliquot.getTopDna(dc);
7011 25 Jan 23 nicklas 64       GenotypeCall genotypeCall = GenotypeCall.get(rba.getParentBioAssay());
7011 25 Jan 23 nicklas 65       BeadChip chip = genotypeCall.getBeadChip(dc);
7017 27 Jan 23 nicklas 66       Scan scan = genotypeCall.getScan(dc);
7017 27 Jan 23 nicklas 67       Hardware scanner = scan.getItem().getHardware();
7007 25 Jan 23 nicklas 68       
7007 25 Jan 23 nicklas 69       JSONObject jsonRaw = new JSONObject();
7007 25 Jan 23 nicklas 70       jsonRaw.put("name", item.toReleaseId(raw.getName()));
7007 25 Jan 23 nicklas 71       jsonRaw.put("type", rba.getType().name());
7007 25 Jan 23 nicklas 72       jsonRaw.put("rawdatatype", rawType.getId());
7007 25 Jan 23 nicklas 73       jsonRaw.put("platform", Rawdatatype.ONCOARRAY500K.getPlatformId());
7007 25 Jan 23 nicklas 74       jsonRaw.put("platformVariant", Rawdatatype.ONCOARRAY500K.getVariantId());
7007 25 Jan 23 nicklas 75       jsonRaw.put("extract", item.toReleaseId(dna.getName()));
7007 25 Jan 23 nicklas 76   
7007 25 Jan 23 nicklas 77       JSONArray jsonAnnotations = new FilteredJSONArray(new NotNullFilter<>(false));
7007 25 Jan 23 nicklas 78       jsonRaw.put("annotations", jsonAnnotations);
7007 25 Jan 23 nicklas 79       jsonAnnotations.add(item.getAnnotationJSON(Annotationtype.PIPELINE, rba, null));
7018 27 Jan 23 nicklas 80
7018 27 Jan 23 nicklas 81       jsonAnnotations.add(item.getAnnotationJSON(Annotationtype.GENOTYPE_COUNT, rba, null));
7018 27 Jan 23 nicklas 82       jsonAnnotations.add(item.getAnnotationJSON(Annotationtype.GENOTYPE_REF_PCT, rba, null));
7018 27 Jan 23 nicklas 83       jsonAnnotations.add(item.getAnnotationJSON(Annotationtype.GENOTYPE_ALT_PCT, rba, null));
7018 27 Jan 23 nicklas 84       jsonAnnotations.add(item.getAnnotationJSON(Annotationtype.GENOTYPE_HET_PCT, rba, null));
7018 27 Jan 23 nicklas 85
7018 27 Jan 23 nicklas 86       jsonAnnotations.add(item.getAnnotationJSON(Annotationtype.NUM_CALLS, genotypeCall, null));
7018 27 Jan 23 nicklas 87       jsonAnnotations.add(item.getAnnotationJSON(Annotationtype.NUM_NO_CALLS, genotypeCall, null));
7018 27 Jan 23 nicklas 88       jsonAnnotations.add(item.getAnnotationJSON(Annotationtype.CALL_RATE, genotypeCall, null));
7018 27 Jan 23 nicklas 89       jsonAnnotations.add(item.getAnnotationJSON(Annotationtype.GC10, genotypeCall, null));
7018 27 Jan 23 nicklas 90       jsonAnnotations.add(item.getAnnotationJSON(Annotationtype.GC50, genotypeCall, null));
7018 27 Jan 23 nicklas 91       jsonAnnotations.add(item.getAnnotationJSON(Annotationtype.LOG_R_DEV, genotypeCall, null));
7018 27 Jan 23 nicklas 92       
7011 25 Jan 23 nicklas 93       jsonAnnotations.add(item.getAnnotationJSON(Annotationtype.BEADCHIP_ID, chip, null));
7011 25 Jan 23 nicklas 94       jsonAnnotations.add(item.getAnnotationJSON(Annotationtype.BEADCHIP_TYPE, chip, null));
7011 25 Jan 23 nicklas 95       jsonAnnotations.add(item.getAnnotationJSON(Annotationtype.BEADCHIP_POSITION, dnaAliquot, null));
7017 27 Jan 23 nicklas 96       jsonAnnotations.add(item.createAnnotationJSON("ScannerModel", Annotationtype.HARDWARE_MODEL.getAnnotationValue(dc, scanner)));
7017 27 Jan 23 nicklas 97       jsonAnnotations.add(item.createAnnotationJSON("ScannerSerial", Annotationtype.SERIAL_NUMBER.getAnnotationValue(dc, scanner)));
7017 27 Jan 23 nicklas 98       jsonAnnotations.add(item.createAnnotationJSON("GenotypeCallSoftware", getName(rba.getSoftware())));
7007 25 Jan 23 nicklas 99       
7007 25 Jan 23 nicklas 100       // Folders and files
7014 26 Jan 23 nicklas 101       // We have files on the GenotypeCall (DERIVEDBIOASSAY) and OncoArray500K (RAWBIOASSAY)
7014 26 Jan 23 nicklas 102       // that must be copied to the same destination folder
7014 26 Jan 23 nicklas 103       String dataFilesFolderRba = (String)item.getAnnotationValue(Annotationtype.DATA_FILES_FOLDER, rba);
7014 26 Jan 23 nicklas 104       String dataFilesFolderGtc = (String)item.getAnnotationValue(Annotationtype.DATA_FILES_FOLDER, genotypeCall);
7014 26 Jan 23 nicklas 105       String releaseDataFilesFolder = item.toReleaseFolder(dataFilesFolderRba).replace("gt/v", "gt.v");
7007 25 Jan 23 nicklas 106       JSONObject jsonDataFilesFolder = item.createAnnotationJSON(Annotationtype.DATA_FILES_FOLDER.getName(), releaseDataFilesFolder);
7007 25 Jan 23 nicklas 107       jsonAnnotations.add(jsonDataFilesFolder);
7007 25 Jan 23 nicklas 108   
7014 26 Jan 23 nicklas 109       JSONArray jsonFilesRba = item.getDataFilesJSON(Datafiletype.VCF, rba, fileFilterOncoarray, false);
7014 26 Jan 23 nicklas 110       JSONArray jsonFilesGtc = item.getDataFilesJSON(Datafiletype.GTC, genotypeCall.getItem(), fileFilterOncoarray, false);
7007 25 Jan 23 nicklas 111       
7014 26 Jan 23 nicklas 112       JSONArray jsonFiles = new FilteredJSONArray(new NotNullFilter<>(false));
7014 26 Jan 23 nicklas 113       jsonFiles.addAll(jsonFilesRba);
7014 26 Jan 23 nicklas 114       jsonFiles.addAll(jsonFilesGtc);
7014 26 Jan 23 nicklas 115       jsonRaw.put("files", jsonFiles);
7014 26 Jan 23 nicklas 116       
7014 26 Jan 23 nicklas 117       if (scriptWriter != null) 
7014 26 Jan 23 nicklas 118       {
7014 26 Jan 23 nicklas 119         scriptWriter.addFiles(releaseDataFilesFolder, dataFilesFolderRba, null, jsonFilesRba);
7014 26 Jan 23 nicklas 120         scriptWriter.addFiles(releaseDataFilesFolder, dataFilesFolderGtc, null, jsonFilesGtc);
7014 26 Jan 23 nicklas 121       }
7014 26 Jan 23 nicklas 122       
7007 25 Jan 23 nicklas 123       json.add(jsonRaw);
7007 25 Jan 23 nicklas 124     }
7007 25 Jan 23 nicklas 125     return json;
7007 25 Jan 23 nicklas 126   }
7007 25 Jan 23 nicklas 127   
7007 25 Jan 23 nicklas 128   @Override
7007 25 Jan 23 nicklas 129   public List<CohortTypeDef> getTypeDefsInJSON()
7007 25 Jan 23 nicklas 130   {
7007 25 Jan 23 nicklas 131     DbControl dc = getDbControl();
7007 25 Jan 23 nicklas 132     
7007 25 Jan 23 nicklas 133     CohortTypeDefFactory rawFactory = new CohortTypeDefFactory(dc, Item.RAWBIOASSAY, "OncoArray500K");
7007 25 Jan 23 nicklas 134     
7007 25 Jan 23 nicklas 135     rawFactory.createAnnotationType(Annotationtype.PIPELINE);
7018 27 Jan 23 nicklas 136     rawFactory.createAnnotationType(Annotationtype.GENOTYPE_COUNT);
7018 27 Jan 23 nicklas 137     rawFactory.createAnnotationType(Annotationtype.GENOTYPE_REF_PCT);
7018 27 Jan 23 nicklas 138     rawFactory.createAnnotationType(Annotationtype.GENOTYPE_ALT_PCT);
7018 27 Jan 23 nicklas 139     rawFactory.createAnnotationType(Annotationtype.GENOTYPE_HET_PCT);
7018 27 Jan 23 nicklas 140     
7018 27 Jan 23 nicklas 141     rawFactory.createAnnotationType(Annotationtype.NUM_CALLS);
7018 27 Jan 23 nicklas 142     rawFactory.createAnnotationType(Annotationtype.NUM_NO_CALLS);
7018 27 Jan 23 nicklas 143     rawFactory.createAnnotationType(Annotationtype.CALL_RATE);
7018 27 Jan 23 nicklas 144     rawFactory.createAnnotationType(Annotationtype.GC10);
7018 27 Jan 23 nicklas 145     rawFactory.createAnnotationType(Annotationtype.GC50);
7018 27 Jan 23 nicklas 146     rawFactory.createAnnotationType(Annotationtype.LOG_R_DEV);
7018 27 Jan 23 nicklas 147
7011 25 Jan 23 nicklas 148     rawFactory.createAnnotationType(Annotationtype.BEADCHIP_ID);
7011 25 Jan 23 nicklas 149     rawFactory.createAnnotationType(Annotationtype.BEADCHIP_POSITION);
7011 25 Jan 23 nicklas 150     rawFactory.createAnnotationType(Annotationtype.BEADCHIP_TYPE);
7017 27 Jan 23 nicklas 151     rawFactory.createAnnotationType("ScannerModel", Type.STRING);
7017 27 Jan 23 nicklas 152     rawFactory.createAnnotationType("ScannerSerial", Type.STRING);
7017 27 Jan 23 nicklas 153     rawFactory.createAnnotationType("GenotypeCallSoftware", Type.STRING);
7007 25 Jan 23 nicklas 154     
7007 25 Jan 23 nicklas 155     rawFactory.createAnnotationType(Annotationtype.DATA_FILES_FOLDER).setProjectSpecificValues(true);
7014 26 Jan 23 nicklas 156     rawFactory.createFileType(Datafiletype.VCF, Rawdatatype.ONCOARRAY500K);
7014 26 Jan 23 nicklas 157     rawFactory.createFileType(Datafiletype.GTC, Rawdatatype.ONCOARRAY500K);
7007 25 Jan 23 nicklas 158     
7007 25 Jan 23 nicklas 159     return rawFactory.allCreated();
7007 25 Jan 23 nicklas 160   }
7007 25 Jan 23 nicklas 161
7007 25 Jan 23 nicklas 162 }