Search in sources :

Example 1 with DetectedLinkageFindings

use of org.dash.valid.report.DetectedLinkageFindings in project ImmunogeneticDataTools by nmdp-bioinformatics.

the class HLALinkageDisequilibrium method hasLinkageDisequilibrium.

public static Sample hasLinkageDisequilibrium(LinkageDisequilibriumGenotypeList glString) {
    Sample sample = new Sample(glString);
    Set<HaplotypePair> linkedPairs = new HaplotypePairSet(new HaplotypePairComparator());
    Set<String> notCommon = GLStringUtilities.checkCommonWellDocumented(glString.getGLString());
    Set<String> notCIWD = GLStringUtilities.checkCommonIntermediateWellDocumented(glString.getGLString());
    DetectedLinkageFindings findings = new DetectedLinkageFindings(System.getProperty(Frequencies.FREQUENCIES_PROPERTY));
    Set<Linkages> linkages = LinkagesLoader.getInstance().getLinkages();
    if (linkages == null) {
        sample.setFindings(findings);
        return sample;
    }
    for (Linkages linkage : linkages) {
        EnumSet<Locus> loci = linkage.getLoci();
        findings.addFindingSought(loci);
        List<DisequilibriumElement> disequilibriumElements = HLAFrequenciesLoader.getInstance().getDisequilibriumElements(loci);
        linkedPairs.addAll(findLinkedPairs(glString, loci, disequilibriumElements, findings));
    }
    LOGGER.info(linkedPairs.size() + " linkedPairs");
    findings.setGenotypeList(glString);
    findings.setLinkedPairs(linkedPairs);
    findings.setNonCWDAlleles(notCommon);
    findings.setNonCIWDAlleles(notCIWD);
    findings.setHladb(System.getProperty(GLStringConstants.HLADB_PROPERTY));
    sample.setFindings(findings);
    return sample;
}
Also used : HaplotypePair(org.dash.valid.gl.haplo.HaplotypePair) HaplotypePairSet(org.dash.valid.gl.haplo.HaplotypePairSet) DetectedDisequilibriumElement(org.dash.valid.report.DetectedDisequilibriumElement) DetectedLinkageFindings(org.dash.valid.report.DetectedLinkageFindings) HaplotypePairComparator(org.dash.valid.gl.haplo.HaplotypePairComparator)

Example 2 with DetectedLinkageFindings

use of org.dash.valid.report.DetectedLinkageFindings in project ImmunogeneticDataTools by nmdp-bioinformatics.

the class HLALinkageDisequilibrium method hasLinkageDisequilibrium.

public static Sample hasLinkageDisequilibrium(LinkageDisequilibriumGenotypeList glString, List<Haplotype> knownHaplotypes) {
    Set<HaplotypePair> linkedPairs = new HaplotypePairSet(new HaplotypePairComparator());
    Set<String> notCommon = GLStringUtilities.checkCommonWellDocumented(glString.getGLString());
    Set<String> notCIWD = GLStringUtilities.checkCommonIntermediateWellDocumented(glString.getGLString());
    Sample sample = new Sample(glString);
    DetectedLinkageFindings findings = new DetectedLinkageFindings(System.getProperty(Frequencies.FREQUENCIES_PROPERTY));
    Set<Linkages> linkages = LinkagesLoader.getInstance().getLinkages();
    if (linkages == null) {
        sample.setFindings(findings);
        return sample;
    }
    for (Linkages linkage : linkages) {
        EnumSet<Locus> loci = linkage.getLoci();
        findings.addFindingSought(loci);
        List<DisequilibriumElement> disequilibriumElements = HLAFrequenciesLoader.getInstance().getDisequilibriumElements(loci);
        List<Haplotype> enrichedHaplotypes = new ArrayList<Haplotype>();
        for (Haplotype haplotype : knownHaplotypes) {
            Haplotype enrichedHaplotype = enrichHaplotype(loci, disequilibriumElements, haplotype);
            if (enrichedHaplotype.getLinkage() != null) {
                findings.addLinkage(enrichedHaplotype.getLinkage());
                enrichedHaplotypes.add(enrichedHaplotype);
            }
        }
        if (enrichedHaplotypes.size() == 2) {
            linkedPairs.add(new HaplotypePair(enrichedHaplotypes.get(0), enrichedHaplotypes.get(1)));
        }
    }
    LOGGER.info(linkedPairs.size() + " linkedPairs");
    findings.setGenotypeList(glString);
    findings.setLinkedPairs(linkedPairs);
    findings.setNonCWDAlleles(notCommon);
    findings.setNonCIWDAlleles(notCIWD);
    findings.setHladb(System.getProperty(GLStringConstants.HLADB_PROPERTY));
    sample.setFindings(findings);
    return sample;
}
Also used : HaplotypePair(org.dash.valid.gl.haplo.HaplotypePair) HaplotypePairSet(org.dash.valid.gl.haplo.HaplotypePairSet) ArrayList(java.util.ArrayList) DetectedDisequilibriumElement(org.dash.valid.report.DetectedDisequilibriumElement) DetectedLinkageFindings(org.dash.valid.report.DetectedLinkageFindings) HaplotypePairComparator(org.dash.valid.gl.haplo.HaplotypePairComparator) Haplotype(org.dash.valid.gl.haplo.Haplotype) MultiLocusHaplotype(org.dash.valid.gl.haplo.MultiLocusHaplotype)

Example 3 with DetectedLinkageFindings

use of org.dash.valid.report.DetectedLinkageFindings in project ImmunogeneticDataTools by nmdp-bioinformatics.

the class ValidateLdGlstrings method read.

static ListMultimap<String, SubjectMug> read(final File file) throws IOException {
    BufferedReader reader = null;
    final ListMultimap<String, SubjectMug> subjectmugs = ArrayListMultimap.create();
    final SubjectMug.Builder builder = SubjectMug.builder();
    try {
        reader = reader(file);
        CharStreams.readLines(reader, new LineProcessor<Void>() {

            private int count = 0;

            @Override
            public boolean processLine(final String line) throws IOException {
                String[] tokens = line.split("\t");
                if (tokens.length < 2) {
                    throw new IOException("illegal format, expected at least 2 columns, found " + tokens.length + "\nline=" + line);
                }
                String fullyQualified = GLStringUtilities.fullyQualifyGLString(tokens[1]);
                MultilocusUnphasedGenotype mug = GLStringUtilities.convertToMug(fullyQualified);
                Sample sample = LinkageDisequilibriumAnalyzer.detectLinkages(mug);
                DetectedLinkageFindings findings = sample.getFindings();
                Float minimumDifference = findings.getMinimumDifference(Locus.FIVE_LOCUS);
                minimumDifference = minimumDifference == null ? 0 : minimumDifference;
                SubjectMug subjectMug = builder.reset().withSample(tokens[0]).withGlstring(tokens[1]).withMug(mug).withFindings(findings).withMinimumDifference(minimumDifference).build();
                subjectmugs.put(subjectMug.sample(), subjectMug);
                count++;
                return true;
            }

            @Override
            public Void getResult() {
                return null;
            }
        });
        return subjectmugs;
    } finally {
        try {
            reader.close();
        } catch (Exception e) {
        // ignore
        }
    }
}
Also used : Sample(org.dash.valid.Sample) MultilocusUnphasedGenotype(org.nmdp.gl.MultilocusUnphasedGenotype) IOException(java.io.IOException) IOException(java.io.IOException) CommandLineParseException(org.dishevelled.commandline.CommandLineParseException) DetectedLinkageFindings(org.dash.valid.report.DetectedLinkageFindings) BufferedReader(java.io.BufferedReader)

Example 4 with DetectedLinkageFindings

use of org.dash.valid.report.DetectedLinkageFindings in project ImmunogeneticDataTools by nmdp-bioinformatics.

the class LinkageDisequilibriumAnalyzer method analyzeGLStringFile.

/**
 * @param filename
 */
public static void analyzeGLStringFile(String filename) throws IOException {
    List<LinkageDisequilibriumGenotypeList> glStrings = GLStringUtilities.readGLStringFile(filename);
    List<Sample> samplesList = null;
    samplesList = detectLinkages(glStrings);
    for (Sample sample : samplesList) {
        DetectedLinkageFindings findings = sample.getFindings();
        LinkageDisequilibriumWriter.getInstance().reportDetectedLinkages(findings);
        HaplotypePairWriter.getInstance().reportDetectedLinkages(findings);
        CommonWellDocumentedWriter.getInstance().reportCommonWellDocumented(findings);
        DetectedFindingsWriter.getInstance().reportDetectedFindings(findings);
    }
    SamplesList allSamples = new SamplesList();
    allSamples.setSamples(samplesList);
    SummaryWriter.getInstance().reportDetectedLinkages(allSamples);
}
Also used : LinkageDisequilibriumGenotypeList(org.dash.valid.gl.LinkageDisequilibriumGenotypeList) SamplesList(org.dash.valid.report.SamplesList) DetectedLinkageFindings(org.dash.valid.report.DetectedLinkageFindings)

Example 5 with DetectedLinkageFindings

use of org.dash.valid.report.DetectedLinkageFindings in project ImmunogeneticDataTools by nmdp-bioinformatics.

the class AnalyzeGLStrings method writeOutput.

private void writeOutput(List<Sample> samplesList) throws IOException {
    PrintWriter writer = null;
    PrintWriter summaryWriter = null;
    PrintWriter pairWriter = null;
    PrintWriter pairWarningsWriter = null;
    PrintWriter linkageWriter = null;
    PrintWriter linkageWarningsWriter = null;
    PrintWriter nonCwdWriter = null;
    PrintWriter detectedFindingsWriter = null;
    boolean writeToDir = false;
    if (outputFile != null && outputFile.isDirectory()) {
        writeToDir = true;
        summaryWriter = writer(new File(outputFile + "/" + SummaryWriter.SUMMARY_XML_FILE), true);
        pairWriter = writer(new File(outputFile + "/" + HaplotypePairFileHandler.HAPLOTYPE_PAIRS_LOG), true);
        pairWarningsWriter = writer(new File(outputFile + "/" + HaplotypePairWarningFileHandler.HAPLOTYPE_PAIRS_WARNING_LOG), true);
        linkageWriter = writer(new File(outputFile + "/" + LinkageDisequilibriumFileHandler.LINKAGES_LOG), true);
        linkageWarningsWriter = writer(new File(outputFile + "/" + LinkageWarningFileHandler.LINKAGE_WARNINGS_LOG), true);
        nonCwdWriter = writer(new File(outputFile + "/" + CommonWellDocumentedFileHandler.NON_CWD_WARNINGS_LOG), true);
        detectedFindingsWriter = writer(new File(outputFile + "/" + DetectedFindingsWriter.DETECTED_FINDINGS_CSV), true);
    } else {
        writer = writer(outputFile, true);
    }
    SamplesList allSamples = new SamplesList();
    allSamples.setSamples(samplesList);
    String summaryFindings = SummaryWriter.formatDetectedLinkages(allSamples);
    for (Sample sample : samplesList) {
        DetectedLinkageFindings findings = sample.getFindings();
        if (warnings != null && warnings == Boolean.TRUE && !findings.hasAnomalies()) {
            continue;
        }
        if (writeToDir) {
            if (sample.getFindings().hasAnomalies()) {
                pairWarningsWriter.write(HaplotypePairWriter.formatDetectedLinkages(findings));
                linkageWarningsWriter.write(LinkageDisequilibriumWriter.formatDetectedLinkages(findings));
            } else {
                pairWriter.write(HaplotypePairWriter.formatDetectedLinkages(findings));
                linkageWriter.write(LinkageDisequilibriumWriter.formatDetectedLinkages(findings));
                nonCwdWriter.write(CommonWellDocumentedWriter.formatCommonWellDocumented(findings));
                detectedFindingsWriter.write(DetectedFindingsWriter.formatDetectedFindings(findings));
            }
        }
    }
    if (writeToDir) {
        summaryWriter.write(summaryFindings);
        summaryWriter.close();
        pairWriter.close();
        pairWarningsWriter.close();
        linkageWriter.close();
        linkageWarningsWriter.close();
        nonCwdWriter.close();
        detectedFindingsWriter.close();
    } else {
        writer.write(summaryFindings);
        writer.close();
    }
}
Also used : SamplesList(org.dash.valid.report.SamplesList) Sample(org.dash.valid.Sample) DetectedLinkageFindings(org.dash.valid.report.DetectedLinkageFindings) File(java.io.File) PrintWriter(java.io.PrintWriter)

Aggregations

DetectedLinkageFindings (org.dash.valid.report.DetectedLinkageFindings)5 Sample (org.dash.valid.Sample)2 HaplotypePair (org.dash.valid.gl.haplo.HaplotypePair)2 HaplotypePairComparator (org.dash.valid.gl.haplo.HaplotypePairComparator)2 HaplotypePairSet (org.dash.valid.gl.haplo.HaplotypePairSet)2 DetectedDisequilibriumElement (org.dash.valid.report.DetectedDisequilibriumElement)2 SamplesList (org.dash.valid.report.SamplesList)2 BufferedReader (java.io.BufferedReader)1 File (java.io.File)1 IOException (java.io.IOException)1 PrintWriter (java.io.PrintWriter)1 ArrayList (java.util.ArrayList)1 LinkageDisequilibriumGenotypeList (org.dash.valid.gl.LinkageDisequilibriumGenotypeList)1 Haplotype (org.dash.valid.gl.haplo.Haplotype)1 MultiLocusHaplotype (org.dash.valid.gl.haplo.MultiLocusHaplotype)1 CommandLineParseException (org.dishevelled.commandline.CommandLineParseException)1 MultilocusUnphasedGenotype (org.nmdp.gl.MultilocusUnphasedGenotype)1