Skip to content

NucleotideSequence

Dan Katzel edited this page Jul 12, 2017 · 1 revision

Working With NucleotideSequences and NucleotideSequenceBuilders

This section deals with modifying a NucleotideSequence by using a NucleotideSequenceBuilder.

How to ungap a Sequence

If the sequence is already stored as a NucleotideSequence, you can either use the NucleotideSequenceBuilder constructor that takes a NucleotideSequence object new NucleotideSequenceBuilder( myseq) or as of Jillion 5, a new method on the NucleotideSequence object itself toBuilder() which will return a new builder instance:

NucleotideSequence originalSequence = ...
 
NucleotideSequence ungappedSequence = originalSequence.toBuilder()
				                    .ungap()
				                    .build();

If the sequence is a String, you must use the NucleotideSequenceBuilder constructor that takes a String object:

NucleotideSequence ungappedSequence = new NucleotideSequenceBuilder("AC-GT-AC-GT")
				                    .ungap()
				                    .build();
 
//ungappedSequence will now contain "ACGTACGT"

How to reverse complement a Sequence

NucleotideSequenceBuilders have a method called reverseComplement() which will reverse complement the current sequence stored in the builder. Any future additions to the sequence will not be auto-complemented.

NucleotideSequence complementedSeq = new NucleotideSequenceBuilder("AAAAGGGG")
  			                    .reverseComplement()
                                            .build();
 
//complementedSeq will now contain "CCCCTTTT"

How to perform multiple changes to a sequence

NucleotideSequenceBuilders use method chaining to allow users to write more intent revealing code:

NucleotideSequence seq = new NucleotideSequenceBuilder("AA--AAG-GG-G")
                                           .reverseComplement()
                                           .ungap()
                                           .append("NNNN")
                                           .build();
 
//seq will now contain "CCCCTTTTNNNN"

Clone this wiki locally