1 package jalview.analysis;
3 import java.util.Random;
6 * Generates a random Fasta format DNA alignment for given sequence length and
12 public class DnaAlignmentGenerator
14 private static final char GAP = '-';
16 private static final char[] BASES = new char[]
17 { 'G', 'T', 'C', 'A', GAP };
19 private Random random;
22 * Given args for sequence length and count, output a DNA 'alignment' where
23 * each position is a random choice from 'GTCA-'.
26 * the width (base count) and height (sequence count) to generate
27 * plus an integer random seed value
29 public static void main(String[] args)
31 int width = Integer.parseInt(args[0]);
32 int height = Integer.parseInt(args[1]);
33 long randomSeed = Long.valueOf(args[2]);
34 new DnaAlignmentGenerator().generate(width, height, randomSeed);
38 * Outputs a DNA 'alignment' of given width and height, where each position is
39 * a random choice from 'GTCA-'.
45 private void generate(int width, int height, long randomSeed)
47 random = new Random(randomSeed);
48 for (int seqno = 0; seqno < height; seqno++)
50 generateSequence(seqno + 1, width);
55 * Outputs a DNA 'sequence' of given length, with some random gaps included.
60 private void generateSequence(int seqno, int length)
62 System.out.println(">SEQ" + seqno);
63 StringBuilder seq = new StringBuilder(length);
66 * Loop till we've output 'length' real bases (excluding gaps)
68 for (int count = 0 ; count < length ; ) {
69 char c = BASES[random.nextInt(Integer.MAX_VALUE) % 5];
76 System.out.println(seq.toString());