Skip to content

Commit

Permalink
Fixes "No more bytes" IllegalArgumentException in case of empty outpu…
Browse files Browse the repository at this point in the history
…t in ClnAReader.
  • Loading branch information
dbolotin committed Apr 12, 2018
1 parent 608ba2d commit c7cf869
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,9 @@ public final class ClnAReader implements AutoCloseable {
final String versionInfo;

public ClnAReader(Path path, VDJCLibraryRegistry libraryRegistry, int chunkSize) throws IOException {
if (chunkSize == 0)
throw new IllegalArgumentException();

this.chunkSize = chunkSize;
this.channel = FileChannel.open(path, StandardOpenOption.READ);
this.libraryRegistry = libraryRegistry;
Expand Down Expand Up @@ -377,7 +380,8 @@ private class InputDataStream implements DataInput {
this.buffer.limit(0);

// Filling first chunk of data
fillBuffer();
if (from < to)
fillBuffer();
}

void fillBuffer() throws IOException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import cc.redberry.pipe.CUtils;
import cc.redberry.pipe.OutputPort;
import com.milaboratory.mixcr.assembler.AlignmentsMappingMerger;
import com.milaboratory.mixcr.assembler.CloneAssemblerParametersPresets;
import com.milaboratory.mixcr.assembler.ReadToCloneMapping;
import com.milaboratory.mixcr.util.MiXCRVersionInfo;
import com.milaboratory.mixcr.util.RunMiXCR;
Expand All @@ -12,6 +13,7 @@
import org.junit.Test;

import java.io.File;
import java.util.Collections;

import static org.junit.Assert.assertEquals;

Expand All @@ -36,7 +38,7 @@ public void test1() throws Exception {

writer.close();

ClnAReader reader = new ClnAReader(file.toPath(), VDJCLibraryRegistry.createDefaultRegistry(), 17);
ClnAReader reader = new ClnAReader(file.toPath(), VDJCLibraryRegistry.getDefault(), 17);

assertEquals(MiXCRVersionInfo.get().getVersionString(MiXCRVersionInfo.OutputType.ToFile), reader.getVersionInfo());

Expand All @@ -54,6 +56,43 @@ public void test1() throws Exception {
}
}

@Test
public void test2Empty() throws Exception {
RunMiXCR.RunMiXCRAnalysis params = new RunMiXCR.RunMiXCRAnalysis(
RunMiXCR.class.getResource("/sequences/test_R1.fastq").getFile(),
RunMiXCR.class.getResource("/sequences/test_R2.fastq").getFile());

RunMiXCR.AlignResult align = RunMiXCR.align(params);

File file = TempFileManager.getTempFile();
ClnAWriter writer = new ClnAWriter(file);
writer.writeClones(new CloneSet(Collections.EMPTY_LIST, align.usedGenes,
align.parameters.alignerParameters.getFeaturesToAlignMap(),
align.parameters.alignerParameters,
CloneAssemblerParametersPresets.getByName("default")));
writer.sortAlignments(CUtils.asOutputPort(align.alignments), align.alignments.size());
writer.writeAlignmentsAndIndex();

writer.close();

ClnAReader reader = new ClnAReader(file.toPath(), VDJCLibraryRegistry.getDefault(), 17);

assertEquals(MiXCRVersionInfo.get().getVersionString(MiXCRVersionInfo.OutputType.ToFile), reader.getVersionInfo());

assertEquals(align.alignments.size(), reader.numberOfAlignments());
assertEquals(0, reader.numberOfClones());

for (ClnAReader.CloneAlignments c : CUtils.it(reader.clonesAndAlignments())) {
assertEquals("" + c.cloneId, c.clone.count, count(c.alignments()), 0.01);
assertEquals(c.cloneId, c.clone.id);
CUtils.it(c.alignments()).forEach(a -> {
assertEquals(c.cloneId, a.getCloneIndex());
if (a.getMappingType() == ReadToCloneMapping.MappingType.Core)
assertEquals(c.clone.getFeature(GeneFeature.CDR3), a.getFeature(GeneFeature.CDR3));
});
}
}

static int count(OutputPort port) {
int c = 0;
while (port.take() != null)
Expand Down

0 comments on commit c7cf869

Please sign in to comment.