Create a discrete alphabet

From Jstacs
Revision as of 08:50, 6 June 2011 by Keilwagen (talk | contribs) (Created page with "'''Create a discrete alphabet:''' <source lang="java5"> String[] symbols = {"A", "C", "G", "T", "-"}; DiscreteAlphabet abc = new DiscreteAlphabet( true, symbols ); </source> '''...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigationJump to search

Create a discrete alphabet:

String[] symbols = {"A", "C", "G", "T", "-"};
DiscreteAlphabet abc = new DiscreteAlphabet( true, symbols );

Create a discrete alphabet that allows to build the reverse complement of a sequence:

int[] revComp = new int[symbols.length];
revComp[0] = 3; //symbols[0]^rc = symbols[3]
revComp[1] = 2; //symbols[1]^rc = symbols[2]
revComp[2] = 1; //symbols[2]^rc = symbols[1]
revComp[3] = 0; //symbols[3]^rc = symbols[0]
revComp[4] = 4; //symbols[4]^rc = symbols[4]

GenericComplementableDiscreteAlphabet abc2 = new GenericComplementableDiscreteAlphabet( true, symbols, revComp );

Test alphabet:

Sequence seq = Sequence.create( new AlphabetContainer( abc2 ), "ACGT-" );
Sequence rc = seq.reverseComplement();
System.out.println( seq );
System.out.println( rc );