Skip to content

Commit

Permalink
Add HCS JSON parsing demo
Browse files Browse the repository at this point in the history
  • Loading branch information
tischi committed Nov 22, 2023
1 parent 9e28cef commit e1485b0
Show file tree
Hide file tree
Showing 8 changed files with 92 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/main/java/org/embl/mobie/lib/hcs/omezarr/Column.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package org.embl.mobie.lib.hcs.omezarr;

public class Column
{
public String name;
}
6 changes: 6 additions & 0 deletions src/main/java/org/embl/mobie/lib/hcs/omezarr/HCSMetadata.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package org.embl.mobie.lib.hcs.omezarr;

public class HCSMetadata
{
public Plate plate;
}
6 changes: 6 additions & 0 deletions src/main/java/org/embl/mobie/lib/hcs/omezarr/Image.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package org.embl.mobie.lib.hcs.omezarr;

public class Image
{
public String path;
}
12 changes: 12 additions & 0 deletions src/main/java/org/embl/mobie/lib/hcs/omezarr/Plate.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package org.embl.mobie.lib.hcs.omezarr;

import java.util.List;

public class Plate
{
public List< Column > columns;
public int field_count;
public String name;
public List< Row > rows;
public List< Well > wells;
}
6 changes: 6 additions & 0 deletions src/main/java/org/embl/mobie/lib/hcs/omezarr/Row.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package org.embl.mobie.lib.hcs.omezarr;

public class Row
{
public String name;
}
9 changes: 9 additions & 0 deletions src/main/java/org/embl/mobie/lib/hcs/omezarr/Well.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package org.embl.mobie.lib.hcs.omezarr;

import java.util.List;

public class Well
{
public String path;
public List< Image > images;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package org.embl.mobie.lib.hcs.omezarr;

import java.util.List;

public class WellMetadata
{
public Well well;
}
39 changes: 39 additions & 0 deletions src/test/java/develop/ParseOMEZarrHCSMetadata.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package develop;

import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import org.embl.mobie.io.util.IOHelper;
import org.embl.mobie.lib.hcs.omezarr.HCSMetadata;
import org.embl.mobie.lib.hcs.omezarr.Well;
import org.embl.mobie.lib.hcs.omezarr.WellMetadata;
import org.embl.mobie.lib.serialize.JsonHelper;

import java.io.IOException;
import java.lang.reflect.Type;

public class ParseOMEZarrHCSMetadata
{

public static final String ZATTRS = "/.zattrs";

public static void main( String[] args ) throws IOException
{
Gson gson = JsonHelper.buildGson(false);

String url = "https://uk1s3.embassy.ebi.ac.uk/idr/zarr/v0.1/plates/5966.zarr";
final String plateJson = IOHelper.read( url + ZATTRS );
System.out.println( plateJson );
HCSMetadata hcsMetadata = gson.fromJson(plateJson, new TypeToken< HCSMetadata >() {}.getType());
String wellPath = hcsMetadata.plate.wells.get( 0 ).path;
System.out.printf( "Site path: " + wellPath );
String wellURL = url + "/" + wellPath ;
final String wellJson = IOHelper.read( wellURL + ZATTRS );
System.out.println( wellJson );

WellMetadata wellMetadata = gson.fromJson( wellJson, new TypeToken< WellMetadata >() {}.getType() );
String imagePath = wellMetadata.well.images.get( 0 ).path;
String imageURL = url + "/" + wellPath + "/" + imagePath;
final String imageJson = IOHelper.read( imageURL + ZATTRS );
System.out.println( imageJson );
}
}

0 comments on commit e1485b0

Please sign in to comment.