Merge branch 'develop' into features/JAL-250_hideredundantseqs
[jalview.git] / test / jalview / analysis / AlignmentGenerator.java
@@ -51,9 +51,8 @@ import org.testng.annotations.BeforeClass;
  * @author gmcarstairs
  *
  */
-public class DnaAlignmentGenerator
+public class AlignmentGenerator
 {
-
   @BeforeClass(alwaysRun = true)
   public void setUpJvOptionPane()
   {
@@ -65,7 +64,11 @@ public class DnaAlignmentGenerator
 
   private static final char ZERO = '0';
 
-  private static final char[] BASES = new char[] { 'G', 'T', 'C', 'A' };
+  private static final char[] NUCS = "GTCA".toCharArray();
+
+  private static final char[] PEPS = "MILVFYWHKRDEQNTCGASNP".toCharArray();
+
+  private static char[] BASES;
 
   private Random random;
 
@@ -78,17 +81,19 @@ public class DnaAlignmentGenerator
    */
   public static void main(String[] args)
   {
-    if (args.length != 5)
+    if (args.length != 6)
     {
       usage();
       return;
     }
-    int width = Integer.parseInt(args[0]);
-    int height = Integer.parseInt(args[1]);
-    long randomSeed = Long.valueOf(args[2]);
-    int gapPercentage = Integer.valueOf(args[3]);
-    int changePercentage = Integer.valueOf(args[4]);
-    AlignmentI al = new DnaAlignmentGenerator().generate(width, height,
+    boolean nucleotide = args[0].toLowerCase().startsWith("n");
+    int width = Integer.parseInt(args[1]);
+    int height = Integer.parseInt(args[2]);
+    long randomSeed = Long.valueOf(args[3]);
+    int gapPercentage = Integer.valueOf(args[4]);
+    int changePercentage = Integer.valueOf(args[5]);
+    AlignmentI al = new AlignmentGenerator(nucleotide).generate(width,
+            height,
             randomSeed, gapPercentage, changePercentage);
 
     System.out.println("; " + height + " sequences of " + width
@@ -104,25 +109,26 @@ public class DnaAlignmentGenerator
   private static void usage()
   {
     System.out.println("Usage:");
-    System.out.println("arg0: number of (non-gap) bases per sequence");
-    System.out.println("arg1: number sequences");
+    System.out.println("arg0: n (for nucleotide) or p (for peptide)");
+    System.out.println("arg1: number of (non-gap) bases per sequence");
+    System.out.println("arg2: number sequences");
     System.out
-            .println("arg2: an integer as random seed (same seed = same results)");
-    System.out.println("arg3: percentage of gaps to (randomly) generate");
+            .println("arg3: an integer as random seed (same seed = same results)");
+    System.out.println("arg4: percentage of gaps to (randomly) generate");
     System.out
-            .println("arg4: percentage of 'mutations' to (randomly) generate");
-    System.out.println("Example: DnaAlignmentGenerator 12 15 387 10 5");
+            .println("arg5: percentage of 'mutations' to (randomly) generate");
+    System.out.println("Example: AlignmentGenerator n 12 15 387 10 5");
     System.out
-            .println("- 15 sequences of 12 bases each, approx 10% gaps and 5% mutations, random seed = 387");
+            .println("- 15 nucleotide sequences of 12 bases each, approx 10% gaps and 5% mutations, random seed = 387");
 
   }
 
   /**
-   * Default constructor
+   * Constructor that sets nucleotide or peptide symbol set
    */
-  public DnaAlignmentGenerator()
+  public AlignmentGenerator(boolean nuc)
   {
-
+    BASES = nuc ? NUCS : PEPS;
   }
 
   /**
@@ -168,7 +174,8 @@ public class DnaAlignmentGenerator
     for (int count = 0; count < length;)
     {
       boolean addGap = random.nextInt(100) < gapPercentage;
-      char c = addGap ? GAP : BASES[random.nextInt(Integer.MAX_VALUE) % 4];
+      char c = addGap ? GAP : BASES[random.nextInt(Integer.MAX_VALUE)
+              % BASES.length];
       seq.append(c);
       if (!addGap)
       {
@@ -277,7 +284,7 @@ public class DnaAlignmentGenerator
     char newchar = c;
     while (newchar == c)
     {
-      newchar = BASES[random.nextInt(Integer.MAX_VALUE) % 4];
+      newchar = BASES[random.nextInt(Integer.MAX_VALUE) % BASES.length];
     }
     return newchar;
   }