Added setName() and getName() (however, not used anywhere yet). Now can set the name of the fasta record manually to whatever, however it will work only if done early enough. If the fasta record already started printing itself (i.e. the header line is already done), setName() will throw an exception. Could be too entangled, may reverse this back...
git-svn-id: file:///humgen/gsa-scr1/gsa-engineering/svn_contents/trunk@1493 348d0f76-0448-11de-a6fe-93d51630548a
This commit is contained in:
parent
c9eb193c7f
commit
591f8eedbb
|
|
@ -1,6 +1,7 @@
|
||||||
package org.broadinstitute.sting.playground.gatk.walkers.fasta;
|
package org.broadinstitute.sting.playground.gatk.walkers.fasta;
|
||||||
|
|
||||||
import org.broadinstitute.sting.utils.GenomeLoc;
|
import org.broadinstitute.sting.utils.GenomeLoc;
|
||||||
|
import org.broadinstitute.sting.utils.StingException;
|
||||||
|
|
||||||
import java.io.PrintStream;
|
import java.io.PrintStream;
|
||||||
|
|
||||||
|
|
@ -12,11 +13,22 @@ public class FastaSequence {
|
||||||
private StringBuffer sb = new StringBuffer();
|
private StringBuffer sb = new StringBuffer();
|
||||||
private long sequenceCounter = 1;
|
private long sequenceCounter = 1;
|
||||||
private boolean printedHeader = false;
|
private boolean printedHeader = false;
|
||||||
|
private String name = null;
|
||||||
|
|
||||||
public FastaSequence(PrintStream out) {
|
public FastaSequence(PrintStream out) {
|
||||||
this.out = out;
|
this.out = out;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setName(String name) {
|
||||||
|
if ( printedHeader ) throw new StingException("Can not set name for FASTA record: header is already printed.");
|
||||||
|
this.name = name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getName() {
|
||||||
|
if ( name != null ) return name;
|
||||||
|
else return getCurrentID();
|
||||||
|
}
|
||||||
|
|
||||||
public void append(String s) {
|
public void append(String s) {
|
||||||
sb.append(s);
|
sb.append(s);
|
||||||
printFasta(false);
|
printFasta(false);
|
||||||
|
|
@ -25,6 +37,7 @@ public class FastaSequence {
|
||||||
public void flush() {
|
public void flush() {
|
||||||
printFasta(true);
|
printFasta(true);
|
||||||
printedHeader = false;
|
printedHeader = false;
|
||||||
|
name = null;
|
||||||
sequenceCounter++;
|
sequenceCounter++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -36,7 +49,8 @@ public class FastaSequence {
|
||||||
if ( sb.length() == 0 || (!printAll && sb.length() < 60) )
|
if ( sb.length() == 0 || (!printAll && sb.length() < 60) )
|
||||||
return;
|
return;
|
||||||
if ( !printedHeader ) {
|
if ( !printedHeader ) {
|
||||||
out.println(">" + sequenceCounter);
|
if ( name == null ) out.println(">" + sequenceCounter);
|
||||||
|
else out.println(">" + name);
|
||||||
printedHeader = true;
|
printedHeader = true;
|
||||||
}
|
}
|
||||||
int lines = sb.length() / 60;
|
int lines = sb.length() / 60;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue