Skip to content

Commit

Permalink
Bug in ReferencePoints class fixed.
Browse files Browse the repository at this point in the history
  • Loading branch information
dbolotin committed Sep 26, 2015
1 parent 7143bfb commit 73a71e5
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 11 deletions.
2 changes: 1 addition & 1 deletion doc/export.rst
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ each target sequence. In this case arrays are sepparated by comma:

2:61:107:107:118:::::::::::::,:::::::::103:112:120:147:181:208:238:239:

Even if there are no anchor points in either of parts:
Even if there are no anchor points in one of the parts:

::

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ static ArrayList<FieldExtractor> parsePresetString(OutputMode outputMode, Class
"-nFeature FR3 -minFeatureQuality FR3 -nFeature CDR3 -minFeatureQuality CDR3 " +
"-nFeature FR4 -minFeatureQuality FR4 " +
"-aaFeature FR1 -aaFeature CDR1 -aaFeature FR2 -aaFeature CDR2 " +
"-aaFeature FR3 -aaFeature CDR3 -aaFeature FR4 -defaultReferencePoints");
"-aaFeature FR3 -aaFeature CDR3 -aaFeature FR4 -defaultAnchorPoints");
preset.put(Clone.class, clones);

Map<String, String> alignments = new HashMap<>();
Expand All @@ -240,7 +240,7 @@ static ArrayList<FieldExtractor> parsePresetString(OutputMode outputMode, Class
"-nFeature FR3 -minFeatureQuality FR3 -nFeature CDR3 -minFeatureQuality CDR3 " +
"-nFeature FR4 -minFeatureQuality FR4 " +
"-aaFeature FR1 -aaFeature CDR1 -aaFeature FR2 -aaFeature CDR2 " +
"-aaFeature FR3 -aaFeature CDR3 -aaFeature FR4 -defaultReferencePoints")
"-aaFeature FR3 -aaFeature CDR3 -aaFeature FR4 -defaultAnchorPoints")
;
preset.put(VDJCAlignments.class, alignments);
}
Expand Down
4 changes: 3 additions & 1 deletion src/main/java/com/milaboratory/mixcr/export/InfoWriter.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
package com.milaboratory.mixcr.export;

import cc.redberry.pipe.InputPort;
import org.apache.commons.io.output.CloseShieldOutputStream;

import java.io.*;
import java.util.ArrayList;
Expand All @@ -40,7 +41,8 @@ public final class InfoWriter<T> implements InputPort<T>, AutoCloseable {
boolean initialized;

public InfoWriter(String file) throws FileNotFoundException {
this(new BufferedOutputStream(new FileOutputStream(new File(file)), 65536));
this(".".equals(file) ? new CloseShieldOutputStream(System.out) :
new BufferedOutputStream(new FileOutputStream(new File(file)), 65536));
}

public void attachInfoProvider(AbstractFieldExtractor<? super T> provider) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,20 +41,23 @@
*/
public final class ReferencePoints extends SequencePartitioning implements java.io.Serializable {
final int[] points;
final boolean reversed;

public ReferencePoints(int[] points) {
if (points.length != BasicReferencePoint.TOTAL_NUMBER_OF_REFERENCE_POINTS)
throw new IllegalArgumentException("Illegal length of array.");
checkReferencePoints(points);
Boolean rev = checkReferencePoints(points);
this.reversed = rev == null ? false : rev;
this.points = points;
}

public ReferencePoints(int start, int[] points) {
checkReferencePoints(points);
Boolean rev = checkReferencePoints(points);
int[] array = new int[BasicReferencePoint.TOTAL_NUMBER_OF_REFERENCE_POINTS];
Arrays.fill(array, -1);
System.arraycopy(points, 0, array, start, points.length);
this.points = array;
this.reversed = rev == null ? false : rev;
}

public int numberOfDefinedPoints() {
Expand All @@ -66,7 +69,7 @@ public int numberOfDefinedPoints() {
return ret;
}

private static void checkReferencePoints(int[] points) {
private static Boolean checkReferencePoints(int[] points) {
Boolean reversed = null;

int first = -1;
Expand All @@ -83,7 +86,7 @@ else if (first != ref) {
}

if (reversed == null)
return;
return null;

int previousPoint = -1;
for (int point : points) {
Expand All @@ -101,6 +104,8 @@ else if (first != ref) {

previousPoint = point;
}

return reversed;
}

private int getPosition(int referencePointIndex) {
Expand Down Expand Up @@ -129,7 +134,7 @@ public int getPosition(ReferencePoint referencePoint) {
int point = getPosition(referencePoint.getIndex());
if (point < 0)
return -1;
return point + referencePoint.getOffset();
return point + (reversed ? -referencePoint.getOffset() : referencePoint.getOffset());
}

ReferencePoints getRelativeReferencePoints(GeneFeature geneFeature) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
*/
package com.milaboratory.mixcr.reference;

import com.milaboratory.core.sequence.AminoAcidSequence;
import com.milaboratory.core.sequence.NucleotideSequence;
import org.junit.Assert;
import org.junit.Ignore;
Expand Down Expand Up @@ -112,9 +113,11 @@ public void test3ReadLL() throws Exception {
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("3-11")) {
for (Allele allele : library.getAllAlleles(Species.MusMusculus)) {
if (allele.getName().contains("1-33")) {
System.out.println(allele.getName());
System.out.println(AminoAcidSequence.translate(allele.getFeature(FR3), 0));
System.out.println(allele.getFeature(FR3));
System.out.println(allele.isFunctional());
System.out.println(Arrays.toString(allele.getPartitioning().points));
}
Expand Down

0 comments on commit 73a71e5

Please sign in to comment.