-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
change SetAsCopy() and getLengthInBytes() to be consistent with writi…
…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.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 { | ||
|
@@ -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) { | ||
|
@@ -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.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong. |
||
offset += thisReadSequence.getLength(); | ||
|
||
} | ||
if ((activeFields & READHEADINFO_FIELDS.THAT_READSEQUENCE) != 0) { | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong. |
||
thatReadSequence.setAsCopy(data, offset); | ||
offset += thatReadSequence.getLength(); | ||
} | ||
add(new ReadHeadInfo(uuid, thisReadSequence, thatReadSequence)); | ||
} | ||
} | ||
|
||
This comment has been minimized.
Sorry, something went wrong.
Nan-Zhang
Collaborator
|
||
|
@@ -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; | ||
} | ||
} |
Should use your
getThisReadSequence()
here-- it could be null.