Skip to content

Commit

Permalink
Issue #25: Convert all incoming gene IDs to the same naming scheme we…
Browse files Browse the repository at this point in the history
… use in PhenoTips internally.

Fixed.
  • Loading branch information
allasm committed Aug 25, 2015
1 parent e36277a commit 2fc4117
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
import org.phenotips.remote.common.internal.api.DefaultJSONToMatchingPatientConverter;
import org.phenotips.remote.hibernate.RemoteMatchingStorageManager;
import org.phenotips.remote.hibernate.internal.DefaultOutgoingMatchRequest;
import org.phenotips.vocabulary.Vocabulary;
import org.slf4j.Logger;
import org.xwiki.component.annotation.Component;
import org.xwiki.context.Execution;
Expand Down Expand Up @@ -84,6 +85,10 @@ public class DefaultRemoteMatchingService implements RemoteMatchingService
@Named("match")
protected AccessLevel matchAccess;

@Inject
@Named("hgnc")
private Vocabulary ontologyService;

@Inject
PatientRepository patientRepository;

Expand Down Expand Up @@ -229,7 +234,7 @@ public List<PatientSimilarityView> getSimilarityResults(OutgoingMatchRequest req
}

DefaultJSONToMatchingPatientConverter patientConverter =
new DefaultJSONToMatchingPatientConverter(ApiConfiguration.LATEST_API_VERSION_STRING, logger);
new DefaultJSONToMatchingPatientConverter(ApiConfiguration.LATEST_API_VERSION_STRING, logger, ontologyService);

//JSONArray processedResults = new JSONArray();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
import org.phenotips.remote.api.fromjson.IncomingJSONParser;
import org.phenotips.remote.api.fromjson.JSONToMatchingPatientConverter;
import org.phenotips.remote.hibernate.internal.DefaultIncomingMatchRequest;

import org.phenotips.vocabulary.Vocabulary;
import org.slf4j.Logger;

import net.sf.json.JSONObject;
Expand All @@ -40,12 +40,12 @@ public class DefaultIncomingJSONParser implements IncomingJSONParser

private final String apiVersion;

public DefaultIncomingJSONParser(String apiVersion, Logger logger)
public DefaultIncomingJSONParser(String apiVersion, Logger logger, Vocabulary ontologyService)
{
this.apiVersion = apiVersion;
this.logger = logger;

this.patientConverter = new DefaultJSONToMatchingPatientConverter(apiVersion, logger);
this.patientConverter = new DefaultJSONToMatchingPatientConverter(apiVersion, logger, ontologyService);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,17 @@
import org.phenotips.remote.common.internal.RemotePatientFeature;
import org.phenotips.remote.common.internal.RemotePatientGene;
import org.phenotips.remote.common.internal.RemotePatientContactInfo;
import org.phenotips.vocabulary.Vocabulary;
import org.phenotips.vocabulary.VocabularyTerm;
import org.slf4j.Logger;

import java.util.HashSet;
import java.util.Set;
import java.util.regex.Pattern;

import javax.inject.Inject;
import javax.inject.Named;

import net.sf.json.JSONArray;
import net.sf.json.JSONObject;

Expand All @@ -48,10 +53,13 @@ public class DefaultJSONToMatchingPatientConverter implements JSONToMatchingPati
private final Pattern hpoTerm; // not static: may be different from api version to api version
private final Pattern disorderTerm;

public DefaultJSONToMatchingPatientConverter(String apiVersion, Logger logger)
private final Vocabulary ontologyService;

public DefaultJSONToMatchingPatientConverter(String apiVersion, Logger logger, Vocabulary ontologyService)
{
this.apiVersion = apiVersion;
this.logger = logger;
this.logger = logger;
this.ontologyService = ontologyService;

this.hpoTerm = Pattern.compile("^HP:\\d+$");
this.disorderTerm = Pattern.compile("^MIM:\\d+$"); // TODO: Orphanet:#####
Expand Down Expand Up @@ -172,12 +180,29 @@ private Set<MatchingPatientGene> convertGenes(JSONObject json)
throw new ApiViolationException("A gene has no id");
}
// TODO: check if name is a valid gene symbol or ensembl id
MatchingPatientGene gene = new RemotePatientGene(geneName);
VocabularyTerm geneTerm = this.ontologyService.getTerm(geneName);
if (geneTerm == null) {
logger.error("Patient genomic features parser: gene id [{}] was not found in the vocabulary", geneName);
throw new ApiViolationException("A gene has unsupported id [" + geneName + "]");
}
String symbol;
try {
symbol = (String)(geneTerm.get("symbol"));
if (!geneName.equals(symbol)) {
this.logger.debug("Converted incoming gene id [{}] to symbol [{}]", geneName, symbol);
}
} catch (Exception ex) {
logger.error("Patient genomic features parser: can not obtain gene symbol for gene ID [{}]", geneName);
throw new ApiViolationException("Internal error processing gene id [" + geneName + "]");
}
MatchingPatientGene gene = new RemotePatientGene(symbol);
geneSet.add(gene);
// TODO: variants
}
return geneSet;
}
} catch (ApiViolationException ex) {
throw ex;
} catch (Exception ex) {
this.logger.error("Error converting genes: {}", ex);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import org.phenotips.remote.api.fromjson.IncomingJSONParser;
import org.phenotips.remote.api.tojson.OutgoingJSONGenerator;
import org.phenotips.remote.api.tojson.PatientToJSONConverter;
import org.phenotips.vocabulary.Vocabulary;
import org.xwiki.security.authorization.AuthorizationManager;
import org.xwiki.bridge.DocumentAccessBridge;
import org.slf4j.Logger;
Expand Down Expand Up @@ -72,9 +73,14 @@ public class ApiDataConverterV1 implements ApiDataConverter, Initializable
@Inject
private DocumentAccessBridge bridge;

/** Used for converting gene ID between different id schemas */
@Inject
@Named("hgnc")
private Vocabulary ontologyService;

public void initialize()
{
incomingJSONParser = new DefaultIncomingJSONParser(getApiVersion(), logger);
incomingJSONParser = new DefaultIncomingJSONParser(getApiVersion(), logger, ontologyService);

patientToJSONConverter = new DefaultPatientToJSONConverter(getApiVersion(), logger);

Expand Down

0 comments on commit 2fc4117

Please sign in to comment.