Skip to content

Commit 78dda48

Browse files
committed
Add basic feature declarations expected by TrackMate
1 parent 2961a4d commit 78dda48

2 files changed

Lines changed: 98 additions & 2 deletions

File tree

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
package org.mastodon.mamut.io.importer.trackmate;
2+
3+
import static org.mastodon.mamut.io.importer.trackmate.TrackMateXMLKeys.FEATURE_ATTRIBUTE;
4+
import static org.mastodon.mamut.io.importer.trackmate.TrackMateXMLKeys.FEATURE_DIMENSION_ATTRIBUTE;
5+
import static org.mastodon.mamut.io.importer.trackmate.TrackMateXMLKeys.FEATURE_ISINT_ATTRIBUTE;
6+
import static org.mastodon.mamut.io.importer.trackmate.TrackMateXMLKeys.FEATURE_NAME_ATTRIBUTE;
7+
import static org.mastodon.mamut.io.importer.trackmate.TrackMateXMLKeys.FEATURE_SHORT_NAME_ATTRIBUTE;
8+
import static org.mastodon.mamut.io.importer.trackmate.TrackMateXMLKeys.FEATURE_TAG;
9+
10+
import java.util.Arrays;
11+
import java.util.List;
12+
13+
import org.jdom2.Element;
14+
15+
public class CommonTrackMateFeatureDeclarations
16+
{
17+
18+
public static final List< CommonTrackMateFeatureDeclaration > spotFeatureDeclarations = Arrays.asList( new CommonTrackMateFeatureDeclaration[] {
19+
new CommonTrackMateFeatureDeclaration( TrackMateXMLKeys.VISIBILITY_FEATURE_NAME, "Visibility", "Visibility", "NONE", true ),
20+
new CommonTrackMateFeatureDeclaration( TrackMateXMLKeys.POSITION_X_FEATURE_NAME, "X", "X", "POSITION", false ),
21+
new CommonTrackMateFeatureDeclaration( TrackMateXMLKeys.POSITION_Y_FEATURE_NAME, "Y", "Y", "POSITION", false ),
22+
new CommonTrackMateFeatureDeclaration( TrackMateXMLKeys.POSITION_Z_FEATURE_NAME, "Z", "Z", "POSITION", false ),
23+
new CommonTrackMateFeatureDeclaration( TrackMateXMLKeys.POSITION_T_FEATURE_NAME, "T", "T", "TIME", false ),
24+
new CommonTrackMateFeatureDeclaration( TrackMateXMLKeys.FRAME_FEATURE_NAME, "Frame", "Frame", "NONE", true ),
25+
new CommonTrackMateFeatureDeclaration( TrackMateXMLKeys.RADIUS_FEATURE_NAME, "Radius", "R", "LENGTH", false ),
26+
new CommonTrackMateFeatureDeclaration( TrackMateXMLKeys.QUALITY_FEATURE_NAME, "Quality", "Quality", "QUALITY", false ),
27+
} );
28+
29+
public static final List< CommonTrackMateFeatureDeclaration > edgeFeatureDeclarations = Arrays.asList( new CommonTrackMateFeatureDeclaration[] {
30+
new CommonTrackMateFeatureDeclaration( TrackMateXMLKeys.EDGE_SOURCE_ATTRIBUTE, "Source spot ID", "Source ID", "NONE", true ),
31+
new CommonTrackMateFeatureDeclaration( TrackMateXMLKeys.EDGE_TARGET_ATTRIBUTE, "Target spot ID", "Target ID", "NONE", true ),
32+
} );
33+
34+
public static final List< CommonTrackMateFeatureDeclaration > trackFeatureDeclarations = Arrays.asList( new CommonTrackMateFeatureDeclaration[] {
35+
new CommonTrackMateFeatureDeclaration( TrackMateXMLKeys.TRACK_ID_ATTRIBUTE, "Track ID", "ID", "NONE", true ),
36+
} );
37+
38+
public static class CommonTrackMateFeatureDeclaration
39+
{
40+
public final String key;
41+
42+
public final String name;
43+
44+
public final String shortName;
45+
46+
public final String dimension;
47+
48+
public final boolean isInt;
49+
50+
public CommonTrackMateFeatureDeclaration( final String key, final String name, final String shortName, final String dimension, final boolean isInt )
51+
{
52+
this.key = key;
53+
this.name = name;
54+
this.shortName = shortName;
55+
this.dimension = dimension;
56+
this.isInt = isInt;
57+
}
58+
59+
public Element toElement()
60+
{
61+
final Element fel = new Element( FEATURE_TAG );
62+
fel.setAttribute( FEATURE_ATTRIBUTE, key );
63+
fel.setAttribute( FEATURE_NAME_ATTRIBUTE, name );
64+
fel.setAttribute( FEATURE_SHORT_NAME_ATTRIBUTE, shortName );
65+
fel.setAttribute( FEATURE_DIMENSION_ATTRIBUTE, dimension );
66+
fel.setAttribute( FEATURE_ISINT_ATTRIBUTE, "" + isInt );
67+
return fel;
68+
}
69+
}
70+
}

src/main/java/org/mastodon/mamut/io/importer/trackmate/MamutExporter.java

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -682,13 +682,29 @@ else if ( origName.startsWith( "IMPORTED_" ) )
682682
private Element featuresDeclarationToXml()
683683
{
684684
final Element featuresElement = new Element( FEATURE_DECLARATION_TAG );
685+
appendBasicFeatureDeclarations( featuresElement );
685686
appendFeaturesDeclarationOfClass( Spot.class, featuresElement, SPOT_FEATURE_DECLARATION_TAG );
686687
appendFeaturesDeclarationOfClass( Link.class, featuresElement, EDGE_FEATURE_DECLARATION_TAG );
687688
// Create an empty declaration for track features, for now.
688689
appendFeaturesDeclarationOfClass( Boolean.class, featuresElement, TRACK_FEATURE_DECLARATION_TAG );
689690
return featuresElement;
690691
}
691692

693+
private void appendBasicFeatureDeclarations( final Element featuresElement )
694+
{
695+
// Spots.
696+
final Element spotFeaturesElement = getOrAddChild( featuresElement, SPOT_FEATURE_DECLARATION_TAG );
697+
CommonTrackMateFeatureDeclarations.spotFeatureDeclarations.forEach( cf -> spotFeaturesElement.addContent( cf.toElement() ) );
698+
699+
// Edges.
700+
final Element edgeFeaturesElement = getOrAddChild( featuresElement, EDGE_FEATURE_DECLARATION_TAG );
701+
CommonTrackMateFeatureDeclarations.edgeFeatureDeclarations.forEach( cf -> edgeFeaturesElement.addContent( cf.toElement() ) );
702+
703+
// Tracks.
704+
final Element trackFeaturesElement = getOrAddChild( featuresElement, TRACK_FEATURE_DECLARATION_TAG );
705+
CommonTrackMateFeatureDeclarations.trackFeatureDeclarations.forEach( cf -> trackFeaturesElement.addContent( cf.toElement() ) );
706+
}
707+
692708
@SuppressWarnings( { "unchecked", "rawtypes" } )
693709
private < T > void appendFeaturesDeclarationOfClass( final Class< T > clazz, final Element featuresElement,
694710
final String classFeatureDeclarationTag )
@@ -701,7 +717,7 @@ else if ( clazz.equals( Link.class ) )
701717
else
702718
projections = Collections.emptyList();
703719

704-
final Element classFeaturesElement = new Element( classFeatureDeclarationTag );
720+
final Element classFeaturesElement = getOrAddChild( featuresElement, classFeatureDeclarationTag );
705721
for ( final ExportFeatureProjection< T > p : projections )
706722
{
707723
final String isint = ( p.projection instanceof IntFeatureProjection )
@@ -719,7 +735,17 @@ else if ( clazz.equals( Link.class ) )
719735
fel.setAttribute( FEATURE_ISINT_ATTRIBUTE, isint );
720736
classFeaturesElement.addContent( fel );
721737
}
722-
featuresElement.addContent( classFeaturesElement );
738+
}
739+
740+
private Element getOrAddChild( final Element parent, final String childName )
741+
{
742+
Element child = parent.getChild( childName );
743+
if ( null == child )
744+
{
745+
child = new Element( childName );
746+
parent.addContent( child );
747+
}
748+
return child;
723749
}
724750

725751
private static Document getSAXParsedDocument( final String fileName )

0 commit comments

Comments
 (0)