Skip to content

Commit

Permalink
change SetAsCopy() and getLengthInBytes() to be consistent with writi…
Browse files Browse the repository at this point in the history
…ng nothing about null members
  • Loading branch information
Nan Zhang committed Nov 14, 2013
1 parent a8e0e32 commit 90ebdfe
Showing 1 changed file with 30 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

import org.apache.hadoop.io.Writable;

import edu.uci.ics.genomix.type.ReadHeadInfo.READHEADINFO_FIELDS;
import edu.uci.ics.genomix.util.Marshal;

public class ReadHeadSet extends TreeSet<ReadHeadInfo> implements Writable, Serializable {
Expand All @@ -33,17 +34,17 @@ public ReadHeadSet(SortedSet<ReadHeadInfo> s) {
super(s);
}

public void add(byte mateId, long readId, int offset, VKmer mate0ReadSequence, VKmer mate1ReadSequence) {
add(new ReadHeadInfo(mateId, readId, offset, mate0ReadSequence, mate1ReadSequence));
public void add(byte mateId, long readId, int offset, VKmer thisReadSequence, VKmer thatReadSequence) {
add(new ReadHeadInfo(mateId, readId, offset, thisReadSequence, thatReadSequence));
}

public ReadHeadInfo getReadHeadInfoFromReadId(long readId) {
ReadHeadInfo info = super.floor(new ReadHeadInfo(readId, null, null)); //TODO need check
if (info != null && info.getReadId() == readId) {
return info;
}
return null;
}
// public ReadHeadInfo getReadHeadInfoFromReadId(long readId) {
// ReadHeadInfo info = super.floor(new ReadHeadInfo(readId, null, null)); //TODO need check
// if (info != null && info.getReadId() == readId) {
// return info;
// }
// return null;
// }

public int getOffsetFromReadId(long readId) {
for (ReadHeadInfo readHeadInfo : this) {
Expand All @@ -58,16 +59,25 @@ public void setAsCopy(byte[] data, int offset) {
clear();
int count = Marshal.getInt(data, offset);
offset += HEADER_SIZE;
VKmer mate0ReadSequence = new VKmer();
VKmer mate1ReadSequence = new VKmer();
VKmer thisReadSequence = new VKmer();
VKmer thatReadSequence = new VKmer();
for (int i = 0; i < count; i++) {
thisReadSequence.reset(0);
thatReadSequence.reset(0);
byte activeFields = data[offset];
offset++;
long uuid = Marshal.getLong(data, offset);
offset += ReadHeadInfo.ITEM_SIZE;
mate0ReadSequence.setAsCopy(data, offset);
offset += mate0ReadSequence.getLength();
mate1ReadSequence.setAsCopy(data, offset);
offset += mate1ReadSequence.getLength();
add(new ReadHeadInfo(uuid, mate0ReadSequence, mate1ReadSequence));
if ((activeFields & READHEADINFO_FIELDS.THIS_READSEQUENCE) != 0) {
thisReadSequence.setAsCopy(data, offset);

This comment has been minimized.

Copy link
@jakebiesinger

jakebiesinger Nov 14, 2013

Contributor

Should use your getThisReadSequence() here-- it could be null.

This comment has been minimized.

Copy link
@Nan-Zhang

Nan-Zhang Nov 18, 2013

Collaborator

Done.

offset += thisReadSequence.getLength();

}
if ((activeFields & READHEADINFO_FIELDS.THAT_READSEQUENCE) != 0) {

This comment has been minimized.

Copy link
@jakebiesinger

jakebiesinger Nov 14, 2013

Contributor

Same here.

This comment has been minimized.

Copy link
@Nan-Zhang

Nan-Zhang Nov 18, 2013

Collaborator

Done.

thatReadSequence.setAsCopy(data, offset);
offset += thatReadSequence.getLength();
}
add(new ReadHeadInfo(uuid, thisReadSequence, thatReadSequence));
}
}

This comment has been minimized.

Copy link
@Nan-Zhang

Nan-Zhang Nov 14, 2013

Collaborator

@jakebiesinger change setAsCopy() and getLengthInBytes() to be sensitive to null member, please have a check

Expand Down Expand Up @@ -122,6 +132,9 @@ public static ReadHeadSet getIntersection(ReadHeadSet list1, ReadHeadSet list2)
}

public int getLengthInBytes() {
return HEADER_SIZE + first().getLengthInBytes() * size();
int totalBytes = HEADER_SIZE;
for(ReadHeadInfo iter : this)
totalBytes += iter.getLengthInBytes();
return totalBytes;
}
}

0 comments on commit 90ebdfe

Please sign in to comment.