2 * Jalview - A Sequence Alignment Editor and Viewer (Version 2.8.0b1)
3 * Copyright (C) 2014 The Jalview Authors
5 * This file is part of Jalview.
7 * Jalview is free software: you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
11 * Jalview is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty
13 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
14 * PURPOSE. See the GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License along with Jalview. If not, see <http://www.gnu.org/licenses/>.
17 * The Jalview Authors are detailed in the 'AUTHORS' file.
21 import jalview.datamodel.AlignmentI;
22 import jalview.datamodel.Sequence;
23 import jalview.datamodel.SequenceI;
25 import java.io.IOException;
26 import java.util.LinkedHashMap;
28 import java.util.Map.Entry;
32 * A parser for input or output of MEGA format files. <br>
34 * Tamura K, Stecher G, Peterson D, Filipski A, and Kumar S (2013) MEGA6:
35 * Molecular Evolutionary Genetics Analysis Version 6.0. Molecular Biology and
36 * Evolution 30: 2725-2729. <br>
39 * MEGA file format is supported as described in
40 * http://www.megasoftware.net/manual.pdf <br>
43 * <li>nested comments (marked by [ ]) are accepted but not preserved</li>
44 * <li>to be completed</li>
47 * @see http://www.megasoftware.net/
49 public class MegaFile extends AlignFile
51 private static final int DEFAULT_LINE_LENGTH = 60;
53 private static final String INDENT = " ";
55 private static final String N_SITES = "NSites";
57 private static final String N_SEQS = "NSeqs";
59 private static final String MISSING = "Missing";
61 private static final String IDENTICAL = "Identical";
63 private static final String INDEL = "Indel";
65 private static final String CODETABLE = "CodeTable";
67 private static final String PROTEIN = "Protein";
69 private static final String NUCLEOTIDE = "Nucleotide";
71 private static final String DATATYPE = "DataType";
73 private static final char COMMENT_START = '[';
75 private static final char COMMENT_END = ']';
77 private static final String HASHSIGN = "#";
79 private static final String SEMICOLON = ";";
81 private static final String BANG = "!";
83 private static final String EQUALS = "=";
85 private static final String MEGA_ID = HASHSIGN + "MEGA";
87 private static final String TITLE = "Title";
89 private static final String FORMAT = "Format";
91 private static final String DESCRIPTION = "Description";
93 private static final String GENE = "Gene";
95 private static final String DOMAIN = "Domain";
98 * names of properties to save to the alignment (may affect eventual output
101 static final String PROP_TITLE = "MEGA_TITLE";
103 static final String PROP_INTERLEAVED = "MEGA_INTERLEAVED";
105 static final String PROP_DESCRIPTION = "MEGA_DESCRIPTION";
107 static final String PROP_CODETABLE = "MEGA_CODETABLE";
109 static final String PROP_IDENTITY = "MEGA_IDENTITY";
111 static final String PROP_MISSING = "MEGA_MISSING";
113 static final String PROP_DATATYPE = "MEGA_DATATYPE";
115 // number of bases per line of file (value is inferred)
116 static final String PROP_LINELENGTH = "MEGA_LINELENGTH";
118 // TODO: need a controlled name for Gene as a feature if we want to be able to
119 // output the MEGA file with !Gene headers
120 // WTF do we do if the sequences get realigned?
122 // initial size for sequence data buffer
123 private static final int SEQBUFFERSIZE = 256;
125 private static final String SPACE = " ";
128 * number of sequence positions output per line
130 private int positionsPerLine;
132 private String title;
134 // gap character may be explicitly declared, if not we infer it
135 private Character gapCharacter;
137 // this can be True, False or null (meaning not asserted in file)
138 private Boolean nucleotide;
140 // set once we have seen one block of interleaved data
141 private boolean firstDataBlockRead = false;
143 // this can be True, False or null (meaning we don't know yet)
144 private Boolean interleaved;
150 public MegaFile(String inFile, String type) throws IOException
155 public MegaFile(FileParse source) throws IOException
161 * Parse the input stream.
164 public void parse() throws IOException
167 * Read and process MEGA and Title/Format/Description headers if present.
168 * Returns the first data line following the headers.
170 String dataLine = parseHeaderLines();
173 * Temporary store of {sequenceId, positionData} while parsing interleaved
174 * sequences; sequences are maintained in the order in which they are added
175 * i.e. read in the file
177 Map<String, StringBuilder> seqData = new LinkedHashMap<String, StringBuilder>();
180 * The id of the sequence being read (for non-interleaved)
182 String currentId = "";
184 while (dataLine != null)
186 dataLine = dataLine.trim();
187 if (dataLine.length() > 0)
189 if (dataLine.startsWith(BANG + GENE))
193 else if (dataLine.startsWith(BANG + DOMAIN))
195 parseDomain(dataLine);
199 currentId = parseDataLine(dataLine, seqData, currentId);
202 else if (!seqData.isEmpty())
205 * Blank line after processing some data...
207 this.firstDataBlockRead = true;
209 dataLine = nextNonCommentLine();
212 // remember the (longest) line length read in, so we can output the same
213 setAlignmentProperty(PROP_LINELENGTH, String.valueOf(positionsPerLine));
215 setSequences(seqData);
219 * Parse a !Gene command line
223 protected void parseGene(String dataLine)
228 * Parse a !Domain command line
232 private void parseDomain(String dataLine)
237 * Returns the next line that is not a comment, or null at end of file.
238 * Comments in MEGA are within [ ] brackets, and may be nested.
241 * @throws IOException
243 protected String nextNonCommentLine() throws IOException
245 return nextNonCommentLine(0);
249 * Returns the next line that is not a comment, or null at end of file.
250 * Comments in MEGA are within [ ] brackets, and may be nested.
253 * current depth of nesting of comments while parsing
255 * @throws IOException
257 protected String nextNonCommentLine(final int depth) throws IOException
265 System.err.println("Warning: unterminated comment in data file");
269 int leftBracket = data.indexOf(COMMENT_START);
272 * reject unnested comment following data on the same line
274 if (depth == 0 && leftBracket > 0)
276 throw new FileFormatException(
277 "Can't parse comment following data at " + data);
281 * If we are in a (possibly nested) comment after parsing this line, keep
282 * reading recursively until the comment has unwound
284 int newDepth = commentDepth(data, depth);
287 return nextNonCommentLine(newDepth);
292 * not in a comment by end of this line; return what is left (or the next
293 * line if that is empty)
295 String nonCommentPart = getNonCommentContent(data, depth);
296 // if (nonCommentPart.length() > 0)
298 return nonCommentPart;
300 // return nextNonCommentLine(0);
305 * Returns what is left of the input data after removing any comments, whether
306 * 'in progress' from preceding lines, or embedded in the current line
311 * nested depth of comments pending termination
313 * @throws FileFormatException
315 protected static String getNonCommentContent(String data, int depth)
316 throws FileFormatException
318 int len = data.length();
319 StringBuilder result = new StringBuilder(len);
320 for (int i = 0; i < len; i++)
322 char c = data.charAt(i);
347 return result.toString();
351 * Calculates new depth of comment after parsing an input line i.e. the excess
352 * of opening '[' over closing ']' characters. Any excess ']' are ignored (not
353 * treated as comment delimiters).
358 * current comment nested depth before parsing the line
359 * @return new depth after parsing the line
361 protected static int commentDepth(CharSequence data, int depth)
363 int newDepth = depth;
364 int len = data.length();
365 for (int i = 0; i < len; i++)
367 char c = data.charAt(i);
368 if (c == COMMENT_START)
372 else if (c == COMMENT_END && newDepth > 0)
381 * Convert the parsed sequence strings to objects and store them in the model.
385 protected void setSequences(Map<String, StringBuilder> seqData)
387 Set<Entry<String, StringBuilder>> datasets = seqData.entrySet();
389 for (Entry<String, StringBuilder> dataset : datasets)
391 String sequenceId = dataset.getKey();
392 StringBuilder characters = dataset.getValue();
393 SequenceI s = new Sequence(sequenceId, new String(characters));
394 this.seqs.addElement(s);
399 * Process one line of sequence data. If it has no sequence identifier, append
400 * to the current id's sequence. Else parse out the sequence id and append the
401 * data (if any) to that id's sequence. Returns the sequence id (implicit or
402 * explicit) for this line.
408 * @throws IOException
410 protected String parseDataLine(String dataLine,
411 Map<String, StringBuilder> seqData, String currentId)
414 String seqId = getSequenceId(dataLine);
418 * Just character data
420 parseNoninterleavedDataLine(dataLine, seqData, currentId);
423 else if ((HASHSIGN + seqId).trim().equals(dataLine.trim()))
426 * Sequence id only - header line for noninterleaved data
433 * Sequence id followed by data
435 parseInterleavedDataLine(dataLine, seqData, seqId);
441 * Add a line of sequence data to the buffer for the given sequence id. Start
442 * a new one if we haven't seen it before.
447 * @throws IOException
449 protected void parseNoninterleavedDataLine(String dataLine,
450 Map<String, StringBuilder> seqData, String currentId)
453 if (currentId == null)
456 * Oops. Data but no sequence id context.
458 throw new IOException("No sequence id context at: " + dataLine);
461 assertInterleaved(false, dataLine);
463 StringBuilder sb = getSequenceDataBuffer(seqData, currentId);
466 * Add the current line of data to the sequence.
470 setPositionsPerLine(Math.max(positionsPerLine, dataLine.length()));
474 * Get the sequence data for this sequence id, starting a new one if
481 protected StringBuilder getSequenceDataBuffer(
482 Map<String, StringBuilder> seqData, String currentId)
484 StringBuilder sb = seqData.get(currentId);
487 // first data met for this sequence id, start a new buffer
488 sb = new StringBuilder(SEQBUFFERSIZE);
489 seqData.put(currentId, sb);
495 * Parse one line of interleaved data e.g.
498 * #TheSeqId CGATCGCATGCA
504 * @throws IOException
506 protected void parseInterleavedDataLine(String dataLine,
507 Map<String, StringBuilder> seqData, String seqId)
511 * New sequence found in second or later data block - error.
513 if (this.firstDataBlockRead && !seqData.containsKey(seqId))
515 throw new IOException(
516 "Parse error: misplaced new sequence starting at " + dataLine);
519 StringBuilder sb = getSequenceDataBuffer(seqData, seqId);
520 String data = dataLine.substring(seqId.length() + 1).trim();
523 * Do nothing if this line is _only_ a sequence id with no data following.
525 * Remove any internal spaces
527 if (data != null && data.length() > 0)
529 if (data.indexOf(SPACE) != -1)
531 data = data.replace(SPACE, "");
534 setPositionsPerLine(Math.max(positionsPerLine, data.length()));
535 assertInterleaved(true, dataLine);
540 * If the line begins with (e.g.) "#abcde " then returns "abcde" as the
541 * identifier. Else returns null.
546 public static String getSequenceId(String dataLine)
548 // TODO refactor to a StringUtils type class
549 if (dataLine != null)
551 if (dataLine.startsWith(HASHSIGN))
553 int spacePos = dataLine.indexOf(" ");
554 return (spacePos == -1 ? dataLine.substring(1) : dataLine
555 .substring(1, spacePos));
562 * Read the #MEGA and Title/Format/Description header lines (if present).
564 * Save as alignment properties in case useful.
566 * @return the next non-blank line following the header lines.
567 * @throws IOException
569 protected String parseHeaderLines() throws IOException
571 String inputLine = null;
572 while ((inputLine = nextNonCommentLine()) != null)
574 inputLine = inputLine.trim();
579 if (inputLine.length() == 0)
584 if (inputLine.toUpperCase().startsWith(MEGA_ID))
589 if (isTitle(inputLine))
591 this.title = getValue(inputLine);
592 setAlignmentProperty(PROP_TITLE, title);
594 else if (inputLine.startsWith(BANG + DESCRIPTION))
596 parseDescription(inputLine);
599 else if (inputLine.startsWith(BANG + FORMAT))
601 parseFormat(inputLine);
603 else if (!inputLine.toUpperCase().startsWith(MEGA_ID))
607 * Return the first 'data line' i.e. one that is not blank, #MEGA or
617 * Parse a !Format statement. This may be multiline, and is ended by a
621 * @throws IOException
623 protected void parseFormat(String inputLine) throws IOException
625 while (inputLine != null)
627 parseFormatLine(inputLine);
628 if (inputLine.endsWith(SEMICOLON))
632 inputLine = nextNonCommentLine();
637 * Parse one line of a !Format statement. This may contain one or more
638 * keyword=value pairs.
641 * @throws FileFormatException
643 protected void parseFormatLine(String inputLine)
644 throws FileFormatException
646 if (inputLine.startsWith(BANG + FORMAT))
648 inputLine = inputLine.substring((BANG + FORMAT).length());
650 if (inputLine.endsWith(SEMICOLON))
652 inputLine = inputLine.substring(0, inputLine.length() - 1);
654 if (inputLine.length() == 0)
658 String[] tokens = inputLine.trim().split("\\s"); // any whitespace
659 for (String token : tokens)
661 parseFormatKeyword(token);
666 * Parse a Keyword=Value token. Possible keywords are
668 * <li>DataType= DNA, RNA, Nucleotide, Protein</li>
669 * <li>DataFormat= Interleaved, ?</li>
670 * <li>NSeqs= number of sequences (synonym NTaxa)</li>
671 * <li>NSites= number of bases / residues</li>
672 * <li>Property= Exon (or Coding), Intron (or Noncoding), End (of domain)</li>
673 * <li>Indel= gap character</li>
674 * <li>Identical= identity character (to first sequence) (synonym MatchChar)</li>
675 * <li>Missing= missing data character</li>
676 * <li>CodeTable= Standard, other (MEGA supports various)</li>
680 * @throws FileFormatException
681 * if an unrecognised keyword or value is encountered
683 protected void parseFormatKeyword(String token)
684 throws FileFormatException
686 String msg = "Unrecognised Format command: " + token;
687 String[] bits = token.split(EQUALS);
688 if (bits.length != 2)
690 throw new FileFormatException(msg);
692 String keyword = bits[0];
693 String value = bits[1];
696 * Jalview will work out whether nucleotide or not anyway
698 if (keyword.equalsIgnoreCase(DATATYPE))
700 if (value.equalsIgnoreCase("DNA") || value.equalsIgnoreCase("RNA")
701 || value.equalsIgnoreCase("Nucleotide"))
703 this.nucleotide = true;
704 // alignment computes whether or not it is nucleotide when created
706 else if (value.equalsIgnoreCase(PROTEIN))
708 this.nucleotide = false;
712 throw new FileFormatException(msg);
714 setAlignmentProperty(PROP_DATATYPE, value);
718 * accept non-Standard code table but save in case we want to disable
719 * 'translate as cDNA'
721 else if (keyword.equalsIgnoreCase(CODETABLE))
723 setAlignmentProperty(PROP_CODETABLE, value);
727 * save gap char to set later on alignment once created
729 else if (keyword.equalsIgnoreCase(INDEL))
731 this.gapCharacter = value.charAt(0);
734 else if (keyword.equalsIgnoreCase(IDENTICAL)
735 || keyword.equalsIgnoreCase("MatchChar"))
737 setAlignmentProperty(PROP_IDENTITY, value);
738 if (!".".equals(value))
740 System.err.println("Warning: " + token
741 + " not supported, Jalview uses '.' for identity");
745 else if (keyword.equalsIgnoreCase(MISSING))
747 setAlignmentProperty(PROP_MISSING, value);
748 System.err.println("Warning: " + token + " not supported");
751 else if (keyword.equalsIgnoreCase("Property"))
753 // TODO: figure out what to do with this
754 // can it appear more than once in a file?
755 setAlignmentProperty(PROP_MISSING, value);
758 else if (!keyword.equalsIgnoreCase(N_SEQS)
759 && !keyword.equalsIgnoreCase(N_SITES))
761 System.err.println("Warning: " + msg);
766 * Returns the trimmed data on the line following either whitespace or '=',
767 * with any trailing semi-colon removed<br>
770 * <li>Hello World</li>
771 * <li>!Hello: \tWorld;</li>
772 * <li>!Hello=World</li>
774 * should all return "World"
779 protected static String getValue(String inputLine)
781 if (inputLine == null)
786 String s = inputLine.replaceAll("\t", " ").trim();
789 * KEYWORD = VALUE should return VALUE
791 int equalsPos = s.indexOf("=");
794 value = s.substring(equalsPos + 1);
798 int spacePos = s.indexOf(' ');
799 value = spacePos == -1 ? "" : s.substring(spacePos + 1);
801 value = value.trim();
802 if (value.endsWith(SEMICOLON))
804 value = value.substring(0, value.length() - 1).trim();
810 * Returns true if the input line starts with "TITLE" or "!TITLE" (not case
811 * sensitive). The latter is the official format, some older data file
812 * examples have it without the !.
817 protected static boolean isTitle(String inputLine)
819 if (inputLine == null)
823 String upper = inputLine.toUpperCase();
824 return (upper.startsWith(TITLE.toUpperCase()) || upper.startsWith(BANG
825 + TITLE.toUpperCase()));
829 * Reads lines until terminated by semicolon, appending each to the
830 * Description property value.
832 * @throws IOException
834 protected void parseDescription(String firstDescriptionLine)
837 StringBuilder desc = new StringBuilder(256);
838 String line = getValue(firstDescriptionLine);
841 if (line.endsWith(SEMICOLON))
843 desc.append(line.substring(0, line.length() - 1));
846 else if (line.length() > 0)
848 desc.append(line).append(newline);
850 line = nextNonCommentLine();
852 setAlignmentProperty(PROP_DESCRIPTION, desc.toString());
856 * Returns the alignment sequences in Mega format.
859 public String print()
861 return MEGA_ID + newline + print(getSeqsAsArray());
865 * Write out the alignment sequences in Mega format - interleaved unless
866 * explicitly noninterleaved.
868 protected String print(SequenceI[] s)
871 if (this.interleaved != null && !this.interleaved)
873 result = printNonInterleaved(s);
877 result = printInterleaved(s);
883 * Print to string in Interleaved format - blocks of next N characters of each
888 protected String printInterleaved(SequenceI[] s)
890 int maxIdLength = getMaxIdLength(s);
891 int maxSequenceLength = getMaxSequenceLength(s);
892 int numLines = maxSequenceLength / positionsPerLine + 3; // approx
895 * Size a buffer to hold the whole output
897 StringBuilder sb = new StringBuilder(numLines
898 * (maxIdLength + 2 + positionsPerLine));
900 int numDataBlocks = (maxSequenceLength - 1) / positionsPerLine + 1;
901 int spaceEvery = this.nucleotide != null && this.nucleotide ? 3 : 10;
902 int chunksPerLine = (positionsPerLine + spaceEvery - 1) / spaceEvery;
905 * Output as: #Seqid CGT AGC ACT ... or blocks of 10 for peptide
908 for (int i = 0; i < numDataBlocks; i++)
911 boolean first = true;
913 for (SequenceI seq : s)
916 String seqId = String.format("#%-" + maxIdLength + "s",
920 * output next line for this sequence
923 int lastPos = seqFrom + positionsPerLine; // exclusive
924 for (int j = 0; j < chunksPerLine; j++)
926 char[] subSequence = seq.getSequence(seqFrom,
927 Math.min(lastPos, seqFrom + spaceEvery));
928 if (subSequence.length > 0)
930 sb.append(SPACE).append(subSequence);
932 seqFrom += subSequence.length;
935 // all sequences should be the same length in MEGA
936 advancedBy += subSequence.length;
945 return new String(sb);
949 * Outputs to string the MEGA header and any other known and relevant
950 * alignment properties
954 protected String printHeaders(AlignmentI al)
956 StringBuilder sb = new StringBuilder(128);
957 sb.append(MEGA_ID).append(newline);
958 String propertyValue = (String) al.getProperty(PROP_TITLE);
959 if (propertyValue != null)
961 sb.append(BANG).append(TITLE).append(SPACE)
962 .append(propertyValue)
966 propertyValue = (String) al.getProperty(PROP_DESCRIPTION);
967 if (propertyValue != null)
969 sb.append(BANG).append(DESCRIPTION).append(newline)
970 .append(propertyValue).append(SEMICOLON)
975 * !Format DataType CodeTable
977 sb.append(BANG).append(FORMAT).append(newline);
978 String dataType = (String) al.getProperty(PROP_DATATYPE);
979 if (dataType == null)
981 dataType = al.isNucleotide() ? NUCLEOTIDE : PROTEIN;
983 sb.append(INDENT).append(DATATYPE).append(EQUALS).append(dataType);
984 String codeTable = (String) al.getProperty(PROP_CODETABLE);
985 sb.append(SPACE).append(CODETABLE).append(EQUALS)
986 .append(codeTable == null ? "Standard" : codeTable)
990 * !Format NSeqs NSites
991 * NSites the length of any sequence (they should all be the same), excluding
994 sb.append(INDENT).append(N_SEQS).append(EQUALS).append(al.getHeight());
995 SequenceI seq = al.getSequenceAt(0);
996 sb.append(SPACE).append(N_SITES).append(EQUALS)
997 .append(seq.getEnd() - seq.getStart() + 1);
1001 * !Format Indel Identical Missing
1004 sb.append(INDEL).append(EQUALS).append(al.getGapCharacter());
1005 String identity = (String) al.getProperty(PROP_IDENTITY);
1006 if (identity != null)
1008 sb.append(SPACE).append(IDENTICAL).append(EQUALS).append(identity);
1010 String missing = (String) al.getProperty(PROP_MISSING);
1011 if (missing != null)
1013 sb.append(SPACE).append(MISSING).append(EQUALS).append(missing);
1015 sb.append(SEMICOLON).append(newline);
1017 return sb.toString();
1021 * Get the longest sequence id (to allow aligned printout).
1026 protected static int getMaxIdLength(SequenceI[] s)
1028 // TODO pull up for reuse
1030 for (SequenceI seq : s)
1032 int len = seq.getName().length();
1033 if (len > maxLength)
1042 * Get the longest sequence length
1047 protected static int getMaxSequenceLength(SequenceI[] s)
1049 // TODO pull up for reuse
1051 for (SequenceI seq : s)
1053 int len = seq.getLength();
1054 if (len > maxLength)
1063 * Print to string in noninterleaved format - all of each sequence in turn, in
1064 * blocks of 50 characters.
1069 protected String printNonInterleaved(SequenceI[] s)
1071 int maxSequenceLength = getMaxSequenceLength(s);
1073 int numLines = maxSequenceLength / positionsPerLine + 2 + s.length;
1076 * Roughly size a buffer to hold the whole output
1078 StringBuilder sb = new StringBuilder(numLines * positionsPerLine);
1080 int spaceEvery = this.nucleotide != null && this.nucleotide ? 3 : 10;
1081 int chunksPerLine = positionsPerLine / spaceEvery;
1082 for (SequenceI seq : s)
1085 sb.append(HASHSIGN + seq.getName()).append(newline);
1087 while (startPos < seq.getLength())
1089 boolean firstChunk = true;
1091 * print next line for this sequence
1093 int lastPos = startPos + positionsPerLine; // exclusive
1094 for (int j = 0; j < chunksPerLine; j++)
1096 char[] subSequence = seq.getSequence(startPos,
1097 Math.min(lastPos, startPos + positionsPerLine));
1098 if (subSequence.length > 0)
1104 sb.append(subSequence);
1107 startPos += subSequence.length;
1113 return new String(sb);
1117 * Flag this file as interleaved or not, based on data format. Throws an
1118 * exception if has previously been determined to be otherwise.
1122 * @throws IOException
1124 protected void assertInterleaved(boolean isIt, String dataLine)
1125 throws FileFormatException
1127 if (this.interleaved != null && isIt != this.interleaved.booleanValue())
1129 throw new FileFormatException(
1130 "Parse error: mix of interleaved and noninterleaved detected, at line: "
1133 this.interleaved = new Boolean(isIt);
1134 setAlignmentProperty(PROP_INTERLEAVED, interleaved.toString());
1137 public boolean isInterleaved()
1139 return this.interleaved == null ? false : this.interleaved
1144 * Adds saved parsed values either as alignment properties, or (in some cases)
1145 * as specific member fields of the alignment
1148 public void addProperties(AlignmentI al)
1150 super.addProperties(al);
1151 if (this.gapCharacter != null)
1153 al.setGapCharacter(gapCharacter);
1157 * warn if e.g. DataType=DNA but data is protein (or vice versa)
1159 if (this.nucleotide != null && this.nucleotide != al.isNucleotide()) {
1160 System.err.println("Warning: " + this.title + " declared "
1161 + (nucleotide ? "" : " not ") + "nucleotide but it is"
1162 + (nucleotide ? " not" : ""));
1167 * Print the given alignment in MEGA format. If the alignment was created by
1168 * parsing a MEGA file, it should have properties set (e.g. Title) which can
1169 * influence the output.
1172 public String print(AlignmentI al)
1174 this.nucleotide = al.isNucleotide();
1175 String lineLength = (String) al.getProperty(PROP_LINELENGTH);
1176 this.positionsPerLine = lineLength == null ? DEFAULT_LINE_LENGTH : Integer
1177 .parseInt(lineLength);
1178 return printHeaders(al) + print(al.getSequencesArray());
1182 * Returns the number of sequence positions output per line
1186 public int getPositionsPerLine()
1188 return positionsPerLine;
1192 * Sets the number of sequence positions output per line. Note these will be
1193 * formatted in blocks of 3 (nucleotide) or 10 (peptide).
1197 public void setPositionsPerLine(int p)
1199 this.positionsPerLine = p;