Skip to content

Commit

Permalink
ALS-4978: Move genomic client from genomic processor project
Browse files Browse the repository at this point in the history
  • Loading branch information
ramari16 committed Nov 2, 2023
1 parent ab4e9a9 commit 5bbd8a8
Show file tree
Hide file tree
Showing 8 changed files with 146 additions and 20 deletions.
26 changes: 21 additions & 5 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -283,11 +283,6 @@
<artifactId>jackson-jaxrs</artifactId>
<version>${jackson.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<version>4.3.20.RELEASE</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
Expand Down Expand Up @@ -320,6 +315,27 @@
<artifactId>spring-test</artifactId>
<version>4.3.30.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webflux</artifactId>
<version>6.0.13</version>
</dependency>
<dependency>
<groupId>io.projectreactor.netty</groupId>
<artifactId>reactor-netty</artifactId>
<version>1.1.12</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<version>6.0.13</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>6.0.13</version>
</dependency>


</dependencies>
</dependencyManagement>
Expand Down
12 changes: 12 additions & 0 deletions processing/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,21 @@
<version>8.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webflux</artifactId>
</dependency>
<dependency>
<groupId>io.projectreactor.netty</groupId>
<artifactId>reactor-netty</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
import edu.harvard.hms.dbmi.avillach.hpds.data.phenotype.ColumnMeta;
import edu.harvard.hms.dbmi.avillach.hpds.data.phenotype.PhenoCube;
import edu.harvard.hms.dbmi.avillach.hpds.data.query.Query;
import edu.harvard.hms.dbmi.avillach.hpds.data.query.Query.VariantInfoFilter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

Expand Down Expand Up @@ -186,7 +185,7 @@ protected Set<Integer> idSetsForEachFilter(Query query) {
DistributableQuery distributableQuery = getDistributableQuery(query);

if (distributableQuery.hasFilters()) {
BigInteger patientMaskForVariantInfoFilters = genomicProcessor.getPatientMaskForVariantInfoFilters(distributableQuery);
BigInteger patientMaskForVariantInfoFilters = genomicProcessor.getPatientMask(distributableQuery);
return patientMaskToPatientIdSet(patientMaskForVariantInfoFilters);
}

Expand Down Expand Up @@ -324,7 +323,7 @@ private List<Set<Integer>> getIdSetsForCategoryFilters(Query query, Distributabl

protected Collection<String> getVariantList(Query query) throws IOException {
DistributableQuery distributableQuery = getDistributableQuery(query);
return genomicProcessor.processVariantList(distributableQuery);
return genomicProcessor.getVariantList(distributableQuery);
}

public FileBackedByteIndexedInfoStore getInfoStore(String column) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,17 @@
package edu.harvard.hms.dbmi.avillach.hpds.processing;

import edu.harvard.hms.dbmi.avillach.hpds.data.query.Query;

import java.math.BigInteger;
import java.util.Collection;
import java.util.Set;

public interface GenomicProcessor {
BigInteger getPatientMaskForVariantInfoFilters(DistributableQuery distributableQuery);
BigInteger getPatientMask(DistributableQuery distributableQuery);

Set<Integer> patientMaskToPatientIdSet(BigInteger patientMask);

BigInteger createMaskForPatientSet(Set<Integer> patientSubset);

Collection<String> processVariantList(DistributableQuery distributableQuery);
Collection<String> getVariantList(DistributableQuery distributableQuery);

String[] getPatientIds();
}
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public GenomicProcessorNodeImpl(String genomicDataDirectory) {
}

@Override
public BigInteger getPatientMaskForVariantInfoFilters(DistributableQuery distributableQuery) {
public BigInteger getPatientMask(DistributableQuery distributableQuery) {
// log.debug("filterdIDSets START size: " + filteredIdSets.size());
/* VARIANT INFO FILTER HANDLING IS MESSY */
if(distributableQuery.hasFilters()) {
Expand Down Expand Up @@ -224,7 +224,7 @@ private VariantIndex addVariantsForInfoFilter(VariantIndex unionOfInfoFilters, Q
}

@Override
public Collection<String> processVariantList(DistributableQuery query) {
public Collection<String> getVariantList(DistributableQuery query) {
boolean queryContainsVariantInfoFilters = query.getVariantInfoFilters().stream().anyMatch(variantInfoFilter ->
!variantInfoFilter.categoryVariantInfoFilters.isEmpty() || !variantInfoFilter.numericVariantInfoFilters.isEmpty()
);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package edu.harvard.hms.dbmi.avillach.hpds.processing;

import edu.harvard.hms.dbmi.avillach.hpds.data.query.Query;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
Expand Down Expand Up @@ -31,13 +30,13 @@ public GenomicProcessorParentImpl() {
}

@Override
public BigInteger getPatientMaskForVariantInfoFilters(DistributableQuery distributableQuery) {
public BigInteger getPatientMask(DistributableQuery distributableQuery) {
BigInteger patientMask = null;
for (GenomicProcessor node : nodes) {
if (patientMask == null) {
patientMask = node.getPatientMaskForVariantInfoFilters(distributableQuery);
patientMask = node.getPatientMask(distributableQuery);
} else {
patientMask = patientMask.or(node.getPatientMaskForVariantInfoFilters(distributableQuery));
patientMask = patientMask.or(node.getPatientMask(distributableQuery));
}
log.info("Patients: " + node.patientMaskToPatientIdSet(patientMask));
}
Expand All @@ -55,9 +54,9 @@ public BigInteger createMaskForPatientSet(Set<Integer> patientSubset) {
}

@Override
public Collection<String> processVariantList(DistributableQuery distributableQuery) {
public Collection<String> getVariantList(DistributableQuery distributableQuery) {
return nodes.parallelStream().flatMap(node ->
node.processVariantList(distributableQuery).stream()).collect(Collectors.toList()
node.getVariantList(distributableQuery).stream()).collect(Collectors.toList()
);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
package edu.harvard.hms.dbmi.avillach.hpds.processing.genomic;

import edu.harvard.hms.dbmi.avillach.hpds.data.query.Query;
import edu.harvard.hms.dbmi.avillach.hpds.processing.DistributableQuery;
import edu.harvard.hms.dbmi.avillach.hpds.processing.GenomicProcessor;
import org.springframework.http.HttpHeaders;
import org.springframework.http.MediaType;
import org.springframework.web.reactive.function.client.WebClient;
import reactor.core.publisher.Mono;

import java.math.BigInteger;
import java.util.Collection;
import java.util.Set;

public class GenomicProcessorRestClient implements GenomicProcessor {

private final WebClient webClient;

public GenomicProcessorRestClient(String serviceUrl) {
this.webClient = WebClient.builder()
.baseUrl(serviceUrl)
.defaultHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE)
.build();
}

@Override
public BigInteger getPatientMask(DistributableQuery distributableQuery) {
return webClient.post()
.uri("/patients")
.contentType(MediaType.APPLICATION_JSON)
.body(Mono.just(distributableQuery), DistributableQuery.class)
.retrieve()
.bodyToMono(BigInteger.class)
.block();
}

@Override
public Set<Integer> patientMaskToPatientIdSet(BigInteger patientMask) {
return null;
}

@Override
public BigInteger createMaskForPatientSet(Set<Integer> patientSubset) {
return null;
}

@SuppressWarnings("unchecked")
@Override
public Collection<String> getVariantList(DistributableQuery distributableQuery) {
return webClient.post()
.uri("/variants")
.contentType(MediaType.APPLICATION_JSON)
.body(Mono.just(distributableQuery), DistributableQuery.class)
.retrieve()
.bodyToMono(Collection.class)
.block();
}

@Override
public String[] getPatientIds() {
return new String[0];
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package edu.harvard.hms.dbmi.avillach.hpds.processing.genomic;

import com.fasterxml.jackson.core.JsonProcessingException;
import edu.harvard.hms.dbmi.avillach.hpds.data.query.Query;
import edu.harvard.hms.dbmi.avillach.hpds.processing.DistributableQuery;
import org.junit.Test;

import java.math.BigInteger;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Set;

public class GenomicProcessorRestClientTest {

private GenomicProcessorRestClient genomicProcessorRestClient = new GenomicProcessorRestClient("http://localhost:8090/");


@Test
public void test() throws JsonProcessingException {
DistributableQuery distributableQuery = new DistributableQuery();

List<Query.VariantInfoFilter> variantInfoFilters = new ArrayList<>();
Query.VariantInfoFilter variantInfoFilter = new Query.VariantInfoFilter();
variantInfoFilter.categoryVariantInfoFilters = Map.of(
"Gene_with_variant", new String[]{"FRG1FP"}
);
Query.VariantInfoFilter variantInfoFilter2 = new Query.VariantInfoFilter();
variantInfoFilter2.categoryVariantInfoFilters = Map.of(
"Gene_with_variant", new String[]{"ACTG1P3"}
);
variantInfoFilters.add(variantInfoFilter2);
distributableQuery.setVariantInfoFilters(variantInfoFilters);
distributableQuery.setPatientIds(Set.of(1, 2, 3, 4, 5, 6, 7, 8, 9, 10));

BigInteger patientMaskForVariantInfoFilters = genomicProcessorRestClient.getPatientMask(distributableQuery);
System.out.println(patientMaskForVariantInfoFilters);
}
}

0 comments on commit 5bbd8a8

Please sign in to comment.