Skip to content

Commit

Permalink
Add Squence asAsciiBytes method.
Browse files Browse the repository at this point in the history
  • Loading branch information
JervenBolleman committed Oct 18, 2023
1 parent 2b4c910 commit a2c3e0f
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 5 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>io.github.jervenbolleman</groupId>
<artifactId>handlegraph4j</artifactId>
<version>1.1-SNAPSHOT</version>
<version>1.1</version>
<packaging>jar</packaging>
<licenses>
<license>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -165,10 +165,11 @@ private static long binaryReverseComplement(long value) {

@Override
public String toString() {
return new String(asByteArray(), US_ASCII);
return new String(asAsciiBytes(), US_ASCII);
}

private byte[] asByteArray() {
@Override
public byte[] asAsciiBytes() {
byte[] val = new byte[length()];
for (int i = 0; i < length(); i++) {
val[i] = byteAt(i);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -211,13 +211,21 @@ static byte complement(byte nucleotide) {
* @return the IUPAC DNA coded sequence.
*/
default String asString() {
return new String(asAsciiBytes(), US_ASCII);
}

/**
* Convert the Sequence object into a java byte array of ascii
*
* @return the IUPAC DNA coded sequence.
*/
default byte[] asAsciiBytes() {
byte[] val = new byte[length()];
for (int i = 0; i < length(); i++) {
val[i] = byteAt(i);
}
return new String(val, US_ASCII);
return val;
}

/**
* Test if a String contains only known IUPAC codes
*
Expand Down

0 comments on commit a2c3e0f

Please sign in to comment.