SamFileBuilder { String handleMaxFilenameLength(String originalName, String srcExtension) { if (originalName.length() <= MAX_FILENAME_LENGTH) { return originalName; } val extensionPos = originalName.toLowerCase().indexOf(srcExtension); val left = StringUtils.left(originalName, MAX_FILENAME_LENGTH - 1); val extension = StringUtils.right(originalName, originalName.length() - extensionPos); return String.format("%s%s%s", left, "~", extension); }  SamFileBuilder reader(SamReader r); SamFileBuilder containedOnly(boolean flag); SamFileBuilder useOriginalHeader(boolean flag); SamFileBuilder outputFormat(OutputFormat format); SamFileBuilder queries(List<String> queries); SamFileBuilder outputDir(File dir); SamFileBuilder stdout(boolean flag); SamFileBuilder bedFile(File bed); SamFileBuilder outputIndex(boolean flag); SamFileBuilder entity(Entity e); SamFileBuilder samInput(SamInputResource resource); SamFileBuilder cramReferenceSource(ReferenceSource source); SamFileBuilder programId(String id); SamFileBuilder programName(String name); SamFileBuilder commandLine(String cl); SamFileBuilder description(String desc); SamFileBuilder version(String ver); @SneakyThrows SamReader createSamReader(); QueryInterval[] normalizeQueries(SamReader reader, List<String> queries); List<SAMRecord> doQuery(SamReader reader, QueryInterval[] intervals); void buildHeaderOnly(); @SneakyThrows void buildTrimmed(); @SneakyThrows void buildTrimmed(SamReader reader); @SneakyThrows void buildMerged(); @Override String toString(); final static int MAX_FILENAME_LENGTH; }
@Test public void test_sane_bam_filename() { String longName = "TEST-HCC1954.NORMAL.7x.compare.1_9000000-12500000.bam"; String result = sut.handleMaxFilenameLength(longName, ".bam"); assertThat(result, equalTo(longName)); assertThat(result.length(), equalTo(longName.length())); }
@Test public void test_long_bam_filename() { String longName = "TEST-HCC1954.NORMAL.7x.compare.1_9000000-12500000__2_180000000-205000000__4_50000-750000__5_1291650-1296560__16_25054900-25099000__21_18279635-18282565.bam"; String fname = "TEST-HCC1954.NORMAL.7x.compare.1_9000000-12500000__2_180000000-205000000__4_50000-750000__5_1291650-1296560__16_25054900-250990~.bam"; String result = sut.handleMaxFilenameLength(longName, ".bam"); assertThat(result.length(), lessThan(longName.length())); assertThat(result, equalTo(fname)); }
@Test public void test_sane_bai_filename() { String longName = "TEST-HCC1954.NORMAL.7x.compare.1_9000000-12500000.bam"; String result = sut.handleMaxFilenameLength(longName, ".bam"); assertThat(result, equalTo(longName)); assertThat(result.length(), equalTo(longName.length())); }
@Test public void test_long_bai_filename() { String longName = "TEST-HCC1954.NORMAL.7x.compare.1_9000000-12500000__2_180000000-205000000__4_50000-750000__5_1291650-1296560__16_25054900-25099000__21_18279635-18282565.bam.bai"; String fname = "TEST-HCC1954.NORMAL.7x.compare.1_9000000-12500000__2_180000000-205000000__4_50000-750000__5_1291650-1296560__16_25054900-250990~.bam.bai"; String result = sut.handleMaxFilenameLength(longName, ".bam.bai"); assertThat(result.length(), lessThan(longName.length())); assertThat(result, equalTo(fname)); }