Skip to content

Commit

Permalink
Migration to MiLib 1.1-SNAPSHOT.
Browse files Browse the repository at this point in the history
  • Loading branch information
dbolotin committed Aug 19, 2015
1 parent df3b7e0 commit ba8f80e
Show file tree
Hide file tree
Showing 16 changed files with 51 additions and 30 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<milib.version>1.0.2</milib.version>
<milib.version>1.1-SNAPSHOT</milib.version>
</properties>

<dependencies>
Expand Down
11 changes: 8 additions & 3 deletions src/main/java/com/milaboratory/mixcr/cli/ActionAlign.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,10 @@
import com.milaboratory.core.io.sequence.SequenceRead;
import com.milaboratory.core.io.sequence.SequenceReaderCloseable;
import com.milaboratory.core.io.sequence.fasta.FastaReader;
import com.milaboratory.core.io.sequence.fasta.FastaSequenceReaderWrapper;
import com.milaboratory.core.io.sequence.fastq.PairedFastqReader;
import com.milaboratory.core.io.sequence.fastq.SingleFastqReader;
import com.milaboratory.core.sequence.NucleotideSequence;
import com.milaboratory.mitools.cli.Action;
import com.milaboratory.mitools.cli.ActionHelper;
import com.milaboratory.mixcr.basictypes.VDJCAlignmentsWriter;
Expand Down Expand Up @@ -241,13 +243,16 @@ public String getOutputName() {

public SequenceReaderCloseable<? extends SequenceRead> createReader() throws IOException {
if (isInputPaired())
return new PairedFastqReader(parameters.get(0), parameters.get(1));
return new PairedFastqReader(parameters.get(0), parameters.get(1), true);
else {
String[] s = parameters.get(0).split("\\.");
if (s[s.length - 1].equals("fasta"))
return new FastaReader(parameters.get(0), true);
return new FastaSequenceReaderWrapper(
new FastaReader<>(parameters.get(0), NucleotideSequence.ALPHABET),
true
);
else
return new SingleFastqReader(parameters.get(0));
return new SingleFastqReader(parameters.get(0), true);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@

import com.milaboratory.core.mutations.Mutations;
import com.milaboratory.core.sequence.NucleotideSequence;
import com.milaboratory.core.sequence.SequencesUtils;
import com.milaboratory.util.Bit2Array;

import java.io.*;
Expand Down Expand Up @@ -252,7 +253,7 @@ private void readSequencePart(boolean compressed) throws IOException {
inflater.end();
} else
seqContent = Bit2Array.readFrom(stream);
library.base.put(accession, from, new NucleotideSequence(seqContent));
library.base.put(accession, from, SequencesUtils.convertBit2ArrayToNSequence(seqContent));
}

private void readMeta() throws IOException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@


import com.milaboratory.core.sequence.NucleotideSequence;
import com.milaboratory.core.sequence.SequencesUtils;

import java.io.ByteArrayOutputStream;
import java.io.DataOutputStream;
Expand Down Expand Up @@ -82,13 +83,13 @@ public void writeSequencePart(String accession, int from, NucleotideSequence seq
ByteArrayOutputStream bos = new ByteArrayOutputStream();
final Deflater def = new Deflater(9, true);
DeflaterOutputStream dos = new DeflaterOutputStream(bos, def);
sequence.getInnerData().writeTo(new DataOutputStream(dos));
SequencesUtils.convertNSequenceToBit2Array(sequence).writeTo(new DataOutputStream(dos));
dos.close();
def.end();
stream.writeInt(bos.size());
stream.write(bos.toByteArray());
} else
sequence.getInnerData().writeTo(stream);
SequencesUtils.convertNSequenceToBit2Array(sequence).writeTo(stream);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public KVJResultsForSingle(KAlignmentResult vResult, KAlignmentResult jResult, b
this.isRC = isRC;
}

private static KAlignmentHit[] extractHits(float minScore, KAlignmentResult result, int maxHits) {
private static KAlignmentHit<?>[] extractHits(float minScore, KAlignmentResult<?> result, int maxHits) {
int count = 0;
for (KAlignmentHit hit : result.getHits())
if (hit.getAlignment().getScore() > minScore) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,12 +141,12 @@ PAlignmentHelper createInitialHelper(PairedTarget target) {
}

static final PreVDJCHit[] zeroArray = new PreVDJCHit[0];
static final KAlignmentHit[] zeroKArray = new KAlignmentHit[0];
static final KAlignmentHit<?>[] zeroKArray = new KAlignmentHit[0];

final class PAlignmentHelper {
final PairedTarget target;
final KAlignmentResult[] vResults;
KAlignmentResult[] jResults;
final KAlignmentResult<?>[] vResults;
KAlignmentResult<?>[] jResults;
PairedHit[] vHits, jHits;
PairedHit bestVHits;

Expand Down Expand Up @@ -219,7 +219,7 @@ boolean hasHits() {
/**
* Converts two KAlignmentResults to an array of paired hits (each paired hit for a particular V of J gene)
*/
PairedHit[] extractDoubleHits(KAlignmentResult... results) {
PairedHit[] extractDoubleHits(KAlignmentResult<?>... results) {
TIntObjectHashMap<PairedHit> hits = new TIntObjectHashMap<>();
addHits(hits, results[0], 0);
addHits(hits, results[1], 1);
Expand All @@ -235,7 +235,7 @@ float score() {
(jHits != null && jHits.length > 0 ? jHits[0].sumScore : 0.0f);
}

void addHits(TIntObjectHashMap<PairedHit> hits, KAlignmentResult result, int index) {
void addHits(TIntObjectHashMap<PairedHit> hits, KAlignmentResult<?> result, int index) {
if (result == null)
return;

Expand Down Expand Up @@ -395,7 +395,7 @@ static void calculateScoreAndSort(PairedHit[] hits) {
* read.
*/
static final class PairedHit {
KAlignmentHit hit0, hit1;
KAlignmentHit<?> hit0, hit1;
float sumScore = -1, vEndScore = -1;

PairedHit() {
Expand Down Expand Up @@ -488,7 +488,7 @@ private static VDJCHit[] convert(PairedHit[] preHits,
/**
* Calculates alignment score only for FR3 and CDR3 part of V gene.
*/
float calculateVEndScore(KAlignmentHit hit) {
float calculateVEndScore(KAlignmentHit<?> hit) {
final Allele allele = getVAllelesToAlign().get(hit.getId());
final int boundary = allele.getPartitioning().getRelativePosition(
parameters.getFeatureToAlign(GeneType.Variable),
Expand Down Expand Up @@ -523,7 +523,7 @@ public int compare(PairedHit o1, PairedHit o2) {
}
};

static VDJCHit[] combine(final List<Allele> alleles, final GeneFeature feature, final KAlignmentHit[][] hits) {
static VDJCHit[] combine(final List<Allele> alleles, final GeneFeature feature, final KAlignmentHit<?>[][] hits) {
for (int i = 0; i < hits.length; i++)
Arrays.sort(hits[i], ALLELE_ID_COMPARATOR);
ArrayList<VDJCHit> result = new ArrayList<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
*/
package com.milaboratory.mixcr.assembler;

import com.milaboratory.core.io.util.TestUtil;
import com.milaboratory.core.io.util.IOTestUtil;
import com.milaboratory.mixcr.reference.GeneFeature;
import org.junit.Assert;
import org.junit.Test;
Expand All @@ -42,6 +42,6 @@ public void test1() throws Exception {

@Test
public void test2() throws Exception {
TestUtil.assertJavaSerialization(CloneAssemblerParametersPresets.getByName("default"));
IOTestUtil.assertJavaSerialization(CloneAssemblerParametersPresets.getByName("default"));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,11 @@ private static CloneSet runFullPipeline(String... fastqFiles) throws IOException

SequenceReader reader;
if (fastqFiles.length == 1)
reader = new SingleFastqReader(CloneAssemblerRunnerTest.class.getClassLoader().getResourceAsStream(fastqFiles[0]));
reader = new SingleFastqReader(CloneAssemblerRunnerTest.class.getClassLoader().getResourceAsStream(fastqFiles[0]),
true);
else
reader = new PairedFastqReader(CloneAssemblerRunnerTest.class.getClassLoader().getResourceAsStream(fastqFiles[0]),
CloneAssemblerRunnerTest.class.getClassLoader().getResourceAsStream(fastqFiles[1]));
CloneAssemblerRunnerTest.class.getClassLoader().getResourceAsStream(fastqFiles[1]), true);

//write alignments to byte array
ByteArrayOutputStream alignmentsSerialized = new ByteArrayOutputStream();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ public void testIsCompatible4() throws Exception {
assert rp <= td.c1.getConcatenated().size();
Mutations<NucleotideSequence> incompatible =
td.mutations.combineWith(Mutations.decode(
"I" + rp + "" + NucleotideSequence.ALPHABET.symbolFromCode(rl)
"I" + rp + "" + NucleotideSequence.ALPHABET.codeToSymbol(rl)
, NucleotideSequence.ALPHABET));
Assert.assertFalse(td.c1.isCompatible(td.c2, incompatible));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public void testSerialization1() throws Exception {
try (SingleFastqReader reader =
new SingleFastqReader(
IOTest.class.getClassLoader()
.getResourceAsStream("sequences/sample_IGH_R1.fastq"))) {
.getResourceAsStream("sequences/sample_IGH_R1.fastq"), true)) {

VDJCAlignerSJFirst aligner = new VDJCAlignerSJFirst(parameters);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import org.junit.Test;

import java.io.*;
import java.util.Arrays;
import java.util.List;
import java.util.UUID;

Expand Down Expand Up @@ -107,6 +108,18 @@ public void test3ReadLL() throws Exception {
Assert.assertTrue(allele.getPartitioning() != null);
}

@Test
public void test3ReadLL1() throws Exception {
InputStream sample = LociLibraryReader.class.getClassLoader().getResourceAsStream("reference/mi.ll");
LociLibrary library = LociLibraryReader.read(sample);
for (Allele allele : library.getAllAlleles(Species.HomoSapiens)) {
if (allele.getName().contains("4-61")) {
System.out.println(allele.isFunctional());
System.out.println(Arrays.toString(allele.getPartitioning().points));
}
}
}

@Ignore
@Test
public void testExportLL() throws Exception {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
package com.milaboratory.mixcr.vdjaligners;

import com.milaboratory.core.alignment.AffineGapAlignmentScoring;
import com.milaboratory.core.io.util.TestUtil;
import com.milaboratory.core.io.util.IOTestUtil;
import com.milaboratory.mixcr.reference.GeneFeature;
import com.milaboratory.util.GlobalObjectMappers;
import org.junit.Test;
Expand All @@ -52,6 +52,6 @@ public void test1() throws Exception {
public void test2() throws Exception {
DAlignerParameters se = new DAlignerParameters(GeneFeature.DRegion,
30.0f, 0.85f, 3, AffineGapAlignmentScoring.getNucleotideBLASTScoring());
TestUtil.assertJavaSerialization(se);
IOTestUtil.assertJavaSerialization(se);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public void test1() throws Exception {
VDJCAlignerSJFirstTest.class.getClassLoader()
.getResourceAsStream("sequences/sample_IGH_R1.fastq"),
VDJCAlignerSJFirstTest.class.getClassLoader()
.getResourceAsStream("sequences/sample_IGH_R2.fastq"))) {
.getResourceAsStream("sequences/sample_IGH_R2.fastq"), true)) {

VDJCAlignerPVFirst aligner = new VDJCAlignerPVFirst(parameters);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public void testSerialization1() throws Exception {
try (SingleFastqReader reader =
new SingleFastqReader(
VDJCAlignerSJFirstTest.class.getClassLoader()
.getResourceAsStream("sequences/sample_IGH_R1.fastq"))) {
.getResourceAsStream("sequences/sample_IGH_R1.fastq"), true)) {
VDJCAlignerSJFirst aligner = new VDJCAlignerSJFirst(parameters);
for (Allele allele : ll.getLocus(Species.HomoSapiens, Locus.IGH).getAllAlleles())
if (parameters.containsRequiredFeature(allele))
Expand All @@ -80,7 +80,7 @@ public void testSerialization1() throws Exception {
Assert.assertEquals(alignemntsList.get(i++), alignments);
}
}

// @Test
// public void testSerializationAndFilter() throws Exception {
// Assume.assumeTrue(TestUtil.lt());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public void test1() throws Exception {
VDJCAlignerSJFirstTest.class.getClassLoader()
.getResourceAsStream("sequences/sample_IGH_R1.fastq"),
VDJCAlignerSJFirstTest.class.getClassLoader()
.getResourceAsStream("sequences/sample_IGH_R2.fastq"))) {
.getResourceAsStream("sequences/sample_IGH_R2.fastq"), true)) {

VDJCAlignerWithMerge aligner = new VDJCAlignerWithMerge(parameters);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.milaboratory.mixcr.vdjaligners;

import com.milaboratory.core.io.util.TestUtil;
import com.milaboratory.core.io.util.IOTestUtil;
import org.junit.Test;

/**
Expand All @@ -9,6 +9,6 @@
public class VDJCParametersPresetsTest {
@Test
public void test1() throws Exception {
TestUtil.assertJavaSerialization(VDJCParametersPresets.getByName("default"));
IOTestUtil.assertJavaSerialization(VDJCParametersPresets.getByName("default"));
}
}

0 comments on commit ba8f80e

Please sign in to comment.