Search in sources :

Example 1 with StudySampleDescription

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

the class StudySampleDesciptionsController method getStudiesSampleDescriptions.

@RequestMapping(produces = MediaType.TEXT_HTML_VALUE, method = RequestMethod.GET)
public void getStudiesSampleDescriptions(HttpServletResponse response) {
    Collection<StudySampleDescription> studySampleDescriptions = studySampleDescriptionsDownloadService.generateStudySampleDescriptions();
    // Create date stamped tsv download file
    DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
    Date date = new Date();
    String now = dateFormat.format(date);
    String fileName = "GWASAncestry".concat("-").concat(now).concat(".tsv");
    response.setContentType("text/tsv");
    response.setHeader("Content-Disposition", "attachement; filename=" + fileName);
    try {
        studySampleDescriptionsDownloadService.createDownloadFile(response.getOutputStream(), studySampleDescriptions);
    } catch (IOException e) {
        getLog().error("Cannot create ancestry download file");
        e.printStackTrace();
    }
}
Also used : StudySampleDescription(uk.ac.ebi.spot.goci.curation.model.StudySampleDescription) SimpleDateFormat(java.text.SimpleDateFormat) DateFormat(java.text.DateFormat) IOException(java.io.IOException) SimpleDateFormat(java.text.SimpleDateFormat) Date(java.util.Date) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 2 with StudySampleDescription

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

the class StudySampleDescriptionsDownloadService method processStudySampleDescriptions.

private String processStudySampleDescriptions(Collection<StudySampleDescription> studySampleDescriptions) {
    String header = "Study ID\tAuthor\tPublication Date\tPubmed ID\tInitial Sample Description\tReplication Sample Description\tType\tNumber of Individuals\tAncestral Group\tCountry of Origin\tCountry of Recruitment\tAdditional Description\tSample Sizes Match\tAncestralty Checked Level One\tAncestralty Checked Level Two\tNotes\n";
    StringBuilder output = new StringBuilder();
    output.append(header);
    for (StudySampleDescription studySampleDescription : studySampleDescriptions) {
        StringBuilder line = new StringBuilder();
        // Study ID
        if (studySampleDescription.getStudyId() == null) {
            line.append("");
        } else {
            line.append(studySampleDescription.getStudyId());
        }
        line.append("\t");
        // Author
        if (studySampleDescription.getAuthor() == null) {
            line.append("");
        } else {
            line.append(studySampleDescription.getAuthor());
        }
        line.append("\t");
        // Publication Date
        if (studySampleDescription.getPublicationDate() == null) {
            line.append("");
        } else {
            DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
            String studyDate = dateFormat.format(studySampleDescription.getPublicationDate());
            line.append(studyDate);
        }
        line.append("\t");
        // Pubmed ID
        if (studySampleDescription.getPubmedId() == null) {
            line.append("");
        } else {
            line.append(studySampleDescription.getPubmedId());
        }
        line.append("\t");
        // Initial sample size
        String initialSampleSize = studySampleDescription.getInitialSampleSize();
        if (initialSampleSize == null) {
            line.append("");
        } else {
            line.append(tidyStringForOutput(initialSampleSize));
        }
        line.append("\t");
        // Replicate sample size
        String replicateSampleSize = studySampleDescription.getReplicateSampleSize();
        if (replicateSampleSize == null) {
            line.append("");
        } else {
            line.append(tidyStringForOutput(replicateSampleSize));
        }
        line.append("\t");
        // Type
        if (studySampleDescription.getType() == null) {
            line.append("");
        } else {
            line.append(studySampleDescription.getType());
        }
        line.append("\t");
        // Number of individuals
        if (studySampleDescription.getNumberOfIndividuals() == null) {
            line.append("");
        } else {
            line.append(studySampleDescription.getNumberOfIndividuals());
        }
        line.append("\t");
        // Ancestral group
        Collection<AncestralGroup> ancestralGroups = studySampleDescription.getAncestralGroups();
        if (ancestralGroups == null) {
            line.append("");
        } else {
            line.append(createAncestralGroupString(ancestralGroups));
        }
        line.append("\t");
        // Origin
        Collection<Country> countryOfOrigin = studySampleDescription.getCountryOfOrigin();
        if (countryOfOrigin == null) {
            line.append("");
        } else {
            line.append(createCountryString(countryOfOrigin));
        }
        line.append("\t");
        // Recruitment
        Collection<Country> countryOfRecruitment = studySampleDescription.getCountryOfRecruitment();
        if (countryOfRecruitment == null) {
            line.append("");
        } else {
            line.append(createCountryString(countryOfRecruitment));
        }
        line.append("\t");
        // Description , this requires some tidying
        String description = studySampleDescription.getDescription();
        if (description == null) {
            line.append("");
        } else {
            String newline = System.getProperty("line.separator");
            if (description.equals(newline)) {
                line.append("");
            } else {
                line.append(tidyStringForOutput(description));
            }
        }
        line.append("\t");
        // Sample size
        if (studySampleDescription.getSampleSizesMatch() == null) {
            line.append("");
        } else {
            line.append(studySampleDescription.getSampleSizesMatch());
        }
        line.append("\t");
        // Housekeeping information
        if (studySampleDescription.isAncestryCheckedLevelOne() == null) {
            line.append("");
        } else {
            if (studySampleDescription.isAncestryCheckedLevelOne()) {
                line.append("Y");
            } else {
                line.append("N");
            }
        }
        line.append("\t");
        if (studySampleDescription.isAncestryCheckedLevelTwo() == null) {
            line.append("");
        } else {
            if (studySampleDescription.isAncestryCheckedLevelTwo()) {
                line.append("Y");
            } else {
                line.append("N");
            }
        }
        line.append("\t");
        // Notes, this requires some tidying
        String notes = studySampleDescription.getNotes();
        if (notes == null) {
            line.append("");
        } else {
            line.append(tidyStringForOutput(notes));
        }
        // Add new line
        line.append("\n");
        output.append(line.toString());
    }
    return output.toString();
}
Also used : AncestralGroup(uk.ac.ebi.spot.goci.model.AncestralGroup) StudySampleDescription(uk.ac.ebi.spot.goci.curation.model.StudySampleDescription) SimpleDateFormat(java.text.SimpleDateFormat) DateFormat(java.text.DateFormat) Country(uk.ac.ebi.spot.goci.model.Country) SimpleDateFormat(java.text.SimpleDateFormat)

Example 3 with StudySampleDescription

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

the class StudySampleDescriptionsDownloadService method generateStudySampleDescriptions.

public Collection<StudySampleDescription> generateStudySampleDescriptions() {
    // Get all ancestries, this will also find all studies with ancestry information
    Collection<Ancestry> ancestries = ancestryRepository.findAll(sortByPublicationDateDesc());
    Collection<StudySampleDescription> studySampleDescriptions = new ArrayList<>();
    for (Ancestry ancestry : ancestries) {
        // Make sure ancestry has an attached study
        if (ancestry.getStudy() != null) {
            Study study = ancestry.getStudy();
            // Study attributes
            Long studyId = study.getId();
            String author = study.getAuthor();
            Date publicationDate = study.getPublicationDate();
            String pubmedId = study.getPubmedId();
            String initialSampleSize = study.getInitialSampleSize();
            String replicateSampleSize = study.getReplicateSampleSize();
            // Housekeeping attributes
            Boolean ancestryCheckedLevelOne = false;
            Boolean ancestryCheckedLevelTwo = false;
            if (study.getHousekeeping() != null) {
                ancestryCheckedLevelOne = study.getHousekeeping().getAncestryCheckedLevelOne();
                ancestryCheckedLevelTwo = study.getHousekeeping().getAncestryCheckedLevelTwo();
            }
            // Ancestry attributes
            String type = ancestry.getType();
            Integer numberOfIndividuals = ancestry.getNumberOfIndividuals();
            Collection<AncestralGroup> ancestralGroup = ancestry.getAncestralGroups();
            Collection<Country> countryOfOrigin = ancestry.getCountryOfOrigin();
            Collection<Country> countryOfRecruitment = ancestry.getCountryOfRecruitment();
            String sampleSizesMatch = ancestry.getSampleSizesMatch();
            String description = ancestry.getDescription();
            String notes = ancestry.getNotes();
            StudySampleDescription studySampleDescription = new StudySampleDescription(studyId, author, publicationDate, pubmedId, initialSampleSize, replicateSampleSize, ancestryCheckedLevelOne, ancestryCheckedLevelTwo, type, numberOfIndividuals, ancestralGroup, countryOfOrigin, countryOfRecruitment, description, sampleSizesMatch, notes);
            studySampleDescriptions.add(studySampleDescription);
        }
    }
    return studySampleDescriptions;
}
Also used : Study(uk.ac.ebi.spot.goci.model.Study) AncestralGroup(uk.ac.ebi.spot.goci.model.AncestralGroup) StudySampleDescription(uk.ac.ebi.spot.goci.curation.model.StudySampleDescription) ArrayList(java.util.ArrayList) Date(java.util.Date) Ancestry(uk.ac.ebi.spot.goci.model.Ancestry) Country(uk.ac.ebi.spot.goci.model.Country)

Aggregations

StudySampleDescription (uk.ac.ebi.spot.goci.curation.model.StudySampleDescription)3 DateFormat (java.text.DateFormat)2 SimpleDateFormat (java.text.SimpleDateFormat)2 Date (java.util.Date)2 AncestralGroup (uk.ac.ebi.spot.goci.model.AncestralGroup)2 Country (uk.ac.ebi.spot.goci.model.Country)2 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)1 Ancestry (uk.ac.ebi.spot.goci.model.Ancestry)1 Study (uk.ac.ebi.spot.goci.model.Study)1