Search in sources :

Example 1 with InsertSizeMetrics

use of picard.analysis.InsertSizeMetrics 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 2 with InsertSizeMetrics

use of picard.analysis.InsertSizeMetrics in project gridss by PapenfussLab.

the class IdsvSamFileMetricsTest method getInsertSizeMetrics_should_use_most_plentiful_orientation.

@Test
public void getInsertSizeMetrics_should_use_most_plentiful_orientation() {
    InsertSizeMetrics metrics = IdsvSamFileMetrics.getInsertSizeMetrics(new File("src/test/resources/multiple.idsv.metrics.insertsize.txt"), false);
    assertEquals(PairOrientation.FR, metrics.PAIR_ORIENTATION);
}
Also used : InsertSizeMetrics(picard.analysis.InsertSizeMetrics) File(java.io.File) Test(org.junit.Test)

Example 3 with InsertSizeMetrics

use of picard.analysis.InsertSizeMetrics 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 InsertSizeMetrics

use of picard.analysis.InsertSizeMetrics in project gridss by PapenfussLab.

the class CallVariants method extractEvidence.

private void extractEvidence(ExecutorService threadpool, List<SAMEvidenceSource> samEvidence) throws InterruptedException, ExecutionException {
    log.info("Extracting evidence.");
    for (Future<Void> future : threadpool.invokeAll(Lists.transform(samEvidence, new Function<SAMEvidenceSource, Callable<Void>>() {

        @Override
        public Callable<Void> apply(final SAMEvidenceSource input) {
            return new Callable<Void>() {

                @Override
                public Void call() throws Exception {
                    try {
                        input.ensureMetrics();
                        InsertSizeMetrics ism = input.getMetrics().getInsertSizeMetrics();
                        if (ism != null && ism.PAIR_ORIENTATION != PairOrientation.FR) {
                            String msg = "GRIDSS currently supports only FR read pair orientation. If usage with other read pair orientations is required, please raise an enchancement request at https://github.com/PapenfussLab/gridss/issues";
                            log.error(msg);
                            throw new RuntimeException(msg);
                        }
                        input.ensureExtracted();
                    } catch (Exception e) {
                        log.error(e, "Fatal exception thrown by worker thread.");
                        if (getContext().getConfig().terminateOnFirstError) {
                            System.exit(1);
                        }
                        throw e;
                    }
                    return null;
                }
            };
        }
    }))) {
        // throw exception from worker thread here
        future.get();
    }
    log.info("Evidence extraction complete.");
}
Also used : Function(com.google.common.base.Function) InsertSizeMetrics(picard.analysis.InsertSizeMetrics) SAMEvidenceSource(au.edu.wehi.idsv.SAMEvidenceSource) Callable(java.util.concurrent.Callable) IOException(java.io.IOException) ExecutionException(java.util.concurrent.ExecutionException)

Example 5 with InsertSizeMetrics

use of picard.analysis.InsertSizeMetrics 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)

Aggregations

InsertSizeMetrics (picard.analysis.InsertSizeMetrics)7 CigarDetailMetrics (gridss.analysis.CigarDetailMetrics)4 IdsvMetrics (gridss.analysis.IdsvMetrics)4 MapqMetrics (gridss.analysis.MapqMetrics)4 Test (org.junit.Test)4 MetricsFile (htsjdk.samtools.metrics.MetricsFile)3 InsertSizeDistribution (gridss.analysis.InsertSizeDistribution)2 SAMRecord (htsjdk.samtools.SAMRecord)2 SAMEvidenceSource (au.edu.wehi.idsv.SAMEvidenceSource)1 IdsvSamFileMetrics (au.edu.wehi.idsv.metrics.IdsvSamFileMetrics)1 IdsvSamFileMetricsCollector (au.edu.wehi.idsv.metrics.IdsvSamFileMetricsCollector)1 Function (com.google.common.base.Function)1 File (java.io.File)1 FileNotFoundException (java.io.FileNotFoundException)1 FileReader (java.io.FileReader)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 Callable (java.util.concurrent.Callable)1 ExecutionException (java.util.concurrent.ExecutionException)1