Skip to content

Commit

Permalink
Merge pull request #5330 from ersinciftci/quick-search
Browse files Browse the repository at this point in the history
Add API support for quick search
  • Loading branch information
ersinciftci authored Nov 27, 2018
2 parents 9e294f5 + fac4651 commit b234274
Show file tree
Hide file tree
Showing 32 changed files with 369 additions and 114 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,10 @@

public interface GeneRepository {

List<Gene> getAllGenes(String alias, String projection, Integer pageSize, Integer pageNumber, String sortBy,
List<Gene> getAllGenes(String keyword, String alias, String projection, Integer pageSize, Integer pageNumber, String sortBy,
String direction);

BaseMeta getMetaGenes(String alias);
BaseMeta getMetaGenes(String keyword, String alias);

Gene getGeneByEntrezGeneId(Integer entrezGeneId);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@

public interface PatientRepository {

List<Patient> getAllPatients(String keyword, String projection, Integer pageSize, Integer pageNumber, String sortBy,
String direction);

BaseMeta getMetaPatients(String keyword);

List<Patient> getAllPatientsInStudy(String studyId, String projection, Integer pageSize, Integer pageNumber,
String sortBy, String direction);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@

public interface StudyRepository {

List<CancerStudy> getAllStudies(String projection, Integer pageSize, Integer pageNumber,
List<CancerStudy> getAllStudies(String keyword, String projection, Integer pageSize, Integer pageNumber,
String sortBy, String direction);

BaseMeta getMetaStudies();
BaseMeta getMetaStudies(String keyword);

CancerStudy getStudy(String studyId, String projection);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@

public interface GeneMapper {

List<Gene> getGenes(String alias, String projection, Integer limit, Integer offset, String sortBy,
List<Gene> getGenes(String keyword, String alias, String projection, Integer limit, Integer offset, String sortBy,
String direction);

BaseMeta getMetaGenes(String alias);
BaseMeta getMetaGenes(String keyword, String alias);

Gene getGeneByEntrezGeneId(Integer entrezGeneId, String projection);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,17 @@ public class GeneMyBatisRepository implements GeneRepository {
private OffsetCalculator offsetCalculator;

@Override
public List<Gene> getAllGenes(String alias, String projection, Integer pageSize, Integer pageNumber, String sortBy,
public List<Gene> getAllGenes(String keyword, String alias, String projection, Integer pageSize, Integer pageNumber, String sortBy,
String direction) {

return geneMapper.getGenes(alias, projection, pageSize, offsetCalculator.calculate(pageSize, pageNumber),
return geneMapper.getGenes(keyword, alias, projection, pageSize, offsetCalculator.calculate(pageSize, pageNumber),
sortBy, direction);
}

@Override
public BaseMeta getMetaGenes(String alias) {
public BaseMeta getMetaGenes(String keyword, String alias) {

return geneMapper.getMetaGenes(alias);
return geneMapper.getMetaGenes(keyword, alias);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@

public interface PatientMapper {

List<Patient> getPatients(List<String> studyIds, List<String> patientIds, String projection, Integer limit,
Integer offset, String sortBy, String direction);
List<Patient> getPatients(List<String> studyIds, List<String> patientIds, String keyword, String projection,
Integer limit, Integer offset, String sortBy, String direction);

BaseMeta getMetaPatients(List<String> studyIds, List<String> patientIds);
BaseMeta getMetaPatients(List<String> studyIds, List<String> patientIds, String keyword);

Patient getPatient(String studyId, String patientId, String projection);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import org.cbioportal.persistence.mybatis.util.OffsetCalculator;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
import org.springframework.web.accept.PathExtensionContentNegotiationStrategy;

import java.util.Arrays;
import java.util.List;
Expand All @@ -20,18 +19,31 @@ public class PatientMyBatisRepository implements PatientRepository {
@Autowired
private OffsetCalculator offsetCalculator;

@Override
public List<Patient> getAllPatients(String keyword, String projection, Integer pageSize, Integer pageNumber,
String sortBy, String direction) {
return patientMapper.getPatients(null, null, keyword, projection, pageSize,
offsetCalculator.calculate(pageSize, pageNumber), sortBy, direction);
}

@Override
public BaseMeta getMetaPatients(String keyword) {

return patientMapper.getMetaPatients(null, null, keyword);
}

@Override
public List<Patient> getAllPatientsInStudy(String studyId, String projection, Integer pageSize, Integer pageNumber,
String sortBy, String direction) {

return patientMapper.getPatients(Arrays.asList(studyId), null, projection, pageSize,
return patientMapper.getPatients(Arrays.asList(studyId), null, null, projection, pageSize,
offsetCalculator.calculate(pageSize, pageNumber), sortBy, direction);
}

@Override
public BaseMeta getMetaPatientsInStudy(String studyId) {

return patientMapper.getMetaPatients(Arrays.asList(studyId), null);
return patientMapper.getMetaPatients(Arrays.asList(studyId), null, null);
}

@Override
Expand All @@ -43,13 +55,13 @@ public Patient getPatientInStudy(String studyId, String patientId) {
@Override
public List<Patient> fetchPatients(List<String> studyIds, List<String> patientIds, String projection) {

return patientMapper.getPatients(studyIds, patientIds, projection, 0, 0, null, null);
return patientMapper.getPatients(studyIds, patientIds, null, projection, 0, 0, null, null);
}

@Override
public BaseMeta fetchMetaPatients(List<String> studyIds, List<String> patientIds) {

return patientMapper.getMetaPatients(studyIds, patientIds);
return patientMapper.getMetaPatients(studyIds, patientIds, null);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@

public interface StudyMapper {

List<CancerStudy> getStudies(List<String> studyIds, String projection, Integer limit, Integer offset, String sortBy,
List<CancerStudy> getStudies(List<String> studyIds, String keyword, String projection, Integer limit, Integer offset, String sortBy,
String direction);

BaseMeta getMetaStudies(List<String> studyIds);
BaseMeta getMetaStudies(List<String> studyIds, String keyword);

CancerStudy getStudy(String studyId, String projection);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,16 @@ public class StudyMyBatisRepository implements StudyRepository {
private OffsetCalculator offsetCalculator;

@Override
public List<CancerStudy> getAllStudies(String projection, Integer pageSize, Integer pageNumber,
public List<CancerStudy> getAllStudies(String keyword, String projection, Integer pageSize, Integer pageNumber,
String sortBy, String direction) {

return studyMapper.getStudies(null, projection, pageSize, offsetCalculator.calculate(pageSize, pageNumber), sortBy,
direction);
return studyMapper.getStudies(null, keyword, projection, pageSize, offsetCalculator.calculate(pageSize, pageNumber),
sortBy, direction);
}

@Override
public BaseMeta getMetaStudies() {
return studyMapper.getMetaStudies(null);
public BaseMeta getMetaStudies(String keyword) {
return studyMapper.getMetaStudies(null, keyword);
}

@Override
Expand All @@ -39,13 +39,13 @@ public CancerStudy getStudy(String studyId, String projection) {
@Override
public List<CancerStudy> fetchStudies(List<String> studyIds, String projection) {

return studyMapper.getStudies(studyIds, projection, 0, 0, null, null);
return studyMapper.getStudies(studyIds, null, projection, 0, 0, null, null);
}

@Override
public BaseMeta fetchMetaStudies(List<String> studyIds) {

return studyMapper.getMetaStudies(studyIds);
return studyMapper.getMetaStudies(studyIds, null);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,23 +14,43 @@
gene.LENGTH AS "${prefix}length"
</if>
</sql>

<sql id="from">
FROM gene
<if test="alias != null">
INNER JOIN gene_alias ON gene.ENTREZ_GENE_ID = gene_alias.ENTREZ_GENE_ID
</if>
</sql>

<sql id="where">
<where>
<if test="alias != null">
gene_alias.GENE_ALIAS = #{alias}
</if>
<if test="keyword != null">
<bind name="searchKeyword" value="'%' + keyword.trim().toLowerCase() + '%'" />
LOWER(gene.HUGO_GENE_SYMBOL) like #{searchKeyword}
</if>
</where>
</sql>

<select id="getGenes" resultType="org.cbioportal.model.Gene">
SELECT
<include refid="select">
<property name="prefix" value=""/>
</include>
FROM gene
<if test="alias != null">
INNER JOIN gene_alias ON gene.ENTREZ_GENE_ID = gene_alias.ENTREZ_GENE_ID
WHERE gene_alias.GENE_ALIAS = #{alias}
</if>
<if test="sortBy != null and projection != 'ID'">
<include refid="from"/>
<include refid="where"/>
<if test="sortBy != null and projection != 'ID' and keyword == null">
ORDER BY ${sortBy} ${direction}
</if>
<if test="projection == 'ID'">
<if test="projection == 'ID' and keyword == null">
ORDER BY gene.ENTREZ_GENE_ID ASC
</if>
<if test="keyword != null">
<bind name="orderKeyword" value="keyword.trim().toLowerCase() + '%'" />
ORDER BY CASE WHEN gene.HUGO_GENE_SYMBOL LIKE #{orderKeyword} THEN 0 ELSE 1 END, gene.HUGO_GENE_SYMBOL
</if>
<if test="limit != null and limit != 0">
LIMIT #{limit} OFFSET #{offset}
</if>
Expand All @@ -39,11 +59,8 @@
<select id="getMetaGenes" resultType="org.cbioportal.model.meta.BaseMeta">
SELECT
COUNT(*) AS totalCount
FROM gene
<if test="_parameter != null">
INNER JOIN gene_alias ON gene.ENTREZ_GENE_ID = gene_alias.ENTREZ_GENE_ID
WHERE gene_alias.GENE_ALIAS = #{alias}
</if>
<include refid="from"/>
<include refid="where"/>
</select>

<select id="getGeneByEntrezGeneId" resultType="org.cbioportal.model.Gene">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,20 @@

<sql id="where">
<where>
<if test="patientIds == null">
cancer_study.CANCER_STUDY_IDENTIFIER = #{studyIds[0]}
<if test="keyword == null">
<if test="patientIds == null and studyIds != null">
cancer_study.CANCER_STUDY_IDENTIFIER = #{studyIds[0]}
</if>
<if test="patientIds != null">
(cancer_study.CANCER_STUDY_IDENTIFIER, patient.STABLE_ID) IN
<foreach index="i" collection="patientIds" open="(" separator="," close=")">
(#{studyIds[${i}]}, #{patientIds[${i}]})
</foreach>
</if>
</if>
<if test="patientIds != null">
(cancer_study.CANCER_STUDY_IDENTIFIER, patient.STABLE_ID) IN
<foreach index="i" collection="patientIds" open="(" separator="," close=")">
(#{studyIds[${i}]}, #{patientIds[${i}]})
</foreach>
<if test="keyword != null">
<bind name="searchKeyword" value="'%' + keyword.trim().toLowerCase() + '%'" />
LOWER(patient.STABLE_ID) like #{searchKeyword}
</if>
</where>
</sql>
Expand All @@ -43,12 +49,16 @@
</include>
<include refid="from"/>
<include refid="where"/>
<if test="sortBy != null and projection != 'ID'">
<if test="sortBy != null and projection != 'ID' and keyword == null">
ORDER BY ${sortBy} ${direction}
</if>
<if test="projection == 'ID'">
<if test="projection == 'ID' and keyword == null">
ORDER BY patient.STABLE_ID ASC
</if>
<if test="keyword != null">
<bind name="orderKeyword" value="keyword.trim().toLowerCase() + '%'" />
ORDER BY CASE WHEN patient.STABLE_ID LIKE #{orderKeyword} THEN 0 ELSE 1 END, patient.STABLE_ID
</if>
<if test="limit != null and limit != 0">
LIMIT #{limit} OFFSET #{offset}
</if>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,28 @@
FROM cancer_study
INNER JOIN sample_list ON cancer_study.CANCER_STUDY_ID = sample_list.CANCER_STUDY_ID
INNER JOIN sample_list_list ON sample_list.LIST_ID = sample_list_list.LIST_ID
<if test="projection == 'DETAILED'">
<if test="projection == 'DETAILED' or keyword != null">
INNER JOIN type_of_cancer ON cancer_study.TYPE_OF_CANCER_ID = type_of_cancer.TYPE_OF_CANCER_ID
</if>
</sql>

<sql id="where">
<where>
<if test="studyIds != null and !studyIds.isEmpty()">
cancer_study.CANCER_STUDY_IDENTIFIER IN
<foreach item="item" collection="studyIds" open="(" separator="," close=")">
#{item}
</foreach>
</if>
<if test="keyword != null">
<bind name="searchKeyword" value="'%' + keyword.trim().toLowerCase() + '%'" />
LOWER(cancer_study.NAME) like #{searchKeyword} OR
LOWER(cancer_study.DESCRIPTION) like #{searchKeyword} OR
LOWER(type_of_cancer.NAME) like #{searchKeyword}
</if>
</where>
</sql>

<select id="getStudies" resultType="org.cbioportal.model.CancerStudy">
SELECT
<include refid="select">
Expand All @@ -60,21 +77,19 @@
<include refid="selectDetailed"/>
</if>
<include refid="from"/>
<where>
<if test="studyIds != null and !studyIds.isEmpty()">
cancer_study.CANCER_STUDY_IDENTIFIER IN
<foreach item="item" collection="studyIds" open="(" separator="," close=")">
#{item}
</foreach>
</if>
</where>
<include refid="where"/>
GROUP BY cancer_study.CANCER_STUDY_ID
<if test="sortBy != null and projection != 'ID'">
<if test="sortBy != null and projection != 'ID' and keyword == null">
ORDER BY ${sortBy} ${direction}
</if>
<if test="projection == 'ID'">
<if test="projection == 'ID' and keyword == null">
ORDER BY cancer_study.CANCER_STUDY_IDENTIFIER ASC
</if>
<if test="keyword != null">
<bind name="orderKeyword" value="keyword.trim().toLowerCase() + '%'" />
ORDER BY CASE WHEN cancer_study.NAME LIKE #{orderKeyword} THEN 0 ELSE 1 END,
CASE WHEN cancer_study.NAME LIKE '%tcga%' THEN 0 ELSE 1 END, cancer_study.NAME
</if>
<if test="limit != null and limit != 0">
LIMIT #{limit} OFFSET #{offset}
</if>
Expand All @@ -84,14 +99,10 @@
SELECT
COUNT(*) AS totalCount
FROM cancer_study
<where>
<if test="list != null and !list.isEmpty()">
cancer_study.CANCER_STUDY_IDENTIFIER IN
<foreach item="item" collection="list" open="(" separator="," close=")">
#{item}
</foreach>
</if>
</where>
<if test="keyword != null">
INNER JOIN type_of_cancer ON cancer_study.TYPE_OF_CANCER_ID = type_of_cancer.TYPE_OF_CANCER_ID
</if>
<include refid="where"/>
</select>

<select id="getStudy" resultType="org.cbioportal.model.CancerStudy">
Expand Down
Loading

0 comments on commit b234274

Please sign in to comment.