| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
package dr.evolution.io; |
| 27 |
|
| 28 |
import dr.evolution.alignment.Alignment; |
| 29 |
import dr.evolution.alignment.SimpleAlignment; |
| 30 |
import dr.evolution.datatype.DataType; |
| 31 |
import dr.evolution.sequence.Sequence; |
| 32 |
import dr.evolution.sequence.SequenceList; |
| 33 |
import dr.evolution.util.Taxon; |
| 34 |
|
| 35 |
import java.io.EOFException; |
| 36 |
import java.io.IOException; |
| 37 |
import java.io.Reader; |
| 38 |
import java.io.Writer; |
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
public class PhylipSequentialImporter extends Importer implements SequenceImporter { |
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
public PhylipSequentialImporter(Reader reader, DataType dataType, int maxNameLength) { |
| 54 |
super(reader); |
| 55 |
setCommentDelimiters('\0', '\0', '\0'); |
| 56 |
|
| 57 |
this.dataType = dataType; |
| 58 |
this.maxNameLength = maxNameLength; |
| 59 |
} |
| 60 |
|
| 61 |
public PhylipSequentialImporter(Reader reader, Writer commentWriter, DataType dataType, int maxNameLength) { |
| 62 |
super(reader, commentWriter); |
| 63 |
setCommentDelimiters('\0', '\0', '\0'); |
| 64 |
|
| 65 |
this.dataType = dataType; |
| 66 |
this.maxNameLength = maxNameLength; |
| 67 |
} |
| 68 |
|
| 69 |
|
| 70 |
|
| 71 |
|
| 72 |
public Alignment importAlignment() throws IOException, Importer.ImportException |
| 73 |
{ |
| 74 |
SimpleAlignment alignment = null; |
| 75 |
|
| 76 |
try { |
| 77 |
|
| 78 |
int taxonCount = readInteger(); |
| 79 |
int siteCount = readInteger(); |
| 80 |
|
| 81 |
String firstSeq = null; |
| 82 |
|
| 83 |
for (int i = 0; i < taxonCount; i++) { |
| 84 |
StringBuffer name = new StringBuffer(); |
| 85 |
|
| 86 |
char ch = read(); |
| 87 |
int n = 0; |
| 88 |
while (!Character.isWhitespace(ch) && (maxNameLength < 1 || n < maxNameLength)) { |
| 89 |
name.append(ch); |
| 90 |
ch = read(); |
| 91 |
n++; |
| 92 |
} |
| 93 |
|
| 94 |
StringBuffer seq = new StringBuffer(siteCount); |
| 95 |
readSequence(seq, dataType, "", siteCount, "-", "?", ".", firstSeq); |
| 96 |
|
| 97 |
if (firstSeq == null) { firstSeq = seq.toString(); } |
| 98 |
|
| 99 |
|
| 100 |
if (alignment == null) { |
| 101 |
alignment = new SimpleAlignment(); |
| 102 |
} |
| 103 |
|
| 104 |
alignment.addSequence(new Sequence(new Taxon(name.toString()), seq.toString())); |
| 105 |
} |
| 106 |
|
| 107 |
|
| 108 |
} catch (EOFException e) { } |
| 109 |
|
| 110 |
return alignment; |
| 111 |
} |
| 112 |
|
| 113 |
|
| 114 |
|
| 115 |
|
| 116 |
public SequenceList importSequences() throws IOException, ImportException { |
| 117 |
return importAlignment(); |
| 118 |
} |
| 119 |
|
| 120 |
private DataType dataType; |
| 121 |
private int maxNameLength = 10; |
| 122 |
} |