Java Code Examples for htsjdk.samtools.util.CollectionUtil#makeList()
The following examples show how to use
htsjdk.samtools.util.CollectionUtil#makeList() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: IntervalListToBed.java From picard with MIT License | 6 votes |
@Override protected int doWork() { IOUtil.assertFileIsReadable(INPUT); IOUtil.assertFileIsWritable(OUTPUT); IntervalList intervals = IntervalList.fromFile(INPUT); if (SORT) intervals = intervals.sorted(); try { final BufferedWriter out = IOUtil.openFileForBufferedWriting(OUTPUT); for (final Interval i : intervals) { final String strand = i.isNegativeStrand() ? "-" : "+"; final List<?> fields = CollectionUtil.makeList(i.getContig(), i.getStart()-1, i.getEnd(), i.getName(), SCORE, strand); out.append(fields.stream().map(String::valueOf).collect(Collectors.joining("\t"))); out.newLine(); } out.close(); } catch (IOException ioe) { throw new RuntimeIOException(ioe); } return 0; }
Example 2
Source File: MarkDuplicatesTest.java From picard with MIT License | 6 votes |
@Test(dataProvider = "testOpticalDuplicateDetectionDataProvider") public void testOpticalDuplicateDetection(final File sam, final long expectedNumOpticalDuplicates) { final File outputDir = IOUtil.createTempDir(TEST_BASE_NAME + ".", ".tmp"); outputDir.deleteOnExit(); final File outputSam = new File(outputDir, TEST_BASE_NAME + ".sam"); outputSam.deleteOnExit(); final File metricsFile = new File(outputDir, TEST_BASE_NAME + ".duplicate_metrics"); metricsFile.deleteOnExit(); // Run MarkDuplicates, merging the 3 input files, and either enabling or suppressing PG header // record creation according to suppressPg. final MarkDuplicates markDuplicates = new MarkDuplicates(); markDuplicates.setupOpticalDuplicateFinder(); markDuplicates.INPUT = CollectionUtil.makeList(sam.getAbsolutePath()); markDuplicates.OUTPUT = outputSam; markDuplicates.METRICS_FILE = metricsFile; markDuplicates.TMP_DIR = CollectionUtil.makeList(outputDir); // Needed to suppress calling CommandLineProgram.getVersion(), which doesn't work for code not in a jar markDuplicates.PROGRAM_RECORD_ID = null; Assert.assertEquals(markDuplicates.doWork(), 0); Assert.assertEquals(markDuplicates.numOpticalDuplicates(), expectedNumOpticalDuplicates); IOUtil.recursiveDelete(outputDir.toPath()); }
Example 3
Source File: FindMendelianViolations.java From picard with MIT License | 5 votes |
private void writeAllViolations(final MendelianViolationDetector.Result result) { if (VCF_DIR != null) { LOG.info(String.format("Writing family violation VCFs to %s/", VCF_DIR.getAbsolutePath())); final VariantContextComparator vcComparator = new VariantContextComparator(inputHeader.get().getContigLines()); final Set<VCFHeaderLine> headerLines = new LinkedHashSet<>(inputHeader.get().getMetaDataInInputOrder()); headerLines.add(new VCFInfoHeaderLine(MendelianViolationDetector.MENDELIAN_VIOLATION_KEY, 1, VCFHeaderLineType.String, "Type of mendelian violation.")); headerLines.add(new VCFInfoHeaderLine(MendelianViolationDetector.ORIGINAL_AC, VCFHeaderLineCount.A, VCFHeaderLineType.Integer, "Original AC")); headerLines.add(new VCFInfoHeaderLine(MendelianViolationDetector.ORIGINAL_AF, VCFHeaderLineCount.A, VCFHeaderLineType.Float, "Original AF")); headerLines.add(new VCFInfoHeaderLine(MendelianViolationDetector.ORIGINAL_AN, 1, VCFHeaderLineType.Integer, "Original AN")); for (final PedFile.PedTrio trio : pedFile.get().values()) { final File outputFile = new File(VCF_DIR, IOUtil.makeFileNameSafe(trio.getFamilyId() + IOUtil.VCF_FILE_EXTENSION)); LOG.info(String.format("Writing %s violation VCF to %s", trio.getFamilyId(), outputFile.getAbsolutePath())); final VariantContextWriter out = new VariantContextWriterBuilder() .setOutputFile(outputFile) .unsetOption(INDEX_ON_THE_FLY) .build(); final VCFHeader newHeader = new VCFHeader(headerLines, CollectionUtil.makeList(trio.getMaternalId(), trio.getPaternalId(), trio.getIndividualId())); final TreeSet<VariantContext> orderedViolations = new TreeSet<>(vcComparator); orderedViolations.addAll(result.violations().get(trio.getFamilyId())); out.writeHeader(newHeader); orderedViolations.forEach(out::add); out.close(); } } }
Example 4
Source File: RenameSampleInVcf.java From picard with MIT License | 5 votes |
@Override protected int doWork() { IOUtil.assertFileIsReadable(INPUT); IOUtil.assertFileIsWritable(OUTPUT); final VCFFileReader in = new VCFFileReader(INPUT, false); final VCFHeader header = in.getFileHeader(); if (header.getGenotypeSamples().size() > 1) { throw new IllegalArgumentException("Input VCF must be single-sample."); } if (OLD_SAMPLE_NAME != null && !OLD_SAMPLE_NAME.equals(header.getGenotypeSamples().get(0))) { throw new IllegalArgumentException("Input VCF did not contain expected sample. Contained: " + header.getGenotypeSamples().get(0)); } final EnumSet<Options> options = EnumSet.copyOf(VariantContextWriterBuilder.DEFAULT_OPTIONS); if (CREATE_INDEX) options.add(Options.INDEX_ON_THE_FLY); else options.remove(Options.INDEX_ON_THE_FLY); final VCFHeader outHeader = new VCFHeader(header.getMetaDataInInputOrder(), CollectionUtil.makeList(NEW_SAMPLE_NAME)); final VariantContextWriter out = new VariantContextWriterBuilder() .setOptions(options) .setOutputFile(OUTPUT).setReferenceDictionary(outHeader.getSequenceDictionary()).build(); out.writeHeader(outHeader); for (final VariantContext ctx : in) { out.add(ctx); } out.close(); in.close(); return 0; }
Example 5
Source File: IntervalListScattererWithSubdivision.java From picard with MIT License | 5 votes |
@Override public List<Interval> takeSome(final Interval interval, final long idealSplitWeight, final long currentSize, final double projectSizeOfRemaining) { final long amount = idealSplitWeight - currentSize; if (amount >= interval.length()) { return CollectionUtil.makeList(interval, null); } if (amount == 0) { return CollectionUtil.makeList(null, interval); } final Interval left = new Interval( interval.getContig(), interval.getStart(), interval.getStart() + (int) amount - 1, interval.isNegativeStrand(), interval.getName() ); final Interval right = new Interval( interval.getContig(), interval.getStart() + (int) amount, interval.getEnd(), interval.isNegativeStrand(), interval.getName() ); return CollectionUtil.makeList(left, right); }
Example 6
Source File: IntervalListScattererWithoutSubdivision.java From picard with MIT License | 5 votes |
@Override public List<Interval> takeSome(final Interval interval, final long idealSplitWeight, final long currentSize, final double projectedSizeOfRemaining) { final long projectedSize = currentSize + intervalWeight(interval); if (shouldIncludeInterval(idealSplitWeight, projectedSizeOfRemaining, projectedSize)) { return CollectionUtil.makeList(interval, null); } else { return CollectionUtil.makeList(null, interval); } }
Example 7
Source File: ReadNameParserTests.java From picard with MIT License | 5 votes |
/** Tests rapidParseInt for positive and negative numbers, as well as non-digit suffixes */ @Test public void testRapidParseIntFails() { List<String> values = CollectionUtil.makeList("foo", "bar", "abc123", "-foo", "f00", "-f00"); for (String s : values) { try { ReadNameParser.rapidParseInt(s); Assert.fail("Should have failed to rapid-parse " + s + " as an int."); } catch (NumberFormatException nfe) { /* expected */ } } }
Example 8
Source File: HaplotypeProbabilitiesTest.java From picard with MIT License | 5 votes |
@DataProvider(name = "dataTestpEvidenceGivenPriorFromGLs") public Object[][] dataTestpEvidenceGivenPriorFromGLs() { return new Object[][]{ new Object[]{ new HaplotypeProbabilitiesFromGenotypeLikelihoods(hb1), Collections.singletonList(snp1), Collections.singletonList(false), Collections.singletonList(new double[]{0, -1, -2})}, new Object[]{ new HaplotypeProbabilitiesFromGenotypeLikelihoods(hb2), Collections.singletonList(snp2), Collections.singletonList(true), Collections.singletonList(new double[]{-2, -1, 0})}, new Object[]{ new HaplotypeProbabilitiesFromGenotypeLikelihoods(hb2), CollectionUtil.makeList(snp1, snp2), CollectionUtil.makeList(false, false), CollectionUtil.makeList(new double[]{0, -1, -2}, new double[]{0, -1, -2})}, new Object[]{ new HaplotypeProbabilitiesFromGenotypeLikelihoods(hb2), CollectionUtil.makeList(snp2, snp1), CollectionUtil.makeList(false, false), CollectionUtil.makeList(new double[]{0, -1, -2}, new double[]{-1, 0, -1})}, new Object[]{ new HaplotypeProbabilitiesFromGenotypeLikelihoods(hb2), CollectionUtil.makeList(snp1, snp2), CollectionUtil.makeList(false, false), CollectionUtil.makeList(new double[]{0, -1, -2}, new double[]{-2, -1, 0})}, }; }
Example 9
Source File: QdFilter.java From picard with MIT License | 4 votes |
@Override public List<VCFFilterHeaderLine> headerLines() { return CollectionUtil.makeList(new VCFFilterHeaderLine(FILTER_NAME, "Site exhibits QD value below a hard limit.")); }
Example 10
Source File: AlleleBalanceFilter.java From picard with MIT License | 4 votes |
@Override public List<VCFFilterHeaderLine> headerLines() { return CollectionUtil.makeList(new VCFFilterHeaderLine(AB_FILTER, "Heterozygote allele balance below required threshold.")); }
Example 11
Source File: FisherStrandFilter.java From picard with MIT License | 4 votes |
@Override public List<VCFFilterHeaderLine> headerLines() { return CollectionUtil.makeList(new VCFFilterHeaderLine("StrandBias", "Site exhibits excessive allele/strand correlation.")); }
Example 12
Source File: Snp.java From picard with MIT License | 4 votes |
public List<Allele> getAlleles() { return CollectionUtil.makeList(Allele.create(getAllele1()), Allele.create(getAllele2())); }
Example 13
Source File: IlluminaBasecallsToSamAdapterClippingTest.java From picard with MIT License | 4 votes |
/** * Run IlluminaBasecallsToSam on a few test cases, and verify that results agree with hand-checked expectation. */ @Test(dataProvider="data") public void testBasic(final String LANE, final String readStructure, final String fivePrimerAdapter, final String threePrimerAdapter, final int expectedNumClippedRecords) throws Exception { // Create the SAM file from Gerald output final File samFile = File.createTempFile("." + LANE + ".illuminaBasecallsToSam", ".sam"); samFile.deleteOnExit(); final List<String> illuminaArgv = CollectionUtil.makeList("BASECALLS_DIR=" + TEST_DATA_DIR, "LANE=" + LANE, "RUN_BARCODE=" + RUN_BARCODE, "READ_STRUCTURE=" + readStructure, "OUTPUT=" + samFile, "SEQUENCING_CENTER=BI", "ALIAS=" + ALIAS ); if (fivePrimerAdapter != null) { illuminaArgv.addAll(CollectionUtil.makeList( "ADAPTERS_TO_CHECK=null", "FIVE_PRIME_ADAPTER=" + fivePrimerAdapter, "THREE_PRIME_ADAPTER=" + threePrimerAdapter )); } Assert.assertEquals(runPicardCommandLine(illuminaArgv), 0); // Read the file and confirm it contains what is expected final SamReader samReader = SamReaderFactory.makeDefault().open(samFile); // look for clipped adaptor attribute in lane 3 PE (2) and in lane 6 (1) non-PE int count = 0; for (final SAMRecord record : samReader) { if (record.getIntegerAttribute(ReservedTagConstants.XT) != null) { count++; if ((count == 1 || count == 2) && LANE.equals("2")){ Assert.assertEquals (114, (int)record.getIntegerAttribute(ReservedTagConstants.XT)); } else if (count == 1 || count == 2 && LANE.equals("1")) { Assert.assertEquals(68, (int) record.getIntegerAttribute(ReservedTagConstants.XT)); } } } // Check the total number of clipped records Assert.assertEquals(count, expectedNumClippedRecords); samReader.close(); samFile.delete(); }
Example 14
Source File: ScatterIntervalsByNsTest.java From picard with MIT License | 4 votes |
@DataProvider(name = "testSegregate") public Object[][] testSegregate() { return new Object[][]{ new Object[]{"NNNNNAAAAANNNNNN", 1, CollectionUtil.makeList( new Interval("fake1", 1, 5), new Interval("fake1", 6, 10), new Interval("fake1", 11, 16))}, new Object[]{"NNNNNAAAAANNNNNN", 5, CollectionUtil.makeList( new Interval("fake1", 1, 5), new Interval("fake1", 6, 10), new Interval("fake1", 11, 16))}, new Object[]{"NNNNNAAAnANNNNNN", 6, CollectionUtil.makeList( new Interval("fake1", 1, 5), new Interval("fake1", 6, 10), new Interval("fake1", 11, 16))}, new Object[]{"AnTGCNNNNNACGTCG", 1, CollectionUtil.makeList( new Interval("fake1", 1, 5), new Interval("fake1", 6, 10), new Interval("fake1", 11, 16))}, new Object[]{"ACTGCNNNNNACGTCG", 4, CollectionUtil.makeList( new Interval("fake1", 1, 5), new Interval("fake1", 6, 10), new Interval("fake1", 11, 16))}, new Object[]{"ACTGCNNNNNACgctG", 5, CollectionUtil.makeList( new Interval("fake1", 1, 16))}, new Object[]{"ACNGCNNNNNACnTNG", 5, CollectionUtil.makeList( new Interval("fake1", 1, 16))}, new Object[]{"ACNGCNNNNNACnTNG", 0, CollectionUtil.makeList( new Interval("fake1", 1, 2), //acgt new Interval("fake1", 3, 3), //N new Interval("fake1", 4, 5), new Interval("fake1", 6, 10), //N new Interval("fake1", 11, 12), new Interval("fake1", 13, 13), //N new Interval("fake1", 14, 14), new Interval("fake1", 15, 15), //N new Interval("fake1", 16, 16))}, new Object[]{"AAAAAAAAAAACnTNG", 0, CollectionUtil.makeList( new Interval("fake1", 1, 12), new Interval("fake1", 13, 13), //N new Interval("fake1", 14, 14), new Interval("fake1", 15, 15), //N new Interval("fake1", 16, 16))}, new Object[]{"AAAAAAAAAAACATNG", 0, CollectionUtil.makeList( new Interval("fake1", 1, 14), new Interval("fake1", 15, 15), //N new Interval("fake1", 16, 16))}, new Object[]{"ANCNNGCNNNNNACNTNGN", 1, CollectionUtil.makeList( new Interval("fake1", 1, 3), new Interval("fake1", 4, 5), new Interval("fake1", 6, 7), new Interval("fake1", 8, 12), new Interval("fake1", 13, 18), new Interval("fake1", 19, 19) )}, new Object[]{"ANCNNGCNNNNNACNTNGN", 0, CollectionUtil.makeList( new Interval("fake1", 1, 1), new Interval("fake1", 2, 2), new Interval("fake1", 3, 3), new Interval("fake1", 4, 5), new Interval("fake1", 6, 7), new Interval("fake1", 8, 12), new Interval("fake1", 13, 14), new Interval("fake1", 15, 15), new Interval("fake1", 16, 16), new Interval("fake1", 17, 17), new Interval("fake1", 18, 18), new Interval("fake1", 19, 19) )} }; }