将(原位)人类可读的DNA序列转换为内部0..4字节。
/* from n o w j a v a . c o m - 时代Java*/ /* * Copyright (c) 2014. Real Time Genomics Limited. * * Use of this source code is bound by the Real Time Genomics Limited Software Licence Agreement * for Academic Non-commercial Research Purposes only. * * If you did not receive a license accompanying this file, a copy must first be obtained by email * from support@realtimegenomics.com. On downloading, using and/or continuing to use this source * code you accept the terms of that license agreement and any amendments to those terms that may * be made from time to time by Real Time Genomics Limited. */ //package com.nowjava; public class Main { /** * Transform (in-situ) a human-readable DNA sequence into internal 0..4 bytes. * @param a Eg. {'a','c','g','t','n'} will become {1,2,3,4,0}. * @param length length to convert * @return the encoded array (which will be the same array as <code>a</code>) */ public static byte[] encodeArray(final byte[] a, final int length) { for (int k = 0; k < length; k++) { switch (a[k]) { case (byte) 'a': case (byte) 'A': a[k] = 1; break; case (byte) 'c':/* 来 自 时代Java*/ case (byte) 'C': a[k] = 2; break; case (byte) 'g': case (byte) 'G': a[k] = 3; break; case (byte) 't': case (byte) 'T': a[k] = 4; break; default: a[k] = 0; break; } } return a; }