Skip to content

Commit

Permalink
updated swagger API and update several annotation. Now this version i…
Browse files Browse the repository at this point in the history
…s ready to use
  • Loading branch information
juexinwang committed Jul 19, 2016
1 parent dab1bec commit 3f68bde
Show file tree
Hide file tree
Showing 22 changed files with 258 additions and 215 deletions.
8 changes: 5 additions & 3 deletions README
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,11 @@ Step 1. Init the Database

Step 2. Check the API
1. in pdb-annotation/pdb-alignment-api/: mvn spring-boot:run
2. open your web browser:
http://localhost:8080/StructureMappingQuery?ensemblid=ENSP00000483207.2
http://localhost:8080/ProteinIdentifierRecognitionQuery?ensemblid=ENSP00000483207.2
2. Swagger-UI:
http://localhost:8080/swagger-ui.html
3. Directly using API:
http://localhost:8080/pdb_annotation/StructureMappingQuery?ensemblId=ENSP00000483207.2
http://localhost:8080/pdb_annotation/ProteinIdentifierRecognitionQuery?ensemblId=ENSP00000483207.2

Step 3. Weekly update
1. in pdb-annotation/pdb-alignment-pipeline/target/: java -jar -Xmx7000m pdb-0.1.0.jar update
Expand Down
12 changes: 12 additions & 0 deletions pdb-alignment-api/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,18 @@
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>2.4.0</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>2.4.0</version>
<scope>compile</scope>
</dependency>
</dependencies>

<properties>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,52 @@
package org.cbioportal.pdb_annotation.web;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;

import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

/**
* Main SpringBoot Application
*
* @author Juexin Wang
*
*/
@SpringBootApplication
@EnableAutoConfiguration
@EnableSwagger2
public class Application {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
}

@Bean
public Docket annotationApi()
{
// default swagger definition file location: <root>/v2/api-docs?group=pdb_annotation
// default swagger UI location: <root>/swagger-ui.html
return new Docket(DocumentationType.SWAGGER_2)
.groupName("pdb_annotation")
.apiInfo(annotationApiInfo())
.select()
.paths(PathSelectors.regex("/pdb_annotation.*"))
.build();
}

private ApiInfo annotationApiInfo()
{
return new ApiInfoBuilder()
.title("PDB Annotation API")
.description("PDB Annotation API")
//.termsOfServiceUrl("http://terms-of-service-url")
.contact("CMO, MSKCC")
.license("GNU AFFERO GENERAL PUBLIC LICENSE Version 3")
.licenseUrl("https://github.com/cBioPortal/pdb-annotation/blob/master/LICENSE")
.version("2.0")
.build();
}
}
Original file line number Diff line number Diff line change
@@ -1,73 +1,90 @@
package org.cbioportal.pdb_annotation.web.controllers;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

import org.cbioportal.pdb_annotation.web.domain.AlignmentRepository;
import org.cbioportal.pdb_annotation.web.domain.EnsemblRepository;
import org.cbioportal.pdb_annotation.web.domain.PdbRepository;
import org.cbioportal.pdb_annotation.web.models.Alignment;
import org.cbioportal.pdb_annotation.web.persistancy.AlignmentRepository;
import org.cbioportal.pdb_annotation.web.persistancy.EnsemblRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.ResponseStatus;
import org.springframework.web.bind.annotation.RestController;

import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;

@Controller
/**
*
* Controller of the main API: AlignmentController
*
* @author Juexin Wang
*
*/
@RestController // shorthand for @Controller, @ResponseBody
@CrossOrigin(origins = "*") // allow all cross-domain requests
@RequestMapping(value = "/pdb_annotation/")
public class AlignmentController {

@RequestMapping("/StructureMappingQuery")
@ResponseBody
public List<Alignment> findByEnsemblidinAlignment(String ensemblid) {

List<Alignment> list = new ArrayList<Alignment>();
try {
Iterator<Alignment> it = alignmentDao.findByEnsemblId(ensemblid).iterator();
while(it.hasNext()){
Alignment alignment = (Alignment)it.next();
list.add(alignment);
}
}
catch (Exception ex) {
ex.printStackTrace();
}
return list;

}


@RequestMapping("/ProteinIdentifierRecognitionQuery")
@ResponseBody
public boolean isExistedEnsemblidinAlignment(String ensemblid) {
try {
Iterator<Alignment> it = alignmentDao.findByEnsemblId(ensemblid).iterator();
if(it.hasNext()){
return true;
}else{
return false;
}
}
catch (Exception ex) {
ex.printStackTrace();
}
return false;
}





// ------------------------
// PRIVATE FIELDS
// ------------------------

@Autowired
private AlignmentRepository alignmentDao;

//@Autowired
//private EnsemblDAO ensemblDao;


private AlignmentRepository alignmentRepository;
private EnsemblRepository ensemblRepository;
private PdbRepository pdbRepository;

@Autowired
public AlignmentController(AlignmentRepository alignmentRepository, EnsemblRepository ensemblRepository,
PdbRepository pdbRepository) {
this.alignmentRepository = alignmentRepository;
this.ensemblRepository = ensemblRepository;
this.pdbRepository = pdbRepository;
}

@ApiOperation(value = "get pdb alignments by ensemblId", nickname = "getPdbAlignmentByEnsemblId")
@ApiResponses(value = {
@ApiResponse(code = 200, message = "Success", response = Alignment.class, responseContainer = "List"),
@ApiResponse(code = 400, message = "Bad Request") })
@RequestMapping(value = "/StructureMappingQuery", method = RequestMethod.GET, produces = "application/json")
@ResponseBody
@ResponseStatus(HttpStatus.OK)
public List<Alignment> getPdbAlignmentByEnsemblId(
@RequestParam @ApiParam(value = "Input ensembl id. For example ENSP00000483207.2", required = true, allowMultiple = true) String ensemblId) {
List<Alignment> list = new ArrayList();
try {
List<Alignment> it = alignmentRepository.findByEnsemblId(ensemblId);
list.addAll(it);
} catch (Exception ex) {
ex.printStackTrace();
}
return list;
}

@ApiOperation(value = "get whether ensemblId exists by ensemblId", nickname = "getExistedEnsemblidinAlignment")
@ApiResponses(value = {
@ApiResponse(code = 200, message = "Success", response = Alignment.class, responseContainer = "boolean"),
@ApiResponse(code = 400, message = "Bad Request") })
@RequestMapping(value = "/ProteinIdentifierRecognitionQuery", method = RequestMethod.GET, produces = "application/json")
@ResponseBody
@ResponseStatus(HttpStatus.OK)
public boolean getExistedEnsemblidinAlignment(
@RequestParam @ApiParam(value = "Input ensembl id. For example ENSP00000483207.2", required = true, allowMultiple = true) String ensemblId) {
try {
List<Alignment> it = alignmentRepository.findByEnsemblId(ensemblId);
if (it.size() != 0) {
return true;
} else {
return false;
}
} catch (Exception ex) {
ex.printStackTrace();
}
return false;
}

}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package org.cbioportal.pdb_annotation.web.domain;

import java.util.List;

import javax.transaction.Transactional;

import org.cbioportal.pdb_annotation.web.models.Alignment;
import org.springframework.data.jpa.repository.JpaRepository;

/**
*
* @author Juexin Wang
*
*/
@Transactional
public interface AlignmentRepository extends JpaRepository<Alignment, Long>{

public List<Alignment> findByEnsemblId(String ensemblId);

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package org.cbioportal.pdb_annotation.web.domain;

import java.util.List;

import javax.transaction.Transactional;

import org.cbioportal.pdb_annotation.web.models.Alignment;
import org.cbioportal.pdb_annotation.web.models.Ensembl;
import org.springframework.data.jpa.repository.JpaRepository;

/**
*
* @author Juexin Wang
*
*/
@Transactional
public interface EnsemblRepository extends JpaRepository<Alignment, Long>{

public List<Ensembl> findByEnsemblId(String ensemblId);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package org.cbioportal.pdb_annotation.web.domain;

import javax.transaction.Transactional;

import org.cbioportal.pdb_annotation.web.models.Alignment;
import org.springframework.data.jpa.repository.JpaRepository;

/**
*
* @author Juexin Wang
*
*/
@Transactional
public interface PdbRepository extends JpaRepository<Alignment, Long>{

}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,12 @@
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;
import javax.validation.constraints.NotNull;

/**
*
* @author Juexin Wang
*
*/

@Entity
@Table(name = "pdb_ensembl_alignment")
Expand Down Expand Up @@ -55,16 +60,14 @@ public class Alignment {
@Column(name = "IDENTP")
private float identp;

/*
@Column(name = "ENSEMBL_ALIGN")
private String ensemblalign;
private String ensemblAlign;

@Column(name = "PDB_ALIGN")
private String pdbalign;
private String pdbAlign;

@Column(name = "MIDLINE_ALIGN")
private String midlinealign;
*/
private String midlineAlign;


// ------------------------
Expand Down Expand Up @@ -175,33 +178,32 @@ public float getIdentp() {
public void setIdentp(float identp) {
this.identp = identp;
}

/*
public String getEnsemblalign() {
return ensemblalign;

public String getEnsemblAlign() {
return ensemblAlign;
}

public void setEnsemblalign(String ensemblalign) {
this.ensemblalign = ensemblalign;
public void setEnsemblAlign(String ensemblAlign) {
this.ensemblAlign = ensemblAlign;
}

public String getPdbalign() {
return pdbalign;
public String getPdbAlign() {
return pdbAlign;
}

public void setPdbalgin(String pdbalign) {
this.pdbalign = pdbalign;
public void setPdbAlign(String pdbAlign) {
this.pdbAlign = pdbAlign;
}

public String getMidlinealign() {
return midlinealign;
public String getMidlineAlign() {
return midlineAlign;
}

public void setMidlinealign(String midlinealign) {
this.midlinealign = midlinealign;
public void setMidlineAlign(String midlineAlign) {
this.midlineAlign = midlineAlign;
}
*/


/**
* Construction Function
*/
Expand Down
Loading

0 comments on commit 3f68bde

Please sign in to comment.