From a2c3e0fae389008a5f72969e5d88e7c40f1def3d Mon Sep 17 00:00:00 2001 From: Jerven Bolleman Date: Wed, 18 Oct 2023 11:04:37 +0200 Subject: [PATCH] Add Squence asAsciiBytes method. --- pom.xml | 2 +- .../handlegraph4j/sequences/LongSequence.java | 5 +++-- .../handlegraph4j/sequences/Sequence.java | 12 ++++++++++-- 3 files changed, 14 insertions(+), 5 deletions(-) diff --git a/pom.xml b/pom.xml index 92ed3cc..517a4da 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ 4.0.0 io.github.jervenbolleman handlegraph4j - 1.1-SNAPSHOT + 1.1 jar diff --git a/src/main/java/io/github/jervenbolleman/handlegraph4j/sequences/LongSequence.java b/src/main/java/io/github/jervenbolleman/handlegraph4j/sequences/LongSequence.java index 0f4e0f9..37e36f9 100644 --- a/src/main/java/io/github/jervenbolleman/handlegraph4j/sequences/LongSequence.java +++ b/src/main/java/io/github/jervenbolleman/handlegraph4j/sequences/LongSequence.java @@ -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); diff --git a/src/main/java/io/github/jervenbolleman/handlegraph4j/sequences/Sequence.java b/src/main/java/io/github/jervenbolleman/handlegraph4j/sequences/Sequence.java index 363716a..5ff829f 100644 --- a/src/main/java/io/github/jervenbolleman/handlegraph4j/sequences/Sequence.java +++ b/src/main/java/io/github/jervenbolleman/handlegraph4j/sequences/Sequence.java @@ -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 *