use of ubic.gemma.model.common.description.VocabCharacteristic in project Gemma by PavlidisLab.
the class CharacteristicUpdateTaskImpl method convertAvo2Characteristic.
private VocabCharacteristic convertAvo2Characteristic(AnnotationValueObject avo) {
VocabCharacteristic vc = VocabCharacteristic.Factory.newInstance();
vc.setId(avo.getId());
vc.setCategory(avo.getClassName());
vc.setCategoryUri(avo.getClassUri());
vc.setValue(avo.getTermName());
vc.setValueUri(avo.getTermUri());
if (StringUtils.isNotBlank(avo.getEvidenceCode()))
vc.setEvidenceCode(GOEvidenceCode.fromString(avo.getEvidenceCode()));
return vc;
}
use of ubic.gemma.model.common.description.VocabCharacteristic in project Gemma by PavlidisLab.
the class NCBIGene2GOAssociationParser method mapFromGene2GO.
/**
* Note that "-" means a missing value, which in practice only occurs in the "qualifier" and "pubmed" columns.
*
* @param line line
* @return Object
*/
// Possible external use
@SuppressWarnings({ "unused", "WeakerAccess" })
public Gene2GOAssociation mapFromGene2GO(String line) {
String[] values = StringUtils.splitPreserveAllTokens(line, "\t");
if (line.startsWith(NCBIGene2GOAssociationParser.COMMENT_INDICATOR))
return null;
if (values.length < 8)
return null;
Integer taxonId;
try {
taxonId = Integer.parseInt(values[TAX_ID]);
} catch (NumberFormatException e) {
throw new RuntimeException(e);
}
if (!taxaNcbiIds.containsKey(taxonId)) {
return null;
}
Gene gene = Gene.Factory.newInstance();
gene.setNcbiGeneId(Integer.parseInt(values[GENE_ID]));
gene.setTaxon(taxaNcbiIds.get(taxonId));
VocabCharacteristic oe = VocabCharacteristic.Factory.newInstance();
String value = values[GO_ID].replace(":", "_");
oe.setValueUri(GeneOntologyService.BASE_GO_URI + value);
oe.setValue(value);
// g2GOAss.setSource( ncbiGeneDb );
GOEvidenceCode evcode = null;
String evidenceCode = values[EVIDENCE_CODE];
if (!(StringUtils.isBlank(evidenceCode) || evidenceCode.equals("-"))) {
if (NCBIGene2GOAssociationParser.ignoredEvidenceCodes.contains(evidenceCode)) {
return null;
}
evcode = GOEvidenceCode.fromString(evidenceCode);
}
Gene2GOAssociation g2GOAss = Gene2GOAssociation.Factory.newInstance(gene, oe, evcode);
try {
queue.put(g2GOAss);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
return g2GOAss;
}
use of ubic.gemma.model.common.description.VocabCharacteristic in project Gemma by PavlidisLab.
the class ExperimentalDesignImporterImpl method addFactorValuesToExperimentalFactor.
/**
* Method that adds factor values to a given experimental factor
*
* @param experimentalFactor The experimental factor to add the factor values to
* @param factorSampleValues A map of factor value names keyed on experimental factor name
* @param factorType Whether the factor is continuous or categorical
*/
private void addFactorValuesToExperimentalFactor(ExperimentalFactor experimentalFactor, Map<String, Set<String>> factorSampleValues, String factorType) {
ExperimentalDesignImporterImpl.log.debug("Addding factors values to experimental factor: " + experimentalFactor.getName());
VocabCharacteristic category = (VocabCharacteristic) experimentalFactor.getCategory();
Set<String> values = factorSampleValues.get(experimentalFactor.getName());
for (String value : values) {
FactorValue factorValue = FactorValue.Factory.newInstance();
factorValue.setValue(value);
if (factorType.equalsIgnoreCase("CATEGORICAL")) {
ExperimentalDesignImporterImpl.log.debug("Factor is categorical");
VocabCharacteristic newVc = VocabCharacteristic.Factory.newInstance();
String category2 = category.getCategory();
assert category2 != null;
newVc.setCategory(category2);
newVc.setCategoryUri(category.getCategoryUri());
newVc.setValue(value);
newVc.setEvidenceCode(GOEvidenceCode.IC);
factorValue.getCharacteristics().add(newVc);
} else {
ExperimentalDesignImporterImpl.log.debug("Factor is continous");
this.addMeasurementToFactorValueOfTypeContinous(factorValue);
}
// set bidirectional relationship
experimentalFactor.getFactorValues().add(factorValue);
factorValue.setExperimentalFactor(experimentalFactor);
ExperimentalDesignImporterImpl.log.debug("Added factor value " + factorValue + " to experimental factor " + experimentalFactor);
}
}
use of ubic.gemma.model.common.description.VocabCharacteristic in project Gemma by PavlidisLab.
the class ExperimentalDesignImporterImpl method addExperimentalFactorsToExperimentalDesign.
/**
* This method reads the file line e.g. $Run time : Category=environmental_history Type=categorical and creates
* experimental factors from it and adds them to the experimental design.
* NOTE that this doesn't have the ability to add values to existing factors, which might be desirable.
*
* @param experimentalDesign Experimental design for this expression experiment
* @param experimentalFactorFileLines List of strings representing lines from input file containing experimental
* factors
* @param headerFields Sample header line split on tab.
* @param factorValueLines Lines containing biomaterial names and their factor values
*/
private void addExperimentalFactorsToExperimentalDesign(ExperimentalDesign experimentalDesign, List<String> experimentalFactorFileLines, String[] headerFields, List<String> factorValueLines) {
int maxWait = 0;
if (efoService.isEnabled()) {
while (!efoService.isOntologyLoaded()) {
try {
Thread.sleep(10000);
if (maxWait++ > 10) {
ExperimentalDesignImporterImpl.log.error("EFO is not loaded and gave up waiting");
break;
// this is okay, we can get by using OntologyTermSimple.
}
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
Collection<OntologyTerm> terms = ontologyService.getCategoryTerms();
if (experimentalDesign.getExperimentalFactors() == null) {
experimentalDesign.setExperimentalFactors(new HashSet<ExperimentalFactor>());
}
Map<String, Set<String>> mapFactorSampleValues = this.getMapFactorSampleValues(headerFields, factorValueLines);
for (String experimentalFactorFileLine : experimentalFactorFileLines) {
// $Run time : Category=EnvironmentalHistory Type=categorical
String[] experimentalFactorfields = experimentalFactorFileLine.split(":");
String factorValue = (StringUtils.strip(experimentalFactorfields[0].replaceFirst(Pattern.quote(ExperimentalDesignImporterImpl.EXPERIMENTAL_FACTOR_DESCRIPTION_LINE_INDICATOR) + "\\s*", ""))).trim();
String categoryAndType = StringUtils.strip(experimentalFactorfields[1]);
String[] categoryAndTypeFields = StringUtils.split(categoryAndType);
// e.g. Category=EnvironmentalHistory
String category = categoryAndTypeFields[0];
// e.g. EnvironmentalHistory
String categoryValue = StringUtils.split(category, "=")[1];
ExperimentalFactor experimentalFactorFromFile = ExperimentalFactor.Factory.newInstance();
experimentalFactorFromFile.setExperimentalDesign(experimentalDesign);
VocabCharacteristic vc = this.termForCategoryLookup(categoryValue, terms);
// e.g. Category=EnvironmentalHistory
String categoryTypeValue = categoryAndTypeFields[1];
String factorType = StringUtils.split(categoryTypeValue, "=")[1];
// vc.setCategory( categoryType );
experimentalFactorFromFile.setCategory(vc);
experimentalFactorFromFile.setName(factorValue);
experimentalFactorFromFile.setDescription(factorValue);
experimentalFactorFromFile.setType(factorType.equalsIgnoreCase("CATEGORICAL") ? FactorType.CATEGORICAL : FactorType.CONTINUOUS);
this.addFactorValuesToExperimentalFactor(experimentalFactorFromFile, mapFactorSampleValues, factorType);
if (!this.checkForDuplicateExperimentalFactorOnExperimentalDesign(experimentalDesign, experimentalFactorFromFile)) {
experimentalDesign.getExperimentalFactors().add(experimentalFactorFromFile);
ExperimentalDesignImporterImpl.log.info("Added " + experimentalFactorFromFile);
}
}
}
use of ubic.gemma.model.common.description.VocabCharacteristic in project Gemma by PavlidisLab.
the class OntologyServiceImpl method termsToCharacteristics.
/**
* Convert raw ontology resources into VocabCharacteristics.
*/
@Override
public Collection<VocabCharacteristic> termsToCharacteristics(final Collection<? extends OntologyResource> terms) {
Collection<VocabCharacteristic> results = new HashSet<>();
if ((terms == null) || (terms.isEmpty()))
return results;
for (OntologyResource res : terms) {
if (res == null)
continue;
VocabCharacteristic vc = VocabCharacteristic.Factory.newInstance();
if (res instanceof OntologyTerm) {
OntologyTerm term = (OntologyTerm) res;
vc.setValue(term.getTerm());
vc.setValueUri(term.getUri());
vc.setDescription(term.getComment());
} else if (res instanceof OntologyIndividual) {
OntologyIndividual indi = (OntologyIndividual) res;
vc.setValue(indi.getLabel());
vc.setValueUri(indi.getUri());
vc.setDescription("Individual");
} else {
OntologyServiceImpl.log.warn("What is it? " + res);
continue;
}
if (vc.getValue() == null)
continue;
results.add(vc);
}
OntologyServiceImpl.log.debug("returning " + results.size() + " terms after filter");
return results;
}
Aggregations