Skip to content

Commit

Permalink
<BUGFIX> PhenotypePage: Fix gene count queries
Browse files Browse the repository at this point in the history
  • Loading branch information
jmason-ebi committed Jul 12, 2021
1 parent c9cd552 commit 939947d
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 37 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -356,27 +356,24 @@ public List<GenotypePhenotypeDTO> getAllMPByPhenotypingCenterAndColonies(String



public List<Group> getGenesBy(String mpId, String sex, boolean onlyB6N)
public List<GenotypePhenotypeDTO> getGenesBy(String mpId, String sex, boolean onlyB6N)
throws SolrServerException, IOException {

// males only
SolrQuery q = new SolrQuery().setQuery("(" + GenotypePhenotypeDTO.MP_TERM_ID + ":\"" + mpId + "\" OR " +
GenotypePhenotypeDTO.TOP_LEVEL_MP_TERM_ID + ":\"" + mpId + "\" OR " +
GenotypePhenotypeDTO.INTERMEDIATE_MP_TERM_ID + ":\"" + mpId + "\")");
GenotypePhenotypeDTO.INTERMEDIATE_MP_TERM_ID + ":\"" + mpId + "\")")
.setRows(Integer.MAX_VALUE)
.setFields(GenotypePhenotypeDTO.MARKER_SYMBOL);
if (onlyB6N){
q.setFilterQueries("(" + GenotypePhenotypeDTO.STRAIN_ACCESSION_ID + ":\"" + StringUtils.join(OverviewChartsConstants.B6N_STRAINS, "\" OR " +
GenotypePhenotypeDTO.STRAIN_ACCESSION_ID + ":\"") + "\")");
}
q.setRows(10000000);
q.set("group.field", "" + GenotypePhenotypeDTO.MARKER_SYMBOL);
q.set("group", true);
q.set("group.limit", 0);

if (sex != null) {
q.addFilterQuery(GenotypePhenotypeDTO.SEX + ":" + sex);
}
QueryResponse results = genotypePhenotypeCore.query(q);

return results.getGroupResponse().getValues().get(0).getValues();
List<GenotypePhenotypeDTO> results = genotypePhenotypeCore.query(q).getBeans(GenotypePhenotypeDTO.class);
return results.stream().distinct().collect(Collectors.toList());
}

public List<String> getGenesAssocByParamAndMp(String parameterStableId, String phenotype_id)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
import org.apache.solr.common.util.NamedList;
import org.mousephenotype.cda.common.Constants;
import org.mousephenotype.cda.constants.OverviewChartsConstants;
import org.mousephenotype.cda.enumerations.ObservationType;
import org.mousephenotype.cda.enumerations.SexType;
import org.mousephenotype.cda.enumerations.ZygosityType;
import org.mousephenotype.cda.solr.SolrUtils;
Expand Down Expand Up @@ -1325,32 +1324,49 @@ public List<BasicBean> getProceduresForDataSource(String resourceName) {
*/


public List<Group> getGenesBy(String mpId, SexType sex)
throws SolrServerException, IOException {
public List<StatisticalResultDTO> getGenesBy(String mpId, String sex)
throws SolrServerException, IOException {

SolrQuery q = new SolrQuery().setQuery("(" + StatisticalResultDTO.MP_TERM_ID + ":\"" + mpId + "\" OR " +
StatisticalResultDTO.TOP_LEVEL_MP_TERM_ID + ":\"" + mpId + "\" OR " +
StatisticalResultDTO.MP_TERM_ID_OPTIONS + ":\"" + mpId + "\" OR " +
StatisticalResultDTO.INTERMEDIATE_MP_TERM_ID + ":\"" + mpId + "\")")
.setRows(10000)
.setSort(StatisticalResultDTO.DOCUMENT_ID, SolrQuery.ORDER.asc);
q.set("group.field", "" + StatisticalResultDTO.MARKER_SYMBOL);
q.set("group", true);
q.set("group.limit", 0);
.setRows(Integer.MAX_VALUE)
.setFields(String.join(",", Arrays.asList(StatisticalResultDTO.MARKER_SYMBOL, StatisticalResultDTO.SEX)));

if (sex != null) {
q.addFilterQuery("(" + StatisticalResultDTO.PHENOTYPE_SEX + ":" + sex.getName() + " OR " + StatisticalResultDTO.SEX + ":" + sex.getName() + ")");
q.addFilterQuery("(" + StatisticalResultDTO.PHENOTYPE_SEX + ":" + sex + " OR " + StatisticalResultDTO.SEX + ":" + sex + ")");
}

System.out.println("Query: " + q);

QueryResponse results = statisticalResultCore.query(q);

System.out.println("Results: " + results.getGroupResponse().getValues().get(0).getValues().size());

return results.getGroupResponse().getValues().get(0).getValues();
List<StatisticalResultDTO> results = statisticalResultCore.query(q).getBeans(StatisticalResultDTO.class);
return results.stream().distinct().collect(Collectors.toList());
}

// public List<Group> getGenesBy(String mpId, SexType sex)
// throws SolrServerException, IOException {
//
// SolrQuery q = new SolrQuery().setQuery("(" + StatisticalResultDTO.MP_TERM_ID + ":\"" + mpId + "\" OR " +
// StatisticalResultDTO.TOP_LEVEL_MP_TERM_ID + ":\"" + mpId + "\" OR " +
// StatisticalResultDTO.MP_TERM_ID_OPTIONS + ":\"" + mpId + "\" OR " +
// StatisticalResultDTO.INTERMEDIATE_MP_TERM_ID + ":\"" + mpId + "\")")
// .setRows(10000)
// .setSort(StatisticalResultDTO.DOCUMENT_ID, SolrQuery.ORDER.asc);
// q.set("group.field", "" + StatisticalResultDTO.MARKER_SYMBOL);
// q.set("group", true);
// q.set("group.limit", 0);
//
// if (sex != null) {
// q.addFilterQuery("(" + StatisticalResultDTO.PHENOTYPE_SEX + ":" + sex.getName() + " OR " + StatisticalResultDTO.SEX + ":" + sex.getName() + ")");
// }
//
// System.out.println("Query: " + q);
//
// QueryResponse results = statisticalResultCore.query(q);
//
// System.out.println("Results: " + results.getGroupResponse().getValues().get(0).getValues().size());
//
// return results.getGroupResponse().getValues().get(0).getValues();
// }

Set<String> nullFilterFields = new TreeSet<>();

public List<StatisticalResultDTO> getImpcPvalues() throws SolrServerException, IOException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@

import com.opencsv.CSVWriter;
import org.apache.solr.client.solrj.SolrServerException;
import org.apache.solr.client.solrj.response.Group;
import org.mousephenotype.cda.enumerations.SexType;
import org.mousephenotype.cda.solr.service.GenotypePhenotypeService;
import org.mousephenotype.cda.solr.service.StatisticalResultService;
import org.mousephenotype.cda.solr.service.dto.GenotypePhenotypeDTO;
import uk.ac.ebi.phenotype.util.PhenotypeGeneSummaryDTO;

import javax.servlet.http.HttpServletResponse;
Expand Down Expand Up @@ -98,31 +98,33 @@ public static PhenotypeGeneSummaryDTO getPercentages(String phenotype_id, Statis
boolean display = (total > 0);
pgs.setDisplay(display);

List<String> genesFemalePhenotype = new ArrayList<String>();
List<String> genesMalePhenotype = new ArrayList<String>();
List<String> genesFemalePhenotype = new ArrayList<>();
List<String> genesMalePhenotype = new ArrayList<>();
List<String> genesBothPhenotype;

if (display) {
for (Group g : gpService.getGenesBy(phenotype_id, "female", false)) {
genesFemalePhenotype.add((String) g.getGroupValue());
for (GenotypePhenotypeDTO dto : gpService.getGenesBy(phenotype_id, "female", false)) {
genesFemalePhenotype.add(dto.getMarkerSymbol());
}

nominator = genesFemalePhenotype.size();
total = srService.getGenesBy(phenotype_id, SexType.female).size();
total = srService.getGenesBy(phenotype_id, SexType.female.getName()).size();
pgs.setFemalePercentage(100 * (float) nominator / (float) total);
pgs.setFemaleGenesAssociated(nominator);
pgs.setFemaleGenesTested(total);

for (Group g : gpService.getGenesBy(phenotype_id, "male", false)) {
genesMalePhenotype.add(g.getGroupValue());
for (GenotypePhenotypeDTO dto : gpService.getGenesBy(phenotype_id, "male", false)) {
genesMalePhenotype.add(dto.getMarkerSymbol());
}

nominator = genesMalePhenotype.size();
total = srService.getGenesBy(phenotype_id, SexType.male).size();
total = srService.getGenesBy(phenotype_id, SexType.male.getName()).size();
pgs.setMalePercentage(100 * (float) nominator / (float) total);
pgs.setMaleGenesAssociated(nominator);
pgs.setMaleGenesTested(total);
}

genesBothPhenotype = new ArrayList<String>(genesFemalePhenotype);
genesBothPhenotype = new ArrayList<>(genesFemalePhenotype);
genesBothPhenotype.retainAll(genesMalePhenotype);
genesFemalePhenotype.removeAll(genesBothPhenotype);
genesMalePhenotype.removeAll(genesBothPhenotype);
Expand Down

0 comments on commit 939947d

Please sign in to comment.