Search in sources :

Example 1 with CigarDetailMetrics

use of gridss.analysis.CigarDetailMetrics in project gridss by PapenfussLab.

the class IdsvSamFileMetrics method getCigarMetrics.

private static List<CigarDetailMetrics> getCigarMetrics(File cigarMetricsFile) {
    if (cigarMetricsFile == null)
        return null;
    List<CigarDetailMetrics> list = new ArrayList<CigarDetailMetrics>();
    for (CigarDetailMetrics metric : Iterables.filter(MetricsFile.readBeans(cigarMetricsFile), CigarDetailMetrics.class)) {
        list.add(metric);
    }
    Collections.sort(list, CigarDetailMetricsByLength);
    for (CigarOperator op : CigarOperator.values()) {
        List<CigarDetailMetrics> opList = list.stream().filter(cdm -> cdm.OPERATOR == CigarOperator.enumToCharacter(op)).collect(Collectors.toList());
        for (int i = 0; i < opList.size(); i++) {
            if (opList.get(i).LENGTH != i) {
                String msg = String.format("%s missing cigar metric: expected metric for length %d, found %d", cigarMetricsFile, i, opList.get(0).LENGTH);
                log.error(msg);
                throw new RuntimeException(msg);
            }
        }
    }
    return list;
}
Also used : MapqMetrics(gridss.analysis.MapqMetrics) Iterables(com.google.common.collect.Iterables) Longs(com.google.common.primitives.Longs) CigarSizeDistribution(gridss.analysis.CigarSizeDistribution) GenomicProcessingContext(au.edu.wehi.idsv.GenomicProcessingContext) CigarDetailMetrics(gridss.analysis.CigarDetailMetrics) CigarOperator(htsjdk.samtools.CigarOperator) MetricsFile(htsjdk.samtools.metrics.MetricsFile) Collectors(java.util.stream.Collectors) File(java.io.File) Iterators(com.google.common.collect.Iterators) ArrayList(java.util.ArrayList) MathUtil(au.edu.wehi.idsv.util.MathUtil) List(java.util.List) InsertSizeDistribution(gridss.analysis.InsertSizeDistribution) Log(htsjdk.samtools.util.Log) Ordering(com.google.common.collect.Ordering) IdsvMetrics(gridss.analysis.IdsvMetrics) InsertSizeMetrics(picard.analysis.InsertSizeMetrics) Collections(java.util.Collections) ArrayList(java.util.ArrayList) CigarOperator(htsjdk.samtools.CigarOperator) CigarDetailMetrics(gridss.analysis.CigarDetailMetrics)

Example 2 with CigarDetailMetrics

use of gridss.analysis.CigarDetailMetrics in project gridss by PapenfussLab.

the class IdsvSamFileMetricsCollectorTest method should_calc_max_fragment_size.

@Test
public void should_calc_max_fragment_size() {
    IdsvSamFileMetricsCollector c = new IdsvSamFileMetricsCollector(null);
    c.acceptRecord(Read(0, 1, "100M"), null);
    c.acceptRecord(RP(0, 1, 2, 1)[0], null);
    c.acceptRecord(RP(0, 1, 7, 5)[0], null);
    // should ignore this as it's not a proper pair
    SAMRecord r = RP(0, 1, 100, 5)[0];
    r.setProperPairFlag(false);
    c.acceptRecord(r, null);
    // 12345678901234567890
    // ----> <----
    c.acceptRecord(Read(0, 1, "100M"), null);
    MetricsFile<IdsvMetrics, Integer> idsv = new MetricsFile<IdsvMetrics, Integer>();
    MetricsFile<InsertSizeMetrics, Integer> is = new MetricsFile<InsertSizeMetrics, Integer>();
    MetricsFile<CigarDetailMetrics, Integer> sc = new MetricsFile<CigarDetailMetrics, Integer>();
    MetricsFile<MapqMetrics, Integer> mq = new MetricsFile<MapqMetrics, Integer>();
    c.finish(is, idsv, mq, sc);
    assertEquals(11, (int) ((IdsvMetrics) idsv.getMetrics().get(0)).MAX_PROPER_PAIR_FRAGMENT_LENGTH);
    c = new IdsvSamFileMetricsCollector(null);
    // mate before
    r = RP(0, 1, 100, 5)[1];
    c.acceptRecord(r, null);
    c.finish(is, idsv, mq, sc);
    assertEquals(11, (int) ((IdsvMetrics) idsv.getMetrics().get(0)).MAX_PROPER_PAIR_FRAGMENT_LENGTH);
}
Also used : MetricsFile(htsjdk.samtools.metrics.MetricsFile) IdsvMetrics(gridss.analysis.IdsvMetrics) SAMRecord(htsjdk.samtools.SAMRecord) InsertSizeMetrics(picard.analysis.InsertSizeMetrics) MapqMetrics(gridss.analysis.MapqMetrics) CigarDetailMetrics(gridss.analysis.CigarDetailMetrics) Test(org.junit.Test)

Example 3 with CigarDetailMetrics

use of gridss.analysis.CigarDetailMetrics in project gridss by PapenfussLab.

the class EmpiricalReferenceLikelihoodModelTest method should_score_read_pairs_correctly.

@Test
public void should_score_read_pairs_correctly() {
    IdsvSamFileMetrics metrics = new IdsvSamFileMetrics(new InsertSizeMetrics() {

        {
            MEAN_INSERT_SIZE = 2;
            MEDIAN_INSERT_SIZE = 2;
            MIN_INSERT_SIZE = 1;
            MAX_INSERT_SIZE = 3;
            MEDIAN_ABSOLUTE_DEVIATION = 1;
        }
    }, new IdsvMetrics() {

        {
            MAX_READ_LENGTH = 100;
            MAX_PROPER_PAIR_FRAGMENT_LENGTH = 2;
            MIN_PROPER_PAIR_FRAGMENT_LENGTH = 2;
            READ_PAIRS = 13;
            READ_PAIRS_ONE_MAPPED = 2;
            READ_PAIRS_ZERO_MAPPED = 1;
            READ_PAIRS_BOTH_MAPPED = READ_PAIRS - READ_PAIRS_ONE_MAPPED - READ_PAIRS_ZERO_MAPPED;
            READS = 2 * READ_PAIRS;
            MAPPED_READS = READS - READ_PAIRS_ONE_MAPPED - 2 * READ_PAIRS_ZERO_MAPPED;
        }
    }, new MapqMetrics() {

        {
        }
    }, new InsertSizeDistribution(new int[] { 1, 2, 3 }, new double[] { 1, 8, 1 }), new ArrayList<CigarDetailMetrics>());
    assertEquals(10, model.scoreReadPair(metrics, 3, 1000, 1000), 0.001);
}
Also used : IdsvMetrics(gridss.analysis.IdsvMetrics) IdsvSamFileMetrics(au.edu.wehi.idsv.metrics.IdsvSamFileMetrics) InsertSizeMetrics(picard.analysis.InsertSizeMetrics) InsertSizeDistribution(gridss.analysis.InsertSizeDistribution) MapqMetrics(gridss.analysis.MapqMetrics) CigarDetailMetrics(gridss.analysis.CigarDetailMetrics) Test(org.junit.Test)

Example 4 with CigarDetailMetrics

use of gridss.analysis.CigarDetailMetrics in project gridss by PapenfussLab.

the class TestHelper method IDSV.

public IdsvMetrics IDSV(Collection<SAMRecord> input) {
    IdsvSamFileMetricsCollector c = new IdsvSamFileMetricsCollector(null);
    for (SAMRecord r : input) {
        c.acceptRecord(r, null);
    }
    MetricsFile<IdsvMetrics, Integer> idsv = new MetricsFile<IdsvMetrics, Integer>();
    MetricsFile<InsertSizeMetrics, Integer> is = new MetricsFile<InsertSizeMetrics, Integer>();
    MetricsFile<CigarDetailMetrics, Integer> sc = new MetricsFile<CigarDetailMetrics, Integer>();
    MetricsFile<MapqMetrics, Integer> mqm = new MetricsFile<MapqMetrics, Integer>();
    c.finish(is, idsv, mqm, sc);
    IdsvMetrics metrics = idsv.getMetrics().get(0);
    return metrics;
}
Also used : MetricsFile(htsjdk.samtools.metrics.MetricsFile) IdsvMetrics(gridss.analysis.IdsvMetrics) SAMRecord(htsjdk.samtools.SAMRecord) InsertSizeMetrics(picard.analysis.InsertSizeMetrics) MapqMetrics(gridss.analysis.MapqMetrics) CigarDetailMetrics(gridss.analysis.CigarDetailMetrics) IdsvSamFileMetricsCollector(au.edu.wehi.idsv.metrics.IdsvSamFileMetricsCollector)

Example 5 with CigarDetailMetrics

use of gridss.analysis.CigarDetailMetrics in project gridss by PapenfussLab.

the class IdsvSamFileMetricsCollector method acceptCigarElement.

private void acceptCigarElement(CigarElement ce) {
    List<CigarDetailMetrics> list = cigar.get(ce.getOperator());
    int length = ce.getLength();
    while (list.size() <= length) {
        CigarDetailMetrics cdm = new CigarDetailMetrics();
        cdm.LENGTH = list.size();
        cdm.OPERATOR = (char) CigarOperator.enumToCharacter(ce.getOperator());
        cdm.COUNT = 0;
        list.add(cdm);
    }
    list.get(ce.getLength()).COUNT++;
}
Also used : CigarDetailMetrics(gridss.analysis.CigarDetailMetrics)

Aggregations

CigarDetailMetrics (gridss.analysis.CigarDetailMetrics)7 IdsvMetrics (gridss.analysis.IdsvMetrics)5 MapqMetrics (gridss.analysis.MapqMetrics)5 InsertSizeMetrics (picard.analysis.InsertSizeMetrics)5 InsertSizeDistribution (gridss.analysis.InsertSizeDistribution)3 MetricsFile (htsjdk.samtools.metrics.MetricsFile)3 Test (org.junit.Test)3 IdsvSamFileMetrics (au.edu.wehi.idsv.metrics.IdsvSamFileMetrics)2 SAMRecord (htsjdk.samtools.SAMRecord)2 ArrayList (java.util.ArrayList)2 GenomicProcessingContext (au.edu.wehi.idsv.GenomicProcessingContext)1 IdsvSamFileMetricsCollector (au.edu.wehi.idsv.metrics.IdsvSamFileMetricsCollector)1 MathUtil (au.edu.wehi.idsv.util.MathUtil)1 Iterables (com.google.common.collect.Iterables)1 Iterators (com.google.common.collect.Iterators)1 Ordering (com.google.common.collect.Ordering)1 Longs (com.google.common.primitives.Longs)1 CigarSizeDistribution (gridss.analysis.CigarSizeDistribution)1 CigarOperator (htsjdk.samtools.CigarOperator)1 Log (htsjdk.samtools.util.Log)1