use of ubic.gemma.model.common.description.Characteristic in project Gemma by PavlidisLab.
the class BatchInfoPopulationHelperServiceImpl method createBatchFactor.
@Override
@Transactional
public ExperimentalFactor createBatchFactor(ExpressionExperiment ee, Map<BioMaterial, Date> dates) {
/*
* Go through the dates and convert to factor values.
*/
Collection<Date> allDates = new HashSet<>(dates.values());
Map<String, Collection<Date>> datesToBatch = this.convertDatesToBatches(allDates);
Map<Date, FactorValue> d2fv = new HashMap<>();
ExperimentalFactor ef = null;
if (datesToBatch == null || datesToBatch.size() < 2) {
if (datesToBatch != null) {
BatchInfoPopulationHelperServiceImpl.log.info("There is only one 'batch'");
}
// we still put the processing dates in, below.
} else {
ef = this.makeFactorForBatch(ee);
for (String batchId : datesToBatch.keySet()) {
FactorValue fv = FactorValue.Factory.newInstance();
fv.setIsBaseline(false);
/* we could set true for the first batch, but nobody cares. */
fv.setValue(batchId);
Collection<Characteristic> chars = new HashSet<>();
VocabCharacteristic c = VocabCharacteristic.Factory.newInstance();
c.setCategory(ExperimentalDesignUtils.BATCH_FACTOR_CATEGORY_NAME);
c.setValue(batchId);
c.setCategoryUri(ExperimentalDesignUtils.BATCH_FACTOR_CATEGORY_URI);
c.setEvidenceCode(GOEvidenceCode.IIA);
chars.add(c);
fv.setCharacteristics(chars);
fv.setExperimentalFactor(ef);
/*
* persist
*/
fv.setCharacteristics(chars);
experimentService.addFactorValue(ee, fv);
for (Date d : datesToBatch.get(batchId)) {
d2fv.put(d, fv);
}
}
}
bioMaterialService.associateBatchFactor(dates, d2fv);
return ef;
}
use of ubic.gemma.model.common.description.Characteristic in project Gemma by PavlidisLab.
the class BatchInfoPopulationServiceImpl method isBatchFactor.
/**
* @param ef ef
* @return true if the factor seems to be a 'batch' factor.
*/
public static boolean isBatchFactor(ExperimentalFactor ef) {
Characteristic c = ef.getCategory();
boolean isBatchFactor = false;
boolean looksLikeBatch = ef.getName().equals(ExperimentalDesignUtils.BATCH_FACTOR_NAME);
if (c != null && c instanceof VocabCharacteristic) {
VocabCharacteristic v = (VocabCharacteristic) c;
if (v.getCategory() != null && v.getCategory().equals(ExperimentalDesignUtils.BATCH_FACTOR_CATEGORY_NAME)) {
isBatchFactor = true;
}
} else if (looksLikeBatch) {
isBatchFactor = true;
}
return isBatchFactor;
}
use of ubic.gemma.model.common.description.Characteristic in project Gemma by PavlidisLab.
the class DatabaseViewGeneratorImpl method generateDatasetTissueView.
private void generateDatasetTissueView(Integer limit, Collection<ExpressionExperiment> experiments) throws IOException {
DatabaseViewGeneratorImpl.log.info("Generating dataset tissue view");
/*
* Get handle to output file
*/
File file = this.getViewFile(DatabaseViewGeneratorImpl.DATASET_TISSUE_VIEW_BASENAME);
DatabaseViewGeneratorImpl.log.info("Writing to " + file);
try (Writer writer = new OutputStreamWriter(new GZIPOutputStream(new FileOutputStream(file)))) {
/*
* For all of their annotations... if it's a tissue, print out a line
*/
writer.write("GemmaDsId\tTerm\tTermURI\n");
int i = 0;
for (ExpressionExperiment ee : experiments) {
ee = expressionExperimentService.thawLite(ee);
DatabaseViewGeneratorImpl.log.info("Processing: " + ee.getShortName());
Long gemmaId = ee.getId();
for (Characteristic c : ee.getCharacteristics()) {
if (StringUtils.isBlank(c.getValue())) {
continue;
}
if (c.getCategory().equals("OrganismPart")) {
// or tissue? check URI
String uri = "";
if (c instanceof VocabCharacteristic) {
VocabCharacteristic vocabCharacteristic = (VocabCharacteristic) c;
if (StringUtils.isNotBlank(vocabCharacteristic.getValueUri()))
uri = vocabCharacteristic.getValueUri();
}
writer.write(String.format("%d\t%s\t%s\n", gemmaId, c.getValue(), uri));
}
}
if (limit != null && (limit > 0 && ++i > limit))
break;
}
}
}
use of ubic.gemma.model.common.description.Characteristic in project Gemma by PavlidisLab.
the class SearchServiceTest method setup.
public void setup() throws Exception {
try (InputStream is = this.getClass().getResourceAsStream("/data/loader/ontology/fma.test.owl")) {
assert is != null;
ontologyService.getFmaOntologyService().loadTermsInNameSpace(is);
}
ee = this.getTestPersistentBasicExpressionExperiment();
VocabCharacteristic eeCharSpinalCord = VocabCharacteristic.Factory.newInstance();
eeCharSpinalCord.setCategory(SearchServiceTest.SPINAL_CORD);
eeCharSpinalCord.setCategoryUri(SearchServiceTest.SPINAL_CORD);
eeCharSpinalCord.setValue(SearchServiceTest.SPINAL_CORD);
eeCharSpinalCord.setValueUri(SearchServiceTest.SPINAL_CORD);
characteristicService.create(eeCharSpinalCord);
VocabCharacteristic eeCharGeneURI = VocabCharacteristic.Factory.newInstance();
eeCharGeneURI.setCategory(SearchServiceTest.GENE_URI);
eeCharGeneURI.setCategoryUri(SearchServiceTest.GENE_URI);
eeCharGeneURI.setValue(SearchServiceTest.GENE_URI);
eeCharGeneURI.setValueUri(SearchServiceTest.GENE_URI);
characteristicService.create(eeCharGeneURI);
VocabCharacteristic eeCharCortexURI = VocabCharacteristic.Factory.newInstance();
eeCharCortexURI.setCategory(SearchServiceTest.BRAIN_CAVITY);
eeCharCortexURI.setCategoryUri(SearchServiceTest.BRAIN_CAVITY);
eeCharCortexURI.setValue(SearchServiceTest.BRAIN_CAVITY);
eeCharCortexURI.setValueUri(SearchServiceTest.BRAIN_CAVITY);
characteristicService.create(eeCharCortexURI);
Collection<Characteristic> chars = new HashSet<>();
chars.add(eeCharSpinalCord);
chars.add(eeCharGeneURI);
chars.add(eeCharCortexURI);
ee.setCharacteristics(chars);
eeService.update(ee);
gene = this.getTestPersistentGene();
this.geneNcbiId = RandomStringUtils.randomNumeric(8);
gene.setNcbiGeneId(new Integer(geneNcbiId));
geneService.update(gene);
thePastUserQuery = UserQuery.Factory.newInstance();
Calendar calendar = Calendar.getInstance();
// the past
calendar.set(Calendar.YEAR, 1979);
calendar.set(Calendar.MONTH, 1);
calendar.set(Calendar.DAY_OF_MONTH, 1);
thePastUserQuery.setLastUsed(calendar.getTime());
SearchSettings settings = SearchSettings.Factory.newInstance();
settings.noSearches();
// should hit 'cavity of brain'.
settings.setQuery("Brain");
settings.setSearchExperiments(true);
settings.setUseCharacteristics(true);
settings.setUseIndices(false);
settings.setUseDatabase(false);
thePastUserQuery.setSearchSettings(settings);
thePastUserQuery.setUrl("someUrl");
// the future
calendar.add(Calendar.YEAR, 2000);
theFutureUserQuery = UserQuery.Factory.newInstance();
theFutureUserQuery.setLastUsed(calendar.getTime());
SearchSettings futureSettings = SearchSettings.Factory.newInstance();
futureSettings.noSearches();
// should hit 'cavity of brain'.
futureSettings.setQuery("Brain");
futureSettings.setSearchExperiments(true);
futureSettings.setUseCharacteristics(true);
theFutureUserQuery.setSearchSettings(futureSettings);
theFutureUserQuery.setUrl("someUrl");
// save to db to load later to test if the pipes are clean
userQueryService.create(thePastUserQuery);
userQueryService.create(theFutureUserQuery);
}
use of ubic.gemma.model.common.description.Characteristic in project Gemma by PavlidisLab.
the class CharacteristicUpdateTaskImpl method doRemove.
private TaskResult doRemove() {
Collection<AnnotationValueObject> chars = taskCommand.getAnnotationValueObjects();
log.info("Delete " + chars.size() + " characteristics...");
Collection<Characteristic> asChars = convertToCharacteristic(chars);
if (asChars.size() == 0) {
log.info("No characteristic objects were received");
return new TaskResult(taskCommand, false);
}
Map<Characteristic, Object> charToParent = characteristicService.getParents(asChars);
for (Characteristic cFromClient : asChars) {
Characteristic cFromDatabase = characteristicService.load(cFromClient.getId());
Object parent = charToParent.get(cFromDatabase);
removeFromParent(cFromDatabase, parent);
characteristicService.remove(cFromDatabase);
log.info("Characteristic deleted: " + cFromDatabase + " (associated with " + parent + ")");
}
return new TaskResult(taskCommand, true);
}
Aggregations