Search in sources :

Example 36 with Association

use of uk.ac.ebi.spot.goci.model.Association in project goci by EBISPOT.

the class AssociationDownloadService method extractGeneticData.

private void extractGeneticData(Association association, StringBuilder line) {
    final StringBuilder strongestAllele = new StringBuilder();
    final StringBuilder reportedGenes = new StringBuilder();
    final StringBuilder rsId = new StringBuilder();
    final StringBuilder proxySnpsRsIds = new StringBuilder();
    final StringBuilder riskAlleleFrequency = new StringBuilder();
    // Set our delimiter for download spreadsheet
    final String delimiter;
    if (association.getSnpInteraction() != null && association.getSnpInteraction()) {
        delimiter = " x ";
    } else {
        delimiter = "; ";
    }
    // Interaction specific values
    if (association.getSnpInteraction() != null && association.getSnpInteraction()) {
        association.getLoci().forEach(locus -> {
            Collection<RiskAllele> ra = locus.getStrongestRiskAlleles().stream().sorted((v1, v2) -> Long.compare(v1.getId(), v2.getId())).collect(Collectors.toList());
            ra.forEach(riskAllele -> {
                if (riskAllele.getRiskFrequency() != null && !riskAllele.getRiskFrequency().isEmpty()) {
                    String frequency = riskAllele.getRiskFrequency();
                    setOrAppend(riskAlleleFrequency, frequency, delimiter);
                } else {
                    setOrAppend(riskAlleleFrequency, "NR", delimiter);
                }
            });
            Collection<String> currentLocusGenes = new ArrayList<>();
            String commaSeparatedGenes = "";
            locus.getAuthorReportedGenes().forEach(gene -> {
                currentLocusGenes.add(gene.getGeneName().trim());
            });
            if (!currentLocusGenes.isEmpty()) {
                commaSeparatedGenes = String.join(", ", currentLocusGenes);
                setOrAppend(reportedGenes, commaSeparatedGenes, delimiter);
            } else {
                setOrAppend(reportedGenes, "NR", delimiter);
            }
        });
    } else {
        // Single study or a haplotype
        association.getLoci().forEach(locus -> {
            Collection<RiskAllele> ra = locus.getStrongestRiskAlleles().stream().sorted((v1, v2) -> Long.compare(v1.getId(), v2.getId())).collect(Collectors.toList());
            ra.forEach(riskAllele -> {
                setOrAppend(riskAlleleFrequency, "", "");
            });
            locus.getAuthorReportedGenes().forEach(gene -> {
                setOrAppend(reportedGenes, gene.getGeneName().trim(), ", ");
            });
        });
    }
    // Set attributes common to all associations
    association.getLoci().forEach(locus -> {
        Collection<RiskAllele> ra = locus.getStrongestRiskAlleles().stream().sorted((v1, v2) -> Long.compare(v1.getId(), v2.getId())).collect(Collectors.toList());
        ra.forEach(riskAllele -> {
            setOrAppend(strongestAllele, riskAllele.getRiskAlleleName(), delimiter);
            SingleNucleotidePolymorphism snp = riskAllele.getSnp();
            setOrAppend(rsId, snp.getRsId(), delimiter);
            Collection<String> currentLocusProxies = new ArrayList<>();
            String colonSeparatedProxies = "";
            if (riskAllele.getProxySnps() != null) {
                for (SingleNucleotidePolymorphism proxySnp : riskAllele.getProxySnps()) {
                    currentLocusProxies.add(proxySnp.getRsId());
                }
            }
            if (!currentLocusProxies.isEmpty()) {
                colonSeparatedProxies = String.join(", ", currentLocusProxies);
                setOrAppend(proxySnpsRsIds, colonSeparatedProxies, delimiter);
            } else {
                setOrAppend(proxySnpsRsIds, "NR", delimiter);
            }
        });
    });
    line.append(reportedGenes.toString());
    line.append("\t");
    line.append(strongestAllele.toString());
    line.append("\t");
    line.append(rsId.toString());
    line.append("\t");
    line.append(proxySnpsRsIds.toString());
    line.append("\t");
    line.append(riskAlleleFrequency.toString());
    line.append("\t");
}
Also used : RiskAllele(uk.ac.ebi.spot.goci.model.RiskAllele) OutputStream(java.io.OutputStream) Service(org.springframework.stereotype.Service) EfoTrait(uk.ac.ebi.spot.goci.model.EfoTrait) Association(uk.ac.ebi.spot.goci.model.Association) Collection(java.util.Collection) Autowired(org.springframework.beans.factory.annotation.Autowired) IOException(java.io.IOException) SingleNucleotidePolymorphism(uk.ac.ebi.spot.goci.model.SingleNucleotidePolymorphism) Collectors(java.util.stream.Collectors) ArrayList(java.util.ArrayList) RiskAllele(uk.ac.ebi.spot.goci.model.RiskAllele) ArrayList(java.util.ArrayList) SingleNucleotidePolymorphism(uk.ac.ebi.spot.goci.model.SingleNucleotidePolymorphism)

Example 37 with Association

use of uk.ac.ebi.spot.goci.model.Association in project goci by EBISPOT.

the class AssociationEventsViewService method createViews.

@Override
public List<EventView> createViews(Long studyId) {
    List<EventView> views = new ArrayList<>();
    Collection<Association> associations = studyRepository.findOne(studyId).getAssociations();
    if (!associations.isEmpty()) {
        // For each association gather up the events into a collection of views
        associations.forEach(association -> {
            Collection<Event> events = association.getEvents();
            Long associationId = association.getId();
            Collection<SingleNucleotidePolymorphism> snps = singleNucleotidePolymorphismRepository.findByRiskAllelesLociAssociationId(associationId);
            String associationSummary;
            StringJoiner snpJoiner = new StringJoiner(", ");
            snps.forEach(singleNucleotidePolymorphism -> {
                snpJoiner.add(singleNucleotidePolymorphism.getRsId());
            });
            associationSummary = snpJoiner.toString();
            events.forEach(event -> {
                String eventName = eventTypeService.translateEventByEventType(event.getEventType());
                EventView eventView = new AssociationEventView(eventName, event.getEventDate(), associationId, event.getUser().getEmail(), associationSummary);
                views.add(eventView);
            });
        });
    }
    return views;
}
Also used : ArrayList(java.util.ArrayList) AssociationEventView(uk.ac.ebi.spot.goci.curation.model.AssociationEventView) EventView(uk.ac.ebi.spot.goci.curation.model.EventView) Association(uk.ac.ebi.spot.goci.model.Association) AssociationEventView(uk.ac.ebi.spot.goci.curation.model.AssociationEventView) SingleNucleotidePolymorphism(uk.ac.ebi.spot.goci.model.SingleNucleotidePolymorphism) Event(uk.ac.ebi.spot.goci.model.Event) StringJoiner(java.util.StringJoiner)

Example 38 with Association

use of uk.ac.ebi.spot.goci.model.Association in project goci by EBISPOT.

the class StudyOperationsService method assignStudyStatus.

/**
     * Assign status to a study
     */
public String assignStudyStatus(Study study, StatusAssignment statusAssignment, SecureUser userFromRequest) {
    CurationStatus newStatus = curationStatusRepository.findOne(statusAssignment.getStatusId());
    CurationStatus currentStudyStatus = study.getHousekeeping().getCurationStatus();
    String message = null;
    // If the current and new status are different
    if (newStatus != null && newStatus != currentStudyStatus) {
        // Get housekeeping object and assign new status
        Housekeeping housekeeping = study.getHousekeeping();
        if (newStatus.getStatus().equals("Publish study")) {
            // Run pre-publish checks first
            Collection<Association> associations = associationRepository.findByStudyId(study.getId());
            message = publishStudyCheckService.runChecks(study, associations);
            // if checks pass then update the status and save objects
            if (message == null) {
                housekeeping.setCurationStatus(newStatus);
                updateStatus(study, housekeeping, userFromRequest);
            }
        } else {
            housekeeping.setCurationStatus(newStatus);
            updateStatus(study, housekeeping, userFromRequest);
        }
    } else {
        message = "Current status and new status are the same, no change required";
    }
    return message;
}
Also used : Housekeeping(uk.ac.ebi.spot.goci.model.Housekeeping) Association(uk.ac.ebi.spot.goci.model.Association) CurationStatus(uk.ac.ebi.spot.goci.model.CurationStatus)

Aggregations

Association (uk.ac.ebi.spot.goci.model.Association)38 ArrayList (java.util.ArrayList)14 SingleNucleotidePolymorphism (uk.ac.ebi.spot.goci.model.SingleNucleotidePolymorphism)10 RiskAllele (uk.ac.ebi.spot.goci.model.RiskAllele)9 Study (uk.ac.ebi.spot.goci.model.Study)7 Test (org.junit.Test)6 Gene (uk.ac.ebi.spot.goci.model.Gene)6 SimpleDateFormat (java.text.SimpleDateFormat)5 EnsemblMappingException (uk.ac.ebi.spot.goci.exception.EnsemblMappingException)5 Locus (uk.ac.ebi.spot.goci.model.Locus)5 EfoTrait (uk.ac.ebi.spot.goci.model.EfoTrait)4 Filter (uk.ac.ebi.spot.goci.pussycat.lang.Filter)4 Collection (java.util.Collection)3 Autowired (org.springframework.beans.factory.annotation.Autowired)3 Service (org.springframework.stereotype.Service)3 IOException (java.io.IOException)2 URI (java.net.URI)2 DateFormat (java.text.DateFormat)2 ParseException (java.text.ParseException)2 Date (java.util.Date)2