From 591f8eedbb4139f423d1d9dfcd3e662f17ce9d07 Mon Sep 17 00:00:00 2001 From: asivache Date: Mon, 31 Aug 2009 18:09:55 +0000 Subject: [PATCH] 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 --- .../gatk/walkers/fasta/FastaSequence.java | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/java/src/org/broadinstitute/sting/playground/gatk/walkers/fasta/FastaSequence.java b/java/src/org/broadinstitute/sting/playground/gatk/walkers/fasta/FastaSequence.java index 2c3c72d49..444497db3 100755 --- a/java/src/org/broadinstitute/sting/playground/gatk/walkers/fasta/FastaSequence.java +++ b/java/src/org/broadinstitute/sting/playground/gatk/walkers/fasta/FastaSequence.java @@ -1,6 +1,7 @@ package org.broadinstitute.sting.playground.gatk.walkers.fasta; import org.broadinstitute.sting.utils.GenomeLoc; +import org.broadinstitute.sting.utils.StingException; import java.io.PrintStream; @@ -12,11 +13,22 @@ public class FastaSequence { private StringBuffer sb = new StringBuffer(); private long sequenceCounter = 1; private boolean printedHeader = false; + private String name = null; public FastaSequence(PrintStream 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) { sb.append(s); printFasta(false); @@ -25,6 +37,7 @@ public class FastaSequence { public void flush() { printFasta(true); printedHeader = false; + name = null; sequenceCounter++; } @@ -36,7 +49,8 @@ public class FastaSequence { if ( sb.length() == 0 || (!printAll && sb.length() < 60) ) return; if ( !printedHeader ) { - out.println(">" + sequenceCounter); + if ( name == null ) out.println(">" + sequenceCounter); + else out.println(">" + name); printedHeader = true; } int lines = sb.length() / 60;