Skip to content

Commit

Permalink
polygons are mapped to area now
Browse files Browse the repository at this point in the history
  • Loading branch information
fbielejec committed Jul 3, 2015
1 parent f2c1efb commit d74ab63
Show file tree
Hide file tree
Showing 10 changed files with 126 additions and 88 deletions.
42 changes: 24 additions & 18 deletions README.textile
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,9 @@ h3. PARSING
* cut into 10 discrete time intervals
-parse -locations /home/filip/Dropbox/JavaProjects/Spread2/data/discrete/H5N1/locationCoordinates_H5N1 -tree /home/filip/Dropbox/JavaProjects/Spread2/data/discrete/H5N1/H5N1_HA_discrete_MCC.tre -locationTrait states -intervals 10 -mrsd 2011-01-01 -output test_discrete.json

* mrsd in decimal format
-parse -locations /home/filip/Dropbox/JavaProjects/Spread2/data/discrete/H5N1/locationCoordinates_H5N1 -tree /home/filip/Dropbox/JavaProjects/Spread2/data/discrete/H5N1/H5N1_HA_discrete_MCC.tre -locationTrait states -intervals 10 -mrsd 2011.653 -output test_discrete.json

h3. RENDERING

* use all default settings
Expand All @@ -118,47 +121,47 @@ h4. POLYGONS
* map alpha channel for polygons, this option overwrites all previous settings, including those in color sheet:
-render kml -json /home/filip/Dropbox/JavaProjects/Spread2/test_discrete.json -polygoncolormapping location -polygoncolors /home/filip/Dropbox/JavaProjects/Spread2/data/H5N1colors -polygonalphamapping count -output test.kml

* override default polygon radius (in KM) settings:
-render kml -json /home/filip/Dropbox/JavaProjects/Spread2/test_discrete.json -polygoncolormapping location -polygoncolors /home/filip/Dropbox/JavaProjects/Spread2/data/H5N1colors -polygonalphamapping count -polygonradius 200 -output test.kml
* override default polygon area (in KM^2) settings:
-render kml -json /home/filip/Dropbox/JavaProjects/Spread2/test_discrete.json -polygoncolormapping location -polygoncolors /home/filip/Dropbox/JavaProjects/Spread2/data/H5N1colors -polygonalphamapping count -polygonarea 200000 -output test.kml

* map polygon radius to count attribute values
-render kml -json /home/filip/Dropbox/JavaProjects/Spread2/test_discrete.json -polygoncolormapping location -polygoncolors /home/filip/Dropbox/JavaProjects/Spread2/data/H5N1colors -polygonalphamapping count -polygonradiusmapping count -output test.kml
* map polygon area to count attribute values
-render kml -json /home/filip/Dropbox/JavaProjects/Spread2/test_discrete.json -polygoncolormapping location -polygoncolors /home/filip/Dropbox/JavaProjects/Spread2/data/H5N1colors -polygonalphamapping count -polygonareamapping count -output test.kml

* map polygon radius to location attribute values
-render kml -json /home/filip/Dropbox/JavaProjects/Spread2/test_discrete.json -polygoncolormapping location -polygoncolors /home/filip/Dropbox/JavaProjects/Spread2/data/H5N1colors -polygonalphamapping count -polygonradiusmapping location -output test.kml
* map polygon area to location attribute values
-render kml -json /home/filip/Dropbox/JavaProjects/Spread2/test_discrete.json -polygoncolormapping location -polygoncolors /home/filip/Dropbox/JavaProjects/Spread2/data/H5N1colors -polygonalphamapping count -polygonareamapping location -output test.kml


h4. LINES

* override default line color settings:
-render kml -json /home/filip/Dropbox/JavaProjects/Spread2/test_discrete.json -polygoncolormapping location -polygoncolors /home/filip/Dropbox/JavaProjects/Spread2/data/H5N1colors -polygonalphamapping count -polygonradiusmapping location -linecolor 250 0 0 -output test.kml
-render kml -json /home/filip/Dropbox/JavaProjects/Spread2/test_discrete.json -polygoncolormapping location -polygoncolors /home/filip/Dropbox/JavaProjects/Spread2/data/H5N1colors -polygonalphamapping count -polygonareamapping location -linecolor 250 0 0 -output test.kml

* map line colors to distance attribute values, use built-in color schemes
-render kml -json /home/filip/Dropbox/JavaProjects/Spread2/test_discrete.json -polygoncolormapping location -polygoncolors /home/filip/Dropbox/JavaProjects/Spread2/data/H5N1colors -polygonalphamapping count -polygonradiusmapping location -linecolormapping distance -output test.kml
-render kml -json /home/filip/Dropbox/JavaProjects/Spread2/test_discrete.json -polygoncolormapping location -polygoncolors /home/filip/Dropbox/JavaProjects/Spread2/data/H5N1colors -polygonalphamapping count -polygonareamapping location -linecolormapping distance -output test.kml

* map line colors to locations, use supplied color sheet (RGB or RGBA values)
-render kml -json /home/filip/Dropbox/JavaProjects/Spread2/test_discrete.json -polygoncolormapping location -polygoncolors /home/filip/Dropbox/JavaProjects/Spread2/data/H5N1colors -polygonalphamapping count -polygonradiusmapping location -linecolormapping location -linecolors /home/filip/Dropbox/JavaProjects/Spread2/data/H5N1colors -output test.kml
-render kml -json /home/filip/Dropbox/JavaProjects/Spread2/test_discrete.json -polygoncolormapping location -polygoncolors /home/filip/Dropbox/JavaProjects/Spread2/data/H5N1colors -polygonalphamapping count -polygonareamapping location -linecolormapping location -linecolors /home/filip/Dropbox/JavaProjects/Spread2/data/H5N1colors -output test.kml

* specify alpha channel for lines, this option overwrites all previous settings, including those in color sheet:
-render kml -json /home/filip/Dropbox/JavaProjects/Spread2/test_discrete.json -polygoncolormapping location -polygoncolors /home/filip/Dropbox/JavaProjects/Spread2/data/H5N1colors -polygonalphamapping count -polygonradiusmapping location -linecolormapping location -linecolors /home/filip/Dropbox/JavaProjects/Spread2/data/H5N1colors -linealpha 150 -output test.kml
-render kml -json /home/filip/Dropbox/JavaProjects/Spread2/test_discrete.json -polygoncolormapping location -polygoncolors /home/filip/Dropbox/JavaProjects/Spread2/data/H5N1colors -polygonalphamapping count -polygonareamapping location -linecolormapping location -linecolors /home/filip/Dropbox/JavaProjects/Spread2/data/H5N1colors -linealpha 150 -output test.kml

* map alpha channel for lines to duration attribute values, this option overwrites all previous settings, including those in color sheet. Duration attribute applies to a whole branch and colors are not interpolated to reflect that:
-render kml -json /home/filip/Dropbox/JavaProjects/Spread2/test_discrete.json -polygoncolormapping location -polygoncolors /home/filip/Dropbox/JavaProjects/Spread2/data/H5N1colors -polygonalphamapping count -polygonradiusmapping location -linecolormapping location -linecolors /home/filip/Dropbox/JavaProjects/Spread2/data/H5N1colors -linealphamapping duration -output test.kml
-render kml -json /home/filip/Dropbox/JavaProjects/Spread2/test_discrete.json -polygoncolormapping location -polygoncolors /home/filip/Dropbox/JavaProjects/Spread2/data/H5N1colors -polygonalphamapping count -polygonareamapping location -linecolormapping location -linecolors /home/filip/Dropbox/JavaProjects/Spread2/data/H5N1colors -linealphamapping duration -output test.kml

* map alpha channel for lines to locations, this option overwrites all previous settings, including those in color sheet. For lines which change location line alpha will be interpolated to reflect that:
-render kml -json /home/filip/Dropbox/JavaProjects/Spread2/test_discrete.json -polygoncolormapping location -polygoncolors /home/filip/Dropbox/JavaProjects/Spread2/data/H5N1colors -polygonalphamapping count -polygonradiusmapping location -linecolormapping location -linecolors /home/filip/Dropbox/JavaProjects/Spread2/data/H5N1colors -linealphamapping location -output test.kml
-render kml -json /home/filip/Dropbox/JavaProjects/Spread2/test_discrete.json -polygoncolormapping location -polygoncolors /home/filip/Dropbox/JavaProjects/Spread2/data/H5N1colors -polygonalphamapping count -polygonareamapping location -linecolormapping location -linecolors /home/filip/Dropbox/JavaProjects/Spread2/data/H5N1colors -linealphamapping location -output test.kml

* override default line width settings:
-render kml -json /home/filip/Dropbox/JavaProjects/Spread2/test_discrete.json -polygoncolormapping location -polygoncolors /home/filip/Dropbox/JavaProjects/Spread2/data/H5N1colors -polygonalphamapping count -polygonradiusmapping location -linecolormapping location -linecolors /home/filip/Dropbox/JavaProjects/Spread2/data/H5N1colors -linealphamapping location -linewidth 3 -output test.kml
-render kml -json /home/filip/Dropbox/JavaProjects/Spread2/test_discrete.json -polygoncolormapping location -polygoncolors /home/filip/Dropbox/JavaProjects/Spread2/data/H5N1colors -polygonalphamapping count -polygonareamapping location -linecolormapping location -linecolors /home/filip/Dropbox/JavaProjects/Spread2/data/H5N1colors -linealphamapping location -linewidth 3 -output test.kml

* map lines width to duration attribute values. Width can only be mapped to attributes which apply to a whole branch.
-render kml -json /home/filip/Dropbox/JavaProjects/Spread2/test_discrete.json -polygoncolormapping location -polygoncolors /home/filip/Dropbox/JavaProjects/Spread2/data/H5N1colors -polygonalphamapping count -polygonradiusmapping location -linecolormapping location -linecolors /home/filip/Dropbox/JavaProjects/Spread2/data/H5N1colors -linealpha 255 -linewidthmapping duration -output test.kml
-render kml -json /home/filip/Dropbox/JavaProjects/Spread2/test_discrete.json -polygoncolormapping location -polygoncolors /home/filip/Dropbox/JavaProjects/Spread2/data/H5N1colors -polygonalphamapping count -polygonareamapping location -linecolormapping location -linecolors /home/filip/Dropbox/JavaProjects/Spread2/data/H5N1colors -linealpha 255 -linewidthmapping duration -output test.kml

* override default line altitude settings:
-render kml -json /home/filip/Dropbox/JavaProjects/Spread2/test_discrete.json -polygoncolormapping location -polygoncolors /home/filip/Dropbox/JavaProjects/Spread2/data/H5N1colors -polygonalphamapping count -polygonradiusmapping location -linecolormapping location -linecolors /home/filip/Dropbox/JavaProjects/Spread2/data/H5N1colors -linealpha 255 -linewidthmapping duration -linealtitude 100000 -output test.kml
-render kml -json /home/filip/Dropbox/JavaProjects/Spread2/test_discrete.json -polygoncolormapping location -polygoncolors /home/filip/Dropbox/JavaProjects/Spread2/data/H5N1colors -polygonalphamapping count -polygonareamapping location -linecolormapping location -linecolors /home/filip/Dropbox/JavaProjects/Spread2/data/H5N1colors -linealpha 255 -linewidthmapping duration -linealtitude 100000 -output test.kml

* map lines altitude to distance attribute values. Altitude can only be mapped to attributes which apply to a whole branch.
-render kml -json /home/filip/Dropbox/JavaProjects/Spread2/test_discrete.json -polygoncolormapping location -polygoncolors /home/filip/Dropbox/JavaProjects/Spread2/data/H5N1colors -polygonalphamapping count -polygonradiusmapping location -linecolormapping location -linecolors /home/filip/Dropbox/JavaProjects/Spread2/data/H5N1colors -linealpha 255 -linewidthmapping duration -linealtitudemapping distance -output test.kml
-render kml -json /home/filip/Dropbox/JavaProjects/Spread2/test_discrete.json -polygoncolormapping location -polygoncolors /home/filip/Dropbox/JavaProjects/Spread2/data/H5N1colors -polygonalphamapping count -polygonareamapping location -linecolormapping location -linecolors /home/filip/Dropbox/JavaProjects/Spread2/data/H5N1colors -linealpha 255 -linewidthmapping duration -linealtitudemapping distance -output test.kml


h3. BAYES FACTORS
Expand Down Expand Up @@ -197,6 +200,9 @@ h3. PARSING
* parse other numerical traits for imputing
-parse -tree /home/filip/Dropbox/JavaProjects/Spread2/data/continuous/locationHost/HA_loc_host_mcc.tre -trees /home/filip/Dropbox/JavaProjects/Spread2/data/continuous/locationHost/HA_loc_host_small.trees -traits location,trait2 -hpd 0.8 -intervals 20 -burnin 5 -mrsd 2011-01-01 -output test_slice.json

* mrsd in decimal format
-parse -tree /home/filip/Dropbox/JavaProjects/Spread2/data/continuous/WNV/WNV_relaxed_geo_gamma_MCC.tre -trees /home/filip/Dropbox/JavaProjects/Spread2/data/continuous/WNV/WNV_relaxed_geo_gamma.trees -traits location -hpd 0.8 -intervals 15 -burnin 5 -mrsd 2011.653 -output test_slice.json

h3. RENDERING

* use all default settings
Expand Down Expand Up @@ -230,13 +236,13 @@ h1. TODO

* Date-time calculations
- time scale multiplier
- If no date specified everything goes to 0
* Renderers
- D3 renderer
- GeoJSON renderer
- KML renderers
- KML renderer
- control arc curvature [0 - 1]
* Non-geographic locations (e.g. antigenic locations)
* parsing BEAST2 and MrBayes output
* Restrict visual summaries or rate statistics to a particular set of nodes, like a clade or a trunk/backbone
* Display warning if one or more of the discrete states are not found.
* Uncaught exception handler (for bug reports).
Expand Down
2 changes: 1 addition & 1 deletion src/app/Spread2ConsoleApp.java
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ public class Spread2ConsoleApp {
private static final String POLYGON_ALPHA = "polygonalpha";

private static final String POLYGON_AREA = "polygonarea";
private static final String POLYGON_AREA_MAPPING = "polygonradiusmapping";
private static final String POLYGON_AREA_MAPPING = "polygonareamapping";

private static final String LINE_COLOR_MAPPING = "linecolormapping";
private static final String LINE_COLORS = "linecolors";
Expand Down
2 changes: 1 addition & 1 deletion src/exceptions/MissingAttributeException.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public MissingAttributeException(String attributeName, String name) {

@Override
public String getMessage() {
String message = "Attribute " + attributeName + " missing from " + name +" attributes";
String message = "Attribute " + attributeName + " missing from " + name + " attributes";
return message;
}

Expand Down
3 changes: 3 additions & 0 deletions src/parsers/DiscretePolygonsParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,9 @@ public LinkedList<Polygon> parseDiscretePolygons() throws LocationNotFoundExcep
}// END: traits loop
}// END: null check

Trait locationTrait = new Trait(location.getId());
attributes.put(LOCATION, locationTrait);

Trait countTrait = new Trait(locationCount);
attributes.put(COUNT, countTrait);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,118 +17,130 @@
import exceptions.AnalysisException;
import exceptions.LocationNotFoundException;

public class DiscreteLinesParser {
public class DiscreteTreeLinesParser {

String locationTrait;
List<Location> locationsList;
RootedTree rootedTree;
private String locationTrait;
private List<Location> locationsList;
private RootedTree rootedTree;
private String[] traits;
private String mrsd;

public DiscreteLinesParser(RootedTree rootedTree, String locationTrait, List<Location> locationsList, String traits[]) {

public DiscreteTreeLinesParser(RootedTree rootedTree, //
String locationTrait, //
List<Location> locationsList, //
String traits[], //
String mrsd //
) {

this.locationTrait = locationTrait;
this.locationsList = locationsList;
this.rootedTree = rootedTree;
this.traits = traits;
this.mrsd = mrsd;

}//END: Constructor

public LinkedList<Line> parseLines() throws IOException, ImportException, LocationNotFoundException, AnalysisException {

}// END: Constructor

public LinkedList<Line> parseLines() throws IOException, ImportException,
LocationNotFoundException, AnalysisException {

LinkedList<Line> linesList = new LinkedList<Line>();


TimeParser timeParser = new TimeParser(mrsd);
timeParser.parseTime();

Location dummy;
for (Node node : rootedTree.getNodes()) {
if (!rootedTree.isRoot(node)) {

Node parentNode = rootedTree.getParent(node);

String parentState = (String) Utils.getObjectNodeAttribute(parentNode, locationTrait);
if(parentState.contains("+")) {

String parentState = (String) Utils.getObjectNodeAttribute(
parentNode, locationTrait);
if (parentState.contains("+")) {
String message = "Found tied state " + parentState + ".";
parentState = Utils.breakTiesRandomly(parentState);
message += (" randomly choosing " + parentState + ".");
System.out.println(message);
}//END: tie check

String nodeState = (String) Utils.getObjectNodeAttribute(node, locationTrait);
if(nodeState.contains("+")) {
}// END: tie check

String nodeState = (String) Utils.getObjectNodeAttribute(node,
locationTrait);
if (nodeState.contains("+")) {
String message = "Found tied state " + nodeState + ".";
nodeState = Utils.breakTiesRandomly(nodeState);
message += (" Randomly choosing " + nodeState + ".");
System.out.println(message);
}//END: tie check

dummy = new Location(parentState, "", new Coordinate(0.0, 0.0), null);
}// END: tie check

dummy = new Location(parentState, "", new Coordinate(0.0, 0.0),
null);
int parentLocationIndex = Integer.MAX_VALUE;
if(locationsList.contains(dummy)) {
parentLocationIndex = locationsList.indexOf(dummy);
if (locationsList.contains(dummy)) {
parentLocationIndex = locationsList.indexOf(dummy);
} else {
throw new LocationNotFoundException(dummy);
}

dummy = new Location(nodeState, "", new Coordinate(0.0, 0.0), null);

dummy = new Location(nodeState, "", new Coordinate(0.0, 0.0),
null);
int nodeLocationIndex = Integer.MAX_VALUE;
if(locationsList.contains(dummy)) {
nodeLocationIndex = locationsList.indexOf(dummy);
if (locationsList.contains(dummy)) {
nodeLocationIndex = locationsList.indexOf(dummy);
} else {
throw new LocationNotFoundException(dummy);
}

Location parentLocation = locationsList.get(parentLocationIndex);

Location parentLocation = locationsList
.get(parentLocationIndex);
Location nodeLocation = locationsList.get(nodeLocationIndex);
if (!(parentLocation.equals(nodeLocation))) {

Double parentHeight = Utils.getNodeHeight(rootedTree, parentNode);
Double parentHeight = Utils.getNodeHeight(rootedTree,
parentNode);
String startTime = timeParser.getNodeDate(parentHeight);

Double nodeHeight = Utils.getNodeHeight(rootedTree, node);

String endTime = timeParser.getNodeDate(nodeHeight);

Map<String, Trait> attributes = new LinkedHashMap<String, Trait>();

if (traits != null) {
for (String traitName : traits) {

// Object parentTraitObject = Utils
// .getObjectNodeAttribute(parentNode,
// traitName);
// Trait parentTrait = new Trait(parentTraitObject,
// parentHeight);

Trait parentTrait = Utils.getNodeTrait(parentNode, traitName);

Trait parentTrait = Utils.getNodeTrait(parentNode,
traitName);
attributes
.put(Utils.START + traitName, parentTrait);

// Object nodeTraitObject = Utils
// .getObjectNodeAttribute(node, traitName);
// Trait nodeTrait = new Trait(nodeTraitObject,
// nodeHeight);

Trait nodeTrait = Utils.getNodeTrait(node, traitName);

Trait nodeTrait = Utils.getNodeTrait(node,
traitName);
attributes.put(Utils.END + traitName, nodeTrait);

}// END: traits loop
}// END: null check
// branch attribute traits

// branch attribute traits

double branchDuration = parentHeight - nodeHeight;
Trait branchDurationTrait = new Trait(branchDuration);
attributes.put(Utils.DURATION, branchDurationTrait);

double distance = Utils.rhumbDistance(parentLocation.getCoordinate(), nodeLocation.getCoordinate());

double distance = Utils.rhumbDistance(
parentLocation.getCoordinate(),
nodeLocation.getCoordinate());
Trait distanceTrait = new Trait(distance);
attributes.put(Utils.DISTANCE, distanceTrait);

Line line = new Line(parentLocation, nodeLocation, "", "", attributes);

Line line = new Line(parentLocation, nodeLocation,
startTime, endTime, attributes);
linesList.add(line);

}// END: branch changes state check

}// END: root check
}// END: node loop

return linesList;
}//END: parseLines
}//END: class
}// END: parseLines

}// END: class
5 changes: 3 additions & 2 deletions src/parsers/DiscreteTreeParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,11 @@ public SpreadData parse() throws IOException, ImportException,

System.out.println("Parsing lines");

DiscreteLinesParser linesParser = new DiscreteLinesParser(rootedTree, //
DiscreteTreeLinesParser linesParser = new DiscreteTreeLinesParser(rootedTree, //
settings.locationTrait, //
locationsList, //
settings.traits //
settings.traits, //
settings.mrsd //
);

linesList = linesParser.parseLines();
Expand Down
Loading

0 comments on commit d74ab63

Please sign in to comment.