From b1245134cc83a39aa16068f72e4a368e145e47ef Mon Sep 17 00:00:00 2001
From: tjc <tjc@ee4ac58c-ac51-4696-9907-e4b3aa274f04>
Date: Tue, 30 Nov 2010 11:07:17 +0000
Subject: [PATCH] add test for BCF file format
git-svn-id: svn+ssh://svn.internal.sanger.ac.uk/repos/svn/pathsoft/artemis/trunk@15131 ee4ac58c-ac51-4696-9907-e4b3aa274f04
---
.../artemis/components/variant/IOUtils.java | 57 ++++++++++---------
1 file changed, 30 insertions(+), 27 deletions(-)
diff --git a/uk/ac/sanger/artemis/components/variant/IOUtils.java b/uk/ac/sanger/artemis/components/variant/IOUtils.java
index faaec10eb..7a00004fe 100644
--- a/uk/ac/sanger/artemis/components/variant/IOUtils.java
+++ b/uk/ac/sanger/artemis/components/variant/IOUtils.java
@@ -42,32 +42,7 @@ import uk.ac.sanger.artemis.io.Key;
import net.sf.samtools.util.BlockCompressedInputStream;
class IOUtils
-{
-
- private static void writeHeader(final String fileName, final Writer writer)
- {
- try
- {
- FileInputStream fileStream = new FileInputStream(fileName);
- BlockCompressedInputStream is = new BlockCompressedInputStream(fileStream);
-
- int c;
- int lc = -1;
-
- while((c = is.read()) >= 0)
- {
- if(lc == '\n' && c != '#')
- break;
- writer.write(c);
- }
- is.close();
- }
- catch (IOException e)
- {
- e.printStackTrace();
- }
- }
-
+{
/**
* Write filtered uncompressed VCF. Uses the filter in VCFview to
* determine if variants are written.
@@ -81,7 +56,6 @@ class IOUtils
final VCFview vcfView,
final FeatureVector features)
{
- writeHeader(vcfFileName, writer);
try
{
TabixReader tr = new TabixReader(vcfFileName);
@@ -89,7 +63,10 @@ class IOUtils
while ((line = tr.readLine()) != null)
{
if(line.startsWith("#"))
+ {
+ writer.write(line+'\n');
continue;
+ }
String parts[] = VCFview.tabPattern.split(line, 0);
int basePosition = Integer.parseInt(parts[1]) + vcfView.getSequenceOffset(parts[0]);
if( !vcfView.showVariant(parts[3], parts[4], features, basePosition, parts[5]) )
@@ -104,6 +81,12 @@ class IOUtils
}
}
+ /**
+ * Export as a VCF based on the filtering applied in the VCFview.
+ * @param entryGroup
+ * @param vcfFiles
+ * @param vcfView
+ */
protected static void export(final EntryGroup entryGroup,
final List<String> vcfFiles,
final VCFview vcfView)
@@ -141,5 +124,25 @@ class IOUtils
"Error", JOptionPane.ERROR_MESSAGE);
}
}
+
+ /**
+ * Test if this is a BCF file.
+ * @param fileName
+ * @return
+ * @throws IOException
+ */
+ protected static boolean isBCF(String fileName) throws IOException
+ {
+ FileInputStream fis = new FileInputStream(fileName);
+ BlockCompressedInputStream is = new BlockCompressedInputStream(fis);
+ byte[] magic = new byte[4];
+ is.read(magic);
+ fis.close();
+ is.close();
+ String line = new String(magic);
+ if(line.equals("BCF\4"))
+ return true;
+ return false;
+ }
}
\ No newline at end of file
--
GitLab