Skip to content

Instantly share code, notes, and snippets.

@pavgup
Created October 6, 2015 02:30
Show Gist options
  • Save pavgup/d4f3d0c99acfa36041ae to your computer and use it in GitHub Desktop.
Save pavgup/d4f3d0c99acfa36041ae to your computer and use it in GitHub Desktop.
for nick with fireworks
package gov.epa.ctstestapi.service;
import com.codahale.metrics.annotation.Timed;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableListMultimap;
import com.google.common.collect.ImmutableSet;
import java.io.IOException;
import javax.annotation.PostConstruct;
import javax.inject.Inject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
@Service
@Transactional
public class TranslateTESTPropertyStringsService {
@Inject
private LoadTESTDataService loadTESTDataService;
private static final Logger log = LoggerFactory.getLogger(TranslateTESTPropertyStringsService.class);
/* Maps everywhere. MultiMaps from Google for now. And one variable. */
private static ImmutableListMultimap<String, String> allTestEndpoints;
//Map<String, String> MOAEndpoints = new HashMap<>(); // LDA/MOA methods need this
//Map<String, String> abbrevEndpoints = new HashMap<>(); // Basic properties (p-chem and tox) abbreviated
//Map<String, String> longEndpoints = new HashMap<>(); // Basic properties (p-chem and tox) full name
//Map<String, String> isLogMolarEndpoint = new HashMap<>(); // Special case endpoints for log molar endpoint
//Map<String, String> hasGroupContribMethod = new HashMap<>(); // Special case endpoints that use group contrib
//Map<String, String> hasSingleModelMethod = new HashMap<>(); // Spcial case endpoints that use single model method
public TranslateTESTPropertyStringsService() {
log.debug("Entering TranslateTESTPropertStringsService...");
}
@PostConstruct
@Timed
private void constructTestEndpoint() {
allTestEndpoints = new ImmutableListMultimap.Builder<String, String>()
.putAll("MeltingPoint", "MP", "abbrevMeltingPoint", "MeltingPoint", "Melting point")
/*.putAll("FHM_LC50", "LC50", "abbrevFHM_LC50", "FHM_LC50", "Fathead minnow LC50 (96 hr)")
.putAll("DM_LC50", "LC50DM", "abbrevDM_LC50", "DM_LC50", "Daphnia magna LC50 (48 hr)")
.putAll("TP_IGC50", "IGC50", "abbrevTP_IGC50", "TP_IGC50", "T. pyriformis IGC50 (48 hr)")
.putAll("Rat_LD50", "LD50", "abbrevRat_LD50", "Rat_LD50", "Oral rat LD50")
.putAll("GA_EC50", "EC50GA", "abbrevGA_EC50", "GA_EC50", "Green algae EC50 (96 hr)")
.putAll("BCF", "BCF", "abbrevBCF", "BCF", "Bioaccumulation factor")
.putAll("ReproTox", "DevTox", "abbrevReproTox", "ReproTox", "Developmental Toxicity")
.putAll("Mutagenicity", "Mutagenicity", "abbrevMutagenicity", "Mutagenicity", "Mutagenicity")
.putAll("ER_Binary", "ER_Binary", "abbrevER_Binary", "EstrogenReceptor", "Estrogen Receptor RBA")
.putAll("ER_LogRBA", "ER_LogRBA", "abbrevER_LogRBA", "EstrogenReceptorRelativeBindingAffinity", "Estrogen Receptor Binding")
.putAll("BoilingPoint", "BP", "abbrevBoilingPoint", "BoilingPoint", "Normal boiling point")
.putAll("VaporPressure", "VP", "abbrevVaporPressure", "VaporPressure", "Vapor pressure at 25C")
.putAll("Density", "Density", "abbrevDensity", "Density", "Density")
.putAll("FlashPoint", "FP", "abbrevFlashPoint", "FlashPoint", "Flash point")
.putAll("SurfaceTension", "ST", "abbrevSurfaceTension", "SurfaceTension", "Surface tension at 25C")
.putAll("ThermalConductivity", "TC", "abbrevThermalConductivity", "ThermalConductivity", "Thermal conductivity at 25C")
.putAll("Viscosity", "Viscosity", "abbrevViscosity", "Viscosity", "Viscosity at 25C")
.putAll("WaterSolubility", "WS", "abbrevWaterSolubility", "WaterSolubility", "Water solubility at 25C")
.putAll("Descriptors", "Descriptors")
.putAll("MOA", "AChE inhibition-Carbamate", "AChE inhibition-Organophosphate", "Narcosis-Ester", "Narcosis-Nonpolar", "Narcosis-Polar", "Neurotoxicity-Organochlorine", "Neurotoxicity-Pyrethroid", "Reactivity", "Uncoupling Oxidative Phosphorylation")
.putAll("getIsLogMolarEndpoint", "BoilingPoint", "Density", "FlashPoint", "MeltingPoint", "SurfaceTension", "ThermalConductivity")
.putAll("haveSingleModelMethod", "FHM_LC50", "DM_LC50", "BCF", "ReproTox", "ThermalConductivity", "EstrogenReceptor", "EstrogenReceptorRelativeBindingAffinity", "Viscosity")
.putAll("haveGroupContributionMethod", "Rat_LD50", "Mutagenicity", "ReproTox")
.putAll("getIsBinaryEndpoint", "ReproTox", "Mutagenicity", "EstrogenReceptor")*/
.build();
log.debug(allTestEndpoints.toString());
try {
loadTESTDataService.loadAllData();
} catch (IOException e) {
e.printStackTrace();
}
}
public static void init() {
log.debug("Entered the init() function...");
}
public String convertProperty(String property) {
log.debug("Working on a TEST-applicable version of the property: " + property);
return allTestEndpoints
.inverse().get(property)
.stream().findFirst()
.orElseThrow(() -> new IllegalArgumentException(property + " is not a valid property"));
}
/**
* Get the abbreviation for the endpoint- needed for loading data files
*
* @param endpoint * @return
*/
public static String getAbbrev(String endpoint) {
log.debug("Looking for the abbreviation for the endpoint: " + endpoint);
return allTestEndpoints
.get(endpoint).stream().findFirst()
.orElseGet(() -> allTestEndpoints.inverse().get(endpoint).stream().findFirst()
.orElseThrow(() -> new IllegalArgumentException(endpoint + " is not a valid endpoint to abbreviate")));
}
/**
* Determines whether endpoint is binary (like mutagenicity) or
* continuous (like boiling point)
*/
public boolean getIsBinaryEndpoint(String endpoint) {
return allTestEndpoints.get("getIsBinaryEndpoint").contains(endpoint);
}
public boolean haveSingleModelMethod(String endpoint) {
return allTestEndpoints.get("haveSingleModelMethod").contains(endpoint);
}
public boolean haveGroupContributionMethod(String endpoint) {
return allTestEndpoints.get("haveGroupContributionMethod").contains(endpoint);
}
/**
* Determines whether predicted values are in log units or absolute units
*/
public boolean getIsLogMolarEndpoint(String endpoint) {
return allTestEndpoints.get("getIsLogMolarEndpoint").contains(endpoint);
}
public ImmutableList<String> parseMultiMapWithKey(String key) {
return allTestEndpoints.get(key);
}
public ImmutableSet<String> getLongEndpoints() {
log.debug(allTestEndpoints.toString());
log.debug(allTestEndpoints.keys().toString());
log.debug(allTestEndpoints.keySet().toString());
return TranslateTESTPropertyStringsService.allTestEndpoints.keySet();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment