Skip to content

Commit

Permalink
Issue #731 Metabolic pathways
Browse files Browse the repository at this point in the history
  • Loading branch information
okolesn committed Jan 25, 2022
1 parent 89b939c commit 6609b9e
Show file tree
Hide file tree
Showing 16 changed files with 1,362 additions and 48 deletions.
6 changes: 6 additions & 0 deletions server/catgenome/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,9 @@ ext {
// >>>>> repositories that should be used to find any external dependencies
repositories {
mavenCentral()
maven {
url "https://jitpack.io"
}
flatDir {
dirs 'lib'
}
Expand Down Expand Up @@ -188,6 +191,9 @@ dependencies {
// newick format
compile group: "com.github.qurben", name: "libnewicktree", version: "1.0"

// sbgn format
compile group: "com.github.sbgn", name: "libsbgn", version: "b619268"

// >>>>> dependencies used to compile tests; in fact no need to include them into artifact
testCompile("org.springframework.boot:spring-boot-starter-test")
testCompile group: "org.unitils", name: "unitils-core", version: project.ext.versionUnitils
Expand Down
1 change: 1 addition & 0 deletions server/catgenome/profiles/dev/catgenome.properties
Original file line number Diff line number Diff line change
Expand Up @@ -136,3 +136,4 @@ homologene.index.directory=${HOMOLOGENE_INDEX_DIR:@rootDirPath@/contents/homolog

#METABOLIC PATHWAY
pathway.index.directory=${PATHWAY_INDEX_DIRECTORY:@rootDirPath@/contents/pathway}
pathway.top.hits=${PATHWAY_TOP_HITS:100}
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,8 @@ public final class MessagesConstants {

//Pathway
public static final String ERROR_PATHWAY_NOT_FOUND = "error.pathway.not.found";
public static final String ERROR_PATHWAY_NO_GLYPHS = "error.pathway.no.glyphs.found";
public static final String ERROR_PATHWAY_NO_ARCS = "error.pathway.no.arcs.found";

//Attributes
public static final String ERROR_ATTRIBUTE_INVALID_VALUE = "error.attribute.invalid.value";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,27 @@
import com.epam.catgenome.controller.Result;
import com.epam.catgenome.controller.vo.registration.PathwayRegistrationRequest;
import com.epam.catgenome.entity.pathway.Pathway;
import com.epam.catgenome.entity.pathway.SbgnElement;
import com.epam.catgenome.util.db.Page;
import com.epam.catgenome.manager.pathway.PathwaySecurityService;
import com.epam.catgenome.util.db.QueryParameters;
import com.wordnik.swagger.annotations.Api;
import com.wordnik.swagger.annotations.ApiOperation;
import com.wordnik.swagger.annotations.ApiResponse;
import com.wordnik.swagger.annotations.ApiResponses;
import lombok.RequiredArgsConstructor;
import org.apache.lucene.queryparser.classic.ParseException;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;
import javax.xml.bind.JAXBException;
import java.io.IOException;
import java.util.List;

Expand All @@ -57,20 +68,49 @@ public class PathwayController extends AbstractRESTController {
value = {@ApiResponse(code = HTTP_STATUS_OK, message = API_STATUS_DESCRIPTION)
})
public Result<Pathway> loadPathway(@PathVariable final Long pathwayId,
@RequestParam(required = false) final Long projectId) {
@RequestParam(required = false) final Long projectId) {
return Result.success(pathwaySecurityService.loadPathway(pathwayId, projectId));
}

@GetMapping(value = "/pathway/content/{pathwayId}")
@ApiOperation(
value = "Returns a pathway file content by pathway id",
notes = "Returns a pathway file content by pathway id",
produces = MediaType.APPLICATION_OCTET_STREAM_VALUE)
@ApiResponses(
value = {@ApiResponse(code = HTTP_STATUS_OK, message = API_STATUS_DESCRIPTION)
})
public void loadPathwayContent(@PathVariable final Long pathwayId,
@RequestParam(required = false) final Long projectId,
final HttpServletResponse response) throws IOException {
byte[] bytes = pathwaySecurityService.loadPathwayContent(pathwayId, projectId);
response.getOutputStream().write(bytes);
response.flushBuffer();
}

@PostMapping(value = "/pathway/search")
@ApiOperation(
value = "Searches sbgn file elements",
notes = "Searches sbgn file elements",
produces = MediaType.APPLICATION_JSON_VALUE)
@ApiResponses(
value = {@ApiResponse(code = HTTP_STATUS_OK, message = API_STATUS_DESCRIPTION)
})
public Result<List<SbgnElement>> searchElements(@RequestBody SbgnElement sbgnElement)
throws IOException, ParseException {
return Result.success(pathwaySecurityService.searchElements(sbgnElement));
}

@GetMapping(value = "/pathways")
@ApiOperation(
value = "Returns all pathways",
notes = "Returns all pathways",
value = "Returns pathways page",
notes = "Returns pathways page",
produces = MediaType.APPLICATION_JSON_VALUE)
@ApiResponses(
value = {@ApiResponse(code = HTTP_STATUS_OK, message = API_STATUS_DESCRIPTION)
})
public Result<List<Pathway>> loadPathways() {
return Result.success(pathwaySecurityService.loadPathways());
public Result<Page<Pathway>> loadPathways(final QueryParameters queryParameters) {
return Result.success(pathwaySecurityService.loadPathways(queryParameters));
}

@PostMapping(value = "/pathway")
Expand All @@ -82,7 +122,7 @@ public Result<List<Pathway>> loadPathways() {
value = {@ApiResponse(code = HTTP_STATUS_OK, message = API_STATUS_DESCRIPTION)
})
public Result<Pathway> createPathway(@RequestBody final PathwayRegistrationRequest request)
throws IOException, ParseException {
throws IOException, ParseException, JAXBException {
return Result.success(pathwaySecurityService.createPathway(request));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import com.epam.catgenome.entity.BiologicalDataItemFormat;
import com.epam.catgenome.entity.BiologicalDataItemResourceType;
import com.epam.catgenome.entity.pathway.Pathway;
import com.epam.catgenome.util.db.QueryParameters;
import lombok.AllArgsConstructor;
import lombok.NoArgsConstructor;
import lombok.Setter;
Expand All @@ -42,6 +43,8 @@
import java.sql.SQLException;
import java.util.List;

import static com.epam.catgenome.util.Utils.addParametersToQuery;

@Setter
@NoArgsConstructor
@AllArgsConstructor
Expand All @@ -54,6 +57,7 @@ public class PathwayDao extends NamedParameterJdbcDaoSupport {
private String deletePathwayQuery;
private String loadPathwayQuery;
private String loadPathwaysQuery;
private String getTotalCountQuery;

/**
* Persists new Pathway record.
Expand Down Expand Up @@ -89,8 +93,13 @@ public Pathway loadPathway(final long pathwayId) {
* Loads {@code Pathways} from a database.
* @return a {@code List<Pathway>} from the database
*/
public List<Pathway> loadAllPathways() {
return getJdbcTemplate().query(loadPathwaysQuery, PathwayParameters.getRowMapper());
public List<Pathway> loadAllPathways(final QueryParameters queryParameters) {
final String query = addParametersToQuery(loadPathwaysQuery, queryParameters);
return getJdbcTemplate().query(query, PathwayParameters.getRowMapper());
}

public long getTotalCount() {
return getJdbcTemplate().queryForObject(getTotalCountQuery, Long.class);
}

enum PathwayParameters {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,10 @@
@Getter
@Setter
@Builder
public class PathwayEntry {
public class SbgnElement {
private Long pathwayId;
//TODO
private SbgnElementType type;
private String clazz;
private String entryId;
private String label;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/*
* MIT License
*
* Copyright (c) 2022 EPAM Systems
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package com.epam.catgenome.entity.pathway;

public enum SbgnElementType {
GLYPH("glyph"),
ARC("arc");

public String getName() {
return name;
}

private final String name;

SbgnElementType(String name) {
this.name = name;
}

public static SbgnElementType getByName(final String name) {
for (SbgnElementType type : SbgnElementType.values()) {
if (name.equals(type.getName())) {
return type;
}
}
return null;
}
}
Loading

0 comments on commit 6609b9e

Please sign in to comment.