Search in sources :

Example 6 with ChromosomeReport

use of org.nextprot.api.core.domain.ChromosomeReport in project nextprot-api by calipho-sib.

the class HPPChromosomeReportTSVWriter method write.

@Override
public void write(ChromosomeReport report) throws IOException {
    writer.write(extractHeaders().stream().collect(Collectors.joining("\t")));
    writer.write("\n");
    Map<String, EntryReport> groupedByAccession = report.getEntryReports().stream().collect(Collectors.toMap(EntryReport::getAccession, er -> er, // 1. keep one entry report for each entry accession
    (er1, er2) -> er1));
    List<String> sortedAccessions = new ArrayList<>(groupedByAccession.keySet()).stream().sorted().collect(Collectors.toList());
    for (String accession : sortedAccessions) {
        EntryReport er = groupedByAccession.get(accession);
        writer.write(extractValues(er, overviewService.findOverviewByEntry(er.getAccession())).stream().collect(Collectors.joining("\t")));
        writer.write("\n");
    }
    writer.close();
}
Also used : OutputStream(java.io.OutputStream) PrintWriter(java.io.PrintWriter) Arrays(java.util.Arrays) OverviewService(org.nextprot.api.core.service.OverviewService) IOException(java.io.IOException) ChromosomeReport(org.nextprot.api.core.domain.ChromosomeReport) Collectors(java.util.stream.Collectors) ArrayList(java.util.ArrayList) Overview(org.nextprot.api.core.domain.Overview) ProteinExistence(org.nextprot.api.core.domain.ProteinExistence) List(java.util.List) EntryReport(org.nextprot.api.core.domain.EntryReport) HPPChromosomeReportWriter(org.nextprot.api.core.service.export.HPPChromosomeReportWriter) Map(java.util.Map) EntityName(org.nextprot.api.core.domain.EntityName) EntryReport(org.nextprot.api.core.domain.EntryReport)

Example 7 with ChromosomeReport

use of org.nextprot.api.core.domain.ChromosomeReport in project nextprot-api by calipho-sib.

the class ChromosomeReportServiceImpl method reportChromosome.

@Cacheable("chromosome-reports")
@Override
public ChromosomeReport reportChromosome(String chromosome) {
    // TODO: if chromosome is not found throw an http error 404
    if (!Chromosome.exists(chromosome)) {
        throw new ChromosomeNotFoundException(chromosome);
    }
    ChromosomeReport report = new ChromosomeReport();
    report.setDataRelease(releaseInfoService.findReleaseVersions().getDatabaseRelease());
    List<String> allEntriesOnChromosome = masterIdentifierService.findUniqueNamesOfChromosome(chromosome);
    List<EntryReport> entryReports = allEntriesOnChromosome.stream().map(entryAccession -> entryGeneReportService.reportEntry(entryAccession)).flatMap(Collection::stream).filter(er -> er.getChromosome().equals(chromosome)).sorted(EntryReport.newByChromosomalPositionComparator()).collect(Collectors.toList());
    report.setEntryReports(entryReports);
    ChromosomeReport.Summary summary = newSummary(chromosome, entryReports);
    setByProteinEvidenceEntryCount(allEntriesOnChromosome, summary);
    report.setSummary(summary);
    return report;
}
Also used : ChromosomeNotFoundException(org.nextprot.api.commons.exception.ChromosomeNotFoundException) EntryReport(org.nextprot.api.core.domain.EntryReport) ChromosomeReport(org.nextprot.api.core.domain.ChromosomeReport) Cacheable(org.springframework.cache.annotation.Cacheable)

Example 8 with ChromosomeReport

use of org.nextprot.api.core.domain.ChromosomeReport in project nextprot-api by calipho-sib.

the class ChromosomeReportTXTReader method read.

@Override
public ChromosomeReport read(Reader reader) throws ParseException {
    ChromosomeReport report = new ChromosomeReport();
    ChromosomeReport.Summary summary = new ChromosomeReport.Summary();
    List<EntryReport> entryReports = new ArrayList<>();
    try {
        MatchConsumer matchConsumer = new MatchConsumer(reader);
        matchConsumer.consumeNextMatchOfThrowException("chromosome name", CHROMOSOME_NAME_PATTERN, (matcher -> summary.setChromosome(matcher.group(1))));
        matchConsumer.consumeNextMatchOfThrowException("release date", RELEASE_DATE_PATTERN, (matcher -> report.setDataRelease(matcher.group(1))));
        matchConsumer.consumeNextMatchOfThrowException("entry count", ENTRY_COUNT_PATTERN, (matcher -> summary.setEntryCount(Integer.parseInt(matcher.group(1)))));
        matchConsumer.consumeNextMatchOfThrowException("gene count", GENE_COUNT_PATTERN, (matcher -> summary.setEntryReportCount(Integer.parseInt(matcher.group(1)))));
        EntryReportConsumer entryReportConsumer = new EntryReportConsumer(summary, entryReports);
        boolean moreLinesToRead;
        do {
            moreLinesToRead = matchConsumer.consumeNextMatch(ENTRY_VALUES_PATTERN, entryReportConsumer);
        } while (moreLinesToRead);
        report.setSummary(summary);
        report.setEntryReports(entryReports);
        return report;
    } catch (IOException e) {
        throw new ParseException(e.getMessage(), -1);
    }
}
Also used : ChromosomeReportReader(org.nextprot.api.core.service.export.ChromosomeReportReader) NextProtException(org.nextprot.api.commons.exception.NextProtException) IOException(java.io.IOException) LineNumberReader(java.io.LineNumberReader) Reader(java.io.Reader) Logger(java.util.logging.Logger) ChromosomeReport(org.nextprot.api.core.domain.ChromosomeReport) ArrayList(java.util.ArrayList) Consumer(java.util.function.Consumer) ProteinExistence(org.nextprot.api.core.domain.ProteinExistence) List(java.util.List) Matcher(java.util.regex.Matcher) ChromosomalLocation(org.nextprot.api.core.domain.ChromosomalLocation) EntryReport(org.nextprot.api.core.domain.EntryReport) Pattern(java.util.regex.Pattern) ParseException(java.text.ParseException) EntryReport(org.nextprot.api.core.domain.EntryReport) ArrayList(java.util.ArrayList) IOException(java.io.IOException) ParseException(java.text.ParseException) ChromosomeReport(org.nextprot.api.core.domain.ChromosomeReport)

Example 9 with ChromosomeReport

use of org.nextprot.api.core.domain.ChromosomeReport in project nextprot-api by calipho-sib.

the class HPPChromosomeReportTXTWriter method write.

@Override
public void write(ChromosomeReport chromosomeReport) throws IOException {
    writer.write(String.format(buildHeaderFormat(), Arrays.asList("neXtProt AC", "Gene name(s)", "Protein existence", "Proteomics", "Antibody").toArray()));
    Map<String, EntryReport> groupedByAccession = chromosomeReport.getEntryReports().stream().collect(Collectors.toMap(EntryReport::getAccession, er -> er, // 1. keep one entry report for each entry accession
    (er1, er2) -> er1));
    List<String> sortedAccessions = new ArrayList<>(groupedByAccession.keySet()).stream().sorted().collect(Collectors.toList());
    for (String accession : sortedAccessions) {
        EntryReport er = groupedByAccession.get(accession);
        write(er, overviewService.findOverviewByEntry(er.getAccession()));
    }
    writer.close();
}
Also used : OutputStream(java.io.OutputStream) PrintWriter(java.io.PrintWriter) Arrays(java.util.Arrays) OverviewService(org.nextprot.api.core.service.OverviewService) IOException(java.io.IOException) ChromosomeReport(org.nextprot.api.core.domain.ChromosomeReport) Collectors(java.util.stream.Collectors) ArrayList(java.util.ArrayList) Overview(org.nextprot.api.core.domain.Overview) ProteinExistence(org.nextprot.api.core.domain.ProteinExistence) List(java.util.List) EntryReport(org.nextprot.api.core.domain.EntryReport) HPPChromosomeReportWriter(org.nextprot.api.core.service.export.HPPChromosomeReportWriter) Map(java.util.Map) EntityName(org.nextprot.api.core.domain.EntityName) EntryReport(org.nextprot.api.core.domain.EntryReport)

Aggregations

ChromosomeReport (org.nextprot.api.core.domain.ChromosomeReport)9 EntryReport (org.nextprot.api.core.domain.EntryReport)8 Test (org.junit.Test)5 HPPChromosomeReportWriter (org.nextprot.api.core.service.export.HPPChromosomeReportWriter)5 StringOutputStream (org.codehaus.plexus.util.StringOutputStream)4 EntryReportTest.newEntryReport (org.nextprot.api.core.domain.EntryReportTest.newEntryReport)4 IOException (java.io.IOException)3 ArrayList (java.util.ArrayList)3 List (java.util.List)3 ProteinExistence (org.nextprot.api.core.domain.ProteinExistence)3 CoreUnitBaseTest (org.nextprot.api.core.test.base.CoreUnitBaseTest)3 OutputStream (java.io.OutputStream)2 PrintWriter (java.io.PrintWriter)2 Arrays (java.util.Arrays)2 Map (java.util.Map)2 Collectors (java.util.stream.Collectors)2 EntityName (org.nextprot.api.core.domain.EntityName)2 Overview (org.nextprot.api.core.domain.Overview)2 OverviewService (org.nextprot.api.core.service.OverviewService)2 LineNumberReader (java.io.LineNumberReader)1