use of org.nextprot.api.commons.exception.NextProtException in project nextprot-api by calipho-sib.
the class RdfHelpController method helpFullInfo.
/*
@RequestMapping("/rdf/help/type/{rdfType}/values")
@ResponseBody
public List<String> helpFullInfoValues(@PathVariable("rdfType") String rdfType, Model model) {
try {
return this.service.getRdfTypeValues(rdfType);
} catch (Exception e) {
throw new NextProtException(e.getMessage());
}
}
@RequestMapping("/rdf/help/visgraphp")
public String visgraphp(Model model) {
Map<String, RdfTypeInfo> map = new HashMap<String, RdfTypeInfo>();
List<String> names = new ArrayList<String>();
for (RdfTypeInfo rti : this.service.getRdfTypeFullInfoList()) {
map.put(rti.getTypeName(), rti);
names.add(rti.getTypeName());
}
model.addAttribute("visutils", new VisUtils());
model.addAttribute("map", map);
model.addAttribute("names", names);
return "visgraphp";
}
@RequestMapping("/rdf/help/visgraph")
public String visgraph(Model model) {
Map<String, RdfTypeInfo> map = new HashMap<String, RdfTypeInfo>();
List<String> names = new ArrayList<String>();
for (RdfTypeInfo rti : this.service.getRdfTypeFullInfoList()) {
map.put(rti.getTypeName(), rti);
if (!rti.getTypeName().startsWith(":Isoform") && !rti.getTypeName().startsWith(":Evidence")) {
names.add(rti.getTypeName());
} else
System.out.println("Skipped for" + rti);
}
model.addAttribute("visutils", new VisUtils());
model.addAttribute("map", map);
model.addAttribute("names", names);
return "visgraph";
}
// Example http://localhost:8080/nextprot-api/rdf/help/visgraph/:Entry,:Gene
@RequestMapping("/rdf/help/visgraph/{rdfType}")
public String visgraph(@PathVariable("rdfType") String rdfType, Model model) {
Map<String, RdfTypeInfo> map = new HashMap<String, RdfTypeInfo>();
for (RdfTypeInfo rti : this.service.getRdfTypeFullInfoList()) {
map.put(rti.getTypeName(), rti);
}
model.addAttribute("visutils", new VisUtils());
model.addAttribute("map", map);
model.addAttribute("names", Arrays.asList(rdfType.split(",")));
return "visgraph";
}
// Example http://localhost:8080/nextprot-api/rdf/help/visgraph/:Entry,:Gene
@RequestMapping("/rdf/help/visgraphp/{rdfType}")
public String visgraphp(@PathVariable("rdfType") String rdfType, Model model) {
Map<String, RdfTypeInfo> map = new HashMap<String, RdfTypeInfo>();
for (RdfTypeInfo rti : this.service.getRdfTypeFullInfoList()) {
map.put(rti.getTypeName(), rti);
}
model.addAttribute("visutils", new VisUtils());
model.addAttribute("map", map);
model.addAttribute("names", Arrays.asList(rdfType.split(",")));
return "visgraphp";
}
public static class VisUtils {
private int n = 6666;
Set<Integer> ids = new TreeSet<Integer>();
Map<String, Integer> mapIds = new HashMap<String, Integer>();
public void addId(int id) {
ids.add(id);
}
public Integer getMaxDepth(RdfTypeInfo rti) {
int max = 0;
for (String p : rti.getPathToOrigin()) {
max = Math.max(max, getDepth(p));
}
return max;
}
public Integer getTripleId(TripleInfo t) {
String key = t.getSubjectType() + "" + t.getPredicate();
if (!mapIds.containsKey(key)) {
mapIds.put(key, n++);
}
return mapIds.get(key);
}
public Integer getNodeId(String currentNode, String relativePath, String _path) {
System.out.println("CN:" + currentNode + " RP:" + relativePath + " P:" + _path);
String path = _path.replace("/", "");
if (currentNode.equals("Entry"))
return getPathId(currentNode);
if (currentNode.equals("isoform")) {
String afterNode = path.replace(relativePath, "").replace(currentNode, "");
int ni = afterNode.indexOf(":");
int nextIndex = afterNode.indexOf(":", ni+1);
if(nextIndex == -1) {
nextIndex = ni;
}
if(ni == -1) {
nextIndex = 0;
}
System.out.println("AN" + afterNode + " ANS" + afterNode.substring(nextIndex));
return getPathId(currentNode + afterNode.substring(nextIndex));
}
String currentAndAfterNode = path.replace(relativePath, "");
System.out.println(currentAndAfterNode + getPathId(currentAndAfterNode));
System.out.println();
return getPathId(currentAndAfterNode);
}
public Integer getPathId(String path) {
if (!mapIds.containsKey(path)) {
mapIds.put(path, n++);
}
return mapIds.get(path);
}
public boolean isLast(String path, String absolutePath) {
return path.replace("/", "").equals(absolutePath);
}
public Integer getEdgeId(Integer id1, Integer id2) {
String s = id1.toString() + id2.toString();
return Integer.valueOf(s);
}
public Integer getDepth(String p) {
return p.split(":").length;
}
public String getSimplePath(String path) {
int n = StringUtils.reverse(path).indexOf(":");
if (n == -1)
return "Entry";
return path.substring(path.length() - n);
}
public List<String> getPathArray(String path) {
String s = path.replace("?entry ", "");
String ss[] = s.split("/");
List<String> r = new ArrayList<String>();
String current = "?entry";
current += " ";
r.add(current);
for (String p : ss) {
current += p;
r.add(current);
}
return r;
}
public boolean contains(int id) {
return ids.contains(id);
}
private Set<String> edges = new TreeSet<String>();
public String getEdge (Integer from, Integer to, String label){
String key = null;
if(from < to){
key = from + "" + to;
}else key = to + "" + from;
if(edges.contains(key)){
return "";
}else {
edges.add(key);
return "edges.push({from: " + from + ", to: " + to + ", label: '" + label + "'});";
}
}
}
/**
* Full info of a single rdf:type
*
* @param rdfType
* @param model
* @return
*/
// we want this undocumented @ApiMethod(path = "/rdf/help/type/{rdfType}", verb = ApiVerb.GET, description = "Gets a description and properties of a rdf type", produces = { MediaType.APPLICATION_JSON_VALUE })
@RequestMapping("/rdf/help/type/{rdfType}")
@ResponseBody
public RdfTypeInfo helpFullInfo(@PathVariable("rdfType") String rdfType, Model model) {
try {
RdfTypeInfo typ;
typ = this.service.getRdfTypeFullInfo(rdfType);
model.addAttribute("result", typ);
return typ;
} catch (Exception e) {
e.printStackTrace();
throw new NextProtException(e.getMessage());
}
}
use of org.nextprot.api.commons.exception.NextProtException in project nextprot-api by calipho-sib.
the class SparqlServiceImpl method sparqlSelect.
@Override
public SparqlResult sparqlSelect(String sparql, String sparqlEndpointUrl, int timeout, String queryTitle, String testId, ResultsFormat format) {
SparqlResult result = null;
try {
QueryExecution qExec = QueryExecutionFactory.sparqlService(sparqlEndpointUrl, sparql);
qExec.setTimeout(timeout);
ResultSet rs = qExec.execSelect();
result = SparqlUtils.convertResultToFormat(rs, format);
qExec.close();
} catch (QueryParseException qe) {
String msg = ExceptionUtils.fixLineNumberInErrorMessage(qe.getLocalizedMessage());
throw new NextProtException("Malformed SPARQL: " + msg);
}
return result;
}
use of org.nextprot.api.commons.exception.NextProtException in project nextprot-api by calipho-sib.
the class ChromosomeReportController method exportChromosomeEntryCountByProteinEvidenceFile.
@ApiMethod(path = "/chromosome-report/export/hpp/entry-count-by-pe", verb = ApiVerb.GET, description = "Export number of entries grouped by protein existence for all chromosomes", produces = { NextprotMediaType.TSV_MEDIATYPE_VALUE })
@RequestMapping(value = "/chromosome-report/export/hpp/entry-count-by-pe", method = { RequestMethod.GET })
public void exportChromosomeEntryCountByProteinEvidenceFile(HttpServletResponse response) {
try (OutputStream os = response.getOutputStream()) {
response.setHeader("Content-Disposition", "attachment; filename=\"count-of-pe12345-by-chromosome.tsv\"");
chromosomeReportExportService.exportHPPChromosomeEntryReportCountByProteinExistence(os);
} catch (IOException e) {
throw new NextProtException(e.getMessage() + ": cannot export entry count by protein existence for all chromosomes");
}
}
use of org.nextprot.api.commons.exception.NextProtException in project nextprot-api by calipho-sib.
the class ChromosomeReportController method exportHPPChromosomeEntriesReportFile.
@ApiMethod(path = "/chromosome-report/export/hpp/{chromosome}", verb = ApiVerb.GET, description = "Export informations of neXtProt entries located on a given chromosome by accession", produces = { MediaType.TEXT_PLAIN_VALUE, NextprotMediaType.TSV_MEDIATYPE_VALUE })
@RequestMapping(value = "/chromosome-report/export/hpp/{chromosome}", method = { RequestMethod.GET })
public void exportHPPChromosomeEntriesReportFile(@ApiPathParam(name = "chromosome", description = "The chromosome number or name (X,Y..)", allowedvalues = { "Y" }) @PathVariable("chromosome") String chromosome, HttpServletRequest request, HttpServletResponse response) {
NextprotMediaType mediaType = NextprotMediaType.valueOf(request);
try (OutputStream os = response.getOutputStream()) {
String filename = "HPP_chromosome_" + chromosome + "." + mediaType.getExtension();
response.setHeader("Content-Disposition", "attachment; filename=\"" + filename + "\"");
chromosomeReportExportService.exportHPPChromosomeEntryReport(chromosome, NextprotMediaType.valueOf(request), os);
} catch (IOException e) {
throw new NextProtException(e.getMessage() + ": cannot export HPP chromosome " + chromosome + " as " + mediaType);
}
}
use of org.nextprot.api.commons.exception.NextProtException in project nextprot-api by calipho-sib.
the class TerminologyDaoImpl method findTerminologyByAccession.
@Override
// SHOULD USE findTermByAccessionAndTerminology
@Cacheable("terminology-by-accession")
public CvTerm findTerminologyByAccession(String accession) {
Set<String> acs = new HashSet<>();
acs.add(accession);
SqlParameterSource params = new MapSqlParameterSource("accessions", acs);
List<CvTerm> terms = new NamedParameterJdbcTemplate(dsLocator.getDataSource()).query(sqlDictionary.getSQLQuery("terminology-by-acs"), params, new DbTermRowMapper());
if (terms.size() == 0)
return null;
else if (terms.size() > 1) {
throw new NextProtException("Found " + terms.size() + " terms that corresponds to the same accession. Use the method findTerminologyByAccessionForTerminology (accession, terminology) instead");
}
return terms.get(0);
}
Aggregations