Consensus Output From Command Line

Hi folks,

I am trying to obtain the consensus sequence from over 100 alignments. I would like a single fasta line for each of my alignments. Obviously this is a pain to do by hand. I have been trying to use the script provided with a command line call to OS X application, but can not seem to get a single line output. Can someone please help me?
Here is my input code:
open /Applications/Jalview.app --args -open ~/GC_00000008_sequences.fa -groovy ~/groovy_consensus.txt -nodisplay -fasta ~/GC8.txt
groovy_consensus.txt is:
// export a consensus sequence

def alf = Jalview.getAlignFrames();
for (ala in alf)
{
// ala is an jalview.gui.AlignFrame object
jalview.datamodel.SequenceI seq = ala.viewport.getConsensusSeq();

print new jalview.io.FastaFile().print(((jalview.datamodel.SequenceI[]) [ seq ]),false)+"\n";

}

Thanks in advance!

Hi there ! It might be better to use a groovy script to loop through your alignments rather than run jalview on each one. That will be much faster, since the jvm will have warmed up after the first couple of alignments.

I’ll post a script in a bit…

I’ve just taken a closer look at your script and realised you are encountering a problem caused by the Jalview application redirecting standard output to its log file (/Applications/Jalview.app/Contents/Resources/app/launcher.log).

Simplest solution is to simply write a new file:
// export a consensus sequence

File output = new File("~/output.consensus.fa")

// nb here you could also use currentAlFrame - only set for groovy scripts during command line execution

def alf = Jalview.getAlignFrames();
for (ala in alf)
{
// ala is an jalview.gui.AlignFrame object
jalview.datamodel.SequenceI seq = ala.viewport.getConsensusSeq();

output.write(new jalview.io.FastaFile().print(((jalview.datamodel.SequenceI[]) [ seq ]),false)+"\n");

}