Martin:

New to R.
This is one way we have been doing it:
One could save the alignment and convert to a XStringSet.
So taking the example from the help(pairwiseAlignment):

s1 <- DNAString("ACTTCACCAGCTCCCTGGCGGTAAGTTGATCAAAGGAAACGCAAAGTTTTCAAG")
s2 <- DNAString("GTTTCACTACTTCCTTTCGGGTAAGTAAATATATAAATATATAAAAATATAATTTTCATC")
mat <- nucleotideSubstitutionMatrix(match = 1, mismatch = -3, baseOnly = TRUE)
globalAlign <- pairwiseAlignment(s1, s2, substitutionMatrix = mat, gapOpening = -5, gapExtension = -2)

Next, collect the DNAStrings in the pairwise alignment:

r = BStringSet( c( toString( subject(globalAlign) ), toString( pattern(globalAlign))))

Then, write the alignment to a text file:

write.XStringSet(r,"out1.txt")

Alternatively, if the sequence is not too long, one can increase the size of the window, and it may show all of the sequence that you need.

A colleague wrote a script to do this on a large file of sequences where we need to do pairwise alignment on a short stretch of DNA sequence repetitively. So he really deserves the credit for this. (Note: the alignment score is not collected). It is a fasta file, that can also be read by fasta readers.

Hope this helps,
Cheers,
Charles


--
Charles C. Chu, PhD
Associate Investigator
The Feinstein Institute for Medical Research
North Shore-Long Island Jewish Health System
350 Community Drive
Manhasset, NY   11030
Telephone: (516) 562-1207
FAX:       (516) 562-1322
Email:     cchu@nshs.edu




On 4/13/12 11:24 AM, "Martin Preusse" <martin.preusse@googlemail.com> wrote:

I do a simple pairwise DNA sequence alignment with pairwiseAlignment from the Biostrings package in Bioconductor:

library('Biostrings')
seq1 = 'ATGCTA'
seq2 = 'ATGTA'
pairwiseAlignment(pattern = seq1, subject = seq2)

The output looks as follows:

Global PairwiseAlignedFixedSubject (1 of 1)
pattern: [1] ATGCTA
subject: [1] ATG-TA
score: -4.091219

For very long sequences, the output is truncated and only one line is shown:

Global PairwiseAlignedFixedSubject (1 of 1)
pattern: [1] AT-----------------------------...----------------TGTCTTCCAKATCTGGCGCGCCTGGGTTGATATC
subject: [1] ATTGGCGGCCGCGCCACCATGCCAGAGCCAG...GAAGGCTGTATGCTGTTGTCTTCAAGATCTGGTACCGCTGGGTTGATATC
score: -29418.8

How can I output the complete alignment to a text file?

Cheers,
Martin

_______________________________________________
Bioconductor mailing list
Bioconductor@r-project.org
https://stat.ethz.ch/mailman/listinfo/bioconductor
Search the archives: http://news.gmane.org/gmane.science.biology.informatics.conductor




The information contained in this electronic e-mail transmission and any attachments are intended only for the use of the individual or entity to whom or to which it is addressed, and may contain information that is privileged, confidential and exempt from disclosure under applicable law. If the reader of this communication is not the intended recipient, or the employee or agent responsible for delivering this communication to the intended recipient, you are hereby notified that any dissemination, distribution, copying or disclosure of this communication and any attachment is strictly prohibited. If you have received this transmission in error, please notify the sender immediately by telephone and electronic mail, and delete the original communication and any attachment from any computer, server or other electronic recording or storage device or medium. Receipt by anyone other than the intended recipient is not a waiver of any attorney-client, physician-patient or other privilege.
	[[alternative HTML version deleted]]

