use of uk.ac.ebi.spot.goci.model.Study in project goci by EBISPOT.
the class DefaultGWASOWLPublisher method filterAndPublishGWASData.
private OWLOntology filterAndPublishGWASData(OWLOntology conversion, Collection<Study> studies) throws OWLConversionException {
//TODO : check with tony : Discard studies which are not yet associated with a trait.
//Discard studies which are not associated with a disease trait and those which haven't been published yet
//by the GWAS catalog.
// Iterator<Study> iterator = studies.iterator();
// while(iterator.hasNext()){
// Study study = iterator.next();
// if(study.getDiseaseTrait() == null) {
// iterator.remove();
// }
// else if( study.getHousekeeping().getCatalogPublishDate() == null) {
// iterator.remove();
// }
// else if(study.getHousekeeping().getCatalogUnpublishDate() != null){
// iterator.remove();
// }
// }
Collection<Study> filteredStudies = new ArrayList<Study>();
Collection<Association> filteredTraitAssociations = new ArrayList<Association>();
Collection<SingleNucleotidePolymorphism> filteredSNPs = new ArrayList<SingleNucleotidePolymorphism>();
int count = 0;
int studyLimit = getStudiesLimit() == -1 ? Integer.MAX_VALUE : getStudiesLimit();
Iterator<Study> studyIterator = studies.iterator();
while (count < studyLimit && studyIterator.hasNext()) {
Study nextStudy = studyIterator.next();
//only process a study if no date filter has been provided or if the study's publication date is smaller than the filter date
if (FilterProperties.getDateFilter() == null || nextStudy.getPublicationDate().before(FilterProperties.getDateFilter())) {
System.out.println("Qualifying study");
for (Association nextTA : nextStudy.getAssociations()) {
float filter = 0;
float pval = 0;
if (FilterProperties.getPvalueFilter() != null) {
filter = (float) (FilterProperties.getPvalueMant() * Math.pow(10, FilterProperties.getPvalueExp()));
pval = (float) (nextTA.getPvalueMantissa() * Math.pow(10, nextTA.getPvalueExponent()));
System.out.println("Your comparators are " + filter + " and " + pval);
}
if (FilterProperties.getPvalueFilter() == null || pval < filter) {
System.out.println("Qualifying association");
filteredTraitAssociations.add(nextTA);
for (Locus locus : nextTA.getLoci()) {
for (RiskAllele riskAllele : locus.getStrongestRiskAlleles()) {
filteredSNPs.add(riskAllele.getSnp());
}
}
}
}
filteredStudies.add(nextStudy);
count++;
}
}
// convert this data, starting with SNPs (no dependencies) and working up to studies
getLog().debug("Starting conversion to OWL...");
getLog().debug("Converting " + filteredSNPs.size() + " filtered SNPs...");
getConverter().addSNPsToOntology(filteredSNPs, conversion);
getLog().debug("Converting " + filteredTraitAssociations.size() + " filtered Trait Associations...");
getConverter().addAssociationsToOntology(filteredTraitAssociations, conversion);
getLog().debug("Converting " + filteredStudies.size() + " filtered Studies...");
getConverter().addStudiesToOntology(filteredStudies, conversion);
getLog().debug("All conversion done!");
return conversion;
}
use of uk.ac.ebi.spot.goci.model.Study in project goci by EBISPOT.
the class PussycatGOCIController method setDateFilter.
private Filter setDateFilter(String dateMin, String dateMax) {
Filter dateFilter;
DateFormat df_input = new SimpleDateFormat("yyyy-MM-dd");
Date to, from;
try {
if (dateMax != null) {
int endYearVar = Integer.parseInt(dateMax.split("-")[0]);
int endMonthVar = Integer.parseInt(dateMax.split("-")[1]);
String end_month, end_year;
//API call provides date for "up to and including the end of" - must increment month for query
if (endMonthVar == 12) {
end_month = "01";
endYearVar++;
end_year = Integer.toString(endYearVar);
} else {
endMonthVar++;
if (endMonthVar > 9) {
end_month = Integer.toString(endMonthVar);
} else {
end_month = "0".concat(Integer.toString(endMonthVar));
}
end_year = Integer.toString(endYearVar);
}
to = df_input.parse(end_year + "-" + end_month + "-01");
} else {
//change to use today's date
to = df_input.parse(df_input.format(new Date()));
}
if (dateMin != null) {
from = df_input.parse(dateMin + "-01");
} else {
from = df_input.parse("2005-01-01");
}
Calendar fromValue = Calendar.getInstance();
fromValue.setTime(from);
Calendar toValue = Calendar.getInstance();
toValue.setTime(to);
Study study = template(Study.class);
dateFilter = refine(study).on(study.getPublicationDate()).hasRange(fromValue, toValue);
} catch (ParseException e) {
getLog().error("Bad date in URL for date range '" + dateMin + "' to '" + dateMax, e);
throw new RuntimeException("Bad date in URL for date range '" + dateMin + "' to '" + dateMax, e);
}
return dateFilter;
}
use of uk.ac.ebi.spot.goci.model.Study in project goci by EBISPOT.
the class AssociationService method loadAssociatedData.
public void loadAssociatedData(Association association) {
int traitCount = association.getEfoTraits().size();
Study study = studyService.fetchOne(association.getStudy());
AtomicInteger reportedGeneCount = new AtomicInteger();
Collection<SingleNucleotidePolymorphism> snps = new HashSet<>();
Collection<Region> regions = new HashSet<>();
Collection<Gene> mappedGenes = new HashSet<>();
Map<String, Set<String>> mappedGeneEntrezIds = new HashMap<>();
Map<String, Set<String>> mappedGeneEnsemblIds = new HashMap<>();
association.getLoci().forEach(locus -> {
locus.getStrongestRiskAlleles().stream().map(RiskAllele::getSnp).forEach(snp -> {
Collection<Location> snpLocations = snp.getLocations();
for (Location location : snpLocations) {
regions.add(location.getRegion());
}
snp.getGenomicContexts().forEach(context -> {
mappedGenes.add(context.getGene());
String geneName = context.getGene().getGeneName();
Collection<EntrezGene> geneEntrezGeneIds = context.getGene().getEntrezGeneIds();
Collection<EnsemblGene> geneEnsemblGeneIds = context.getGene().getEnsemblGeneIds();
if (mappedGeneEntrezIds.containsKey(geneName)) {
for (EntrezGene entrezGene : geneEntrezGeneIds) {
mappedGeneEntrezIds.get(geneName).add(entrezGene.getEntrezGeneId());
}
} else {
Set<String> entrezIds = new HashSet<>();
for (EntrezGene entrezGene : geneEntrezGeneIds) {
entrezIds.add(entrezGene.getEntrezGeneId());
}
mappedGeneEntrezIds.put(geneName, entrezIds);
}
if (mappedGeneEnsemblIds.containsKey(geneName)) {
for (EnsemblGene ensemblGene : geneEnsemblGeneIds) {
mappedGeneEnsemblIds.get(geneName).add(ensemblGene.getEnsemblGeneId());
}
} else {
Set<String> ensemblIds = new HashSet<>();
for (EnsemblGene ensemblGene : geneEnsemblGeneIds) {
ensemblIds.add(ensemblGene.getEnsemblGeneId());
}
mappedGeneEntrezIds.put(geneName, ensemblIds);
}
});
snps.add(snp);
});
snps.addAll(locus.getStrongestRiskAlleles().stream().map(RiskAllele::getSnp).collect(Collectors.toList()));
reportedGeneCount.addAndGet(locus.getAuthorReportedGenes().size());
locus.getAuthorReportedGenes().forEach(authorReportedGene -> {
authorReportedGene.getEnsemblGeneIds().size();
authorReportedGene.getEntrezGeneIds().size();
});
});
getLog().trace("Association '" + association.getId() + "' is mapped to " + "" + traitCount + " EFO traits where study id = " + study.getId() + " " + "(author reported " + reportedGeneCount + " gene(s)); " + "this reports on " + snps.size() + " SNPs in " + regions.size() + " regions, " + "mapped to " + mappedGenes.size() + " genes.");
}
use of uk.ac.ebi.spot.goci.model.Study in project goci by EBISPOT.
the class AssociationUploadService method upload.
public List<AssociationUploadErrorView> upload(MultipartFile file, Study study, SecureUser user) throws IOException, EnsemblMappingException {
// File errors will contain any validation errors and be returned to controller if any are found
List<AssociationUploadErrorView> fileErrors = new ArrayList<>();
String originalFilename = file.getOriginalFilename();
getLog().info("Uploading file: ".concat(originalFilename));
// Upload file
try {
uploadFile(file, study.getId());
// Send file, including path, to SNP batch loader process
File uploadedFile = studyFileService.getFileFromFileName(study.getId(), originalFilename);
ValidationSummary validationSummary = associationFileUploadService.processAndValidateAssociationFile(uploadedFile, "full");
if (validationSummary != null) {
// Check if we have any row errors
long rowErrorCount = validationSummary.getRowValidationSummaries().parallelStream().filter(rowValidationSummary -> !rowValidationSummary.getErrors().isEmpty()).count();
// Errors found
if (rowErrorCount > 0) {
studyFileService.deleteFile(study.getId(), originalFilename);
getLog().error("Row errors found in file: " + originalFilename);
validationSummary.getRowValidationSummaries().forEach(rowValidationSummary -> fileErrors.addAll(processRowError(rowValidationSummary)));
} else {
// Determine if we have any errors rather than warnings
// Errors prevent saving association
List<ValidationError> allAssociationsErrors = new ArrayList<>();
validationSummary.getAssociationSummaries().forEach(associationSummary -> allAssociationsErrors.addAll(associationSummary.getErrors()));
long associationErrorCount = allAssociationsErrors.parallelStream().filter(validationError -> !validationError.getWarning()).count();
if (associationErrorCount > 0) {
studyFileService.deleteFile(study.getId(), originalFilename);
getLog().error("Association errors found in file: " + originalFilename);
validationSummary.getAssociationSummaries().forEach(associationSummary -> fileErrors.addAll(processAssociationError(associationSummary)));
} else {
Integer numberOfAssociations = validationSummary.getAssociationSummaries().size();
String description = numberOfAssociations.toString().concat(" associations created from upload of '").concat(originalFilename).concat("'");
createBatchUploadEvent(study, description, user);
saveAssociations(validationSummary.getAssociationSummaries(), study, user);
}
}
}
return fileErrors;
} catch (IOException e) {
throw new IOException(e);
}
}
use of uk.ac.ebi.spot.goci.model.Study in project goci by EBISPOT.
the class StudyOperationsService method unpublishStudy.
/**
* Unpublish a study entry in the database
*
* @param studyId ID of study to unpublish
* @param unpublishReason Reason the study is being unpublished
* @param user User performing request
*/
public void unpublishStudy(Long studyId, UnpublishReason unpublishReason, SecureUser user) {
Study study = studyRepository.findOne(studyId);
// Before we unpublish the study get its associated housekeeping
Long housekeepingId = study.getHousekeeping().getId();
Housekeeping housekeepingAttachedToStudy = housekeepingRepository.findOne(housekeepingId);
//Set the unpublishDate and a new lastUpdateDate in houskeeping
java.util.Date unpublishDate = new java.util.Date();
housekeepingAttachedToStudy.setCatalogUnpublishDate(unpublishDate);
housekeepingAttachedToStudy.setLastUpdateDate(unpublishDate);
//Set the reason for unpublishing
housekeepingAttachedToStudy.setUnpublishReason(unpublishReason);
housekeepingAttachedToStudy.setIsPublished(false);
//Set the unpublised status in housekeeping
CurationStatus status = curationStatusRepository.findByStatus("Unpublished from catalog");
housekeepingAttachedToStudy.setCurationStatus(status);
updateStatus(study, housekeepingAttachedToStudy, user);
}
Aggregations