Permalink
Browse files

build works now

minor fixes
added short cmd option names
  • Loading branch information...
vadimzalunin committed Nov 8, 2012
1 parent 7874886 commit f7eb4973e46626b2c7e6f7b72701867a42c87bb0
View
@@ -4,7 +4,8 @@
<classpathentry kind="src" path="src/test/java"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.7"/>
<classpathentry kind="lib" path="lib/jcommander-1.7.jar"/>
+ <classpathentry kind="lib" path="lib/sam-1.79.jar"/>
+ <classpathentry kind="lib" path="lib/picard-1.79.jar"/>
<classpathentry kind="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/4"/>
- <classpathentry combineaccessrules="false" kind="src" path="/picard"/>
- <classpathentry kind="output" path="target"/>
+ <classpathentry kind="output" path="bin"/>
</classpath>
@@ -1,11 +1,11 @@
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
-org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.7
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
-org.eclipse.jdt.core.compiler.compliance=1.7
+org.eclipse.jdt.core.compiler.compliance=1.6
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
org.eclipse.jdt.core.compiler.debug.localVariable=generate
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
-org.eclipse.jdt.core.compiler.source=1.7
+org.eclipse.jdt.core.compiler.source=1.6
View
@@ -1,3 +1,3 @@
#Build Number for ANT. Do not edit!
-#Wed Aug 29 11:46:55 BST 2012
-build.number=0
+#Thu Nov 08 16:45:34 GMT 2012
+build.number=11
View
@@ -10,7 +10,7 @@
<property name="target.dir" value="${basedir}/target" />
<property name="classes" value="${target.dir}/classes" />
<property name="crammerClasses" value="target/classes" />
- <property name="jar.file.name" value="cramone.jar" />
+ <property name="jar.file.name" value="cramtools-1.0.jar" />
<path id="classpath">
<fileset dir="${lib.home}" includes="*.jar" />
@@ -42,10 +42,10 @@
<format property="TODAY" pattern="yyyy-MM-dd HH:mm:ss" />
</tstamp>
- <jar destfile="${basedir}/cramtools.jar" filesetmanifest="skip" duplicate="preserve">
+ <jar destfile="${basedir}/${jar.file.name}" filesetmanifest="skip" duplicate="preserve">
<fileset dir="${classes}" />
<zipgroupfileset dir="lib" includes="*.jar" >
- <exclude name="**/SAMFileReader.class" />
+ <exclude name="**/SamFileValidator.class" />
</zipgroupfileset>
<manifest>
@@ -86,11 +86,11 @@
<target name="clean">
<delete dir="${target.dir}" includeEmptyDirs="true" />
- <delete file="cramtools.jar" />
+ <delete file="${jar.file.name}" />
</target>
<target name="compile" depends="setup">
- <javac debug="true" fork="true" destdir="${classes}" srcdir="${src}/main/java:${src}/test/java:../picard/src/java">
+ <javac debug="true" fork="true" destdir="${classes}" srcdir="${src}/main/java:${src}/test/java">
<include name="**/*.java" />
<classpath refid="classpath" />
</javac>
View
Binary file not shown.
View
Binary file not shown.
View
Binary file not shown.
View
Binary file not shown.
View
Binary file not shown.
@@ -59,7 +59,7 @@
SAMFileHeader fileHeader) throws IllegalArgumentException,
IllegalAccessException, IOException {
long time1 = System.nanoTime();
- List<CramRecord> records = new ArrayList<>();
+ List<CramRecord> records = new ArrayList<CramRecord>();
for (Slice s : c.slices)
records.addAll(records(s, h, fileHeader));
@@ -78,7 +78,7 @@
SAMSequenceRecord sequence = fileHeader.getSequence(s.sequenceId);
String seqName = sequence.getSequenceName();
DataReaderFactory f = new DataReaderFactory();
- Map<Integer, InputStream> inputMap = new HashMap<>();
+ Map<Integer, InputStream> inputMap = new HashMap<Integer, InputStream>();
for (Integer exId : s.external.keySet()) {
inputMap.put(exId, new ByteArrayInputStream(
s.external.get(exId).content));
@@ -87,7 +87,7 @@
Reader reader = f.buildReader(new DefaultBitInputStream(
new ByteArrayInputStream(s.coreBlock.content)), inputMap, h);
- List<CramRecord> records = new ArrayList<>();
+ List<CramRecord> records = new ArrayList<CramRecord>();
for (int i = 0; i < s.nofRecords; i++) {
CramRecord r = new CramRecord();
r.setSequenceName(seqName);
@@ -107,7 +107,7 @@
}
static Container writeContainer(List<CramRecord> records,
- SAMFileHeader fileHeader) throws IllegalArgumentException,
+ SAMFileHeader fileHeader, boolean preserveReadNames) throws IllegalArgumentException,
IllegalAccessException, IOException {
// get stats, create compression header and slices
long time1 = System.nanoTime();
@@ -116,11 +116,11 @@ static Container writeContainer(List<CramRecord> records,
h.mappedQualityScoreIncluded = true;
h.unmappedQualityScoreIncluded = true;
- h.readNamesIncluded = true;
+ h.readNamesIncluded = preserveReadNames;
int recordsPerSlice = 10000;
- List<Slice> slices = new ArrayList<>();
+ List<Slice> slices = new ArrayList<Slice>();
Container c = new Container();
c.h = h;
@@ -159,7 +159,7 @@ private static Slice writeSlice(List<CramRecord> records,
CompressionHeader h, SAMFileHeader fileHeader)
throws IllegalArgumentException, IllegalAccessException,
IOException {
- Map<Integer, ExposedByteArrayOutputStream> map = new HashMap<>();
+ Map<Integer, ExposedByteArrayOutputStream> map = new HashMap<Integer, ExposedByteArrayOutputStream>();
for (int id : h.externalIds) {
map.put(id, new ExposedByteArrayOutputStream());
}
@@ -193,7 +193,7 @@ private static Slice writeSlice(List<CramRecord> records,
slice.coreBlock.contentType = BlockContentType.CORE;
bos.close();
- slice.external = new HashMap<>();
+ slice.external = new HashMap<Integer, Block>();
for (Integer i : map.keySet()) {
ExposedByteArrayOutputStream os = map.get(i);
@@ -215,7 +215,7 @@ private static void randomStressTest() throws IOException,
long baseCount = 0;
Random random = new Random();
- List<CramRecord> records = new ArrayList<>();
+ List<CramRecord> records = new ArrayList<CramRecord>();
for (int i = 0; i < 100000; i++) {
int len = random.nextInt(100) + 50;
byte[] bases = new byte[len];
@@ -310,7 +310,7 @@ private static void randomStressTest() throws IOException,
}
long time1 = System.nanoTime();
- Container c = writeContainer(records, samFileHeader);
+ Container c = writeContainer(records, samFileHeader, true);
long time2 = System.nanoTime();
System.out.println("Container written in " + (time2 - time1) / 1000000
+ " milli seconds");
@@ -345,7 +345,7 @@ private static void randomStressTest() throws IOException,
baos.size() * 8f / baseCount);
}
- public static void main(String[] args) throws IllegalArgumentException,
+ public static void main(String[] args, boolean preserveReadNames) throws IllegalArgumentException,
IllegalAccessException, IOException {
File bamFile = new File(
"c:/temp/HG00096.mapped.illumina.mosaik.GBR.exome.20110411.chr20.bam");
@@ -365,7 +365,7 @@ public static void main(String[] args) throws IllegalArgumentException,
}
int maxRecords = 100000;
- List<SAMRecord> samRecords = new ArrayList<>(maxRecords);
+ List<SAMRecord> samRecords = new ArrayList<SAMRecord>(maxRecords);
int alStart = Integer.MAX_VALUE;
int alEnd = 0;
@@ -400,7 +400,7 @@ public static void main(String[] args) throws IllegalArgumentException,
Sam2CramRecordFactory f = new Sam2CramRecordFactory(sequence.getBases());
f.captureUnmappedBases = true;
f.captureUnmappedScores = true;
- List<CramRecord> cramRecords = new ArrayList<>(maxRecords);
+ List<CramRecord> cramRecords = new ArrayList<CramRecord>(maxRecords);
int prevAlStart = samRecords.get(0).getAlignmentStart();
int index = 0;
QualityScorePreservation preservation = new QualityScorePreservation(
@@ -476,7 +476,7 @@ public static void main(String[] args) throws IllegalArgumentException,
System.out.println();
long time1 = System.nanoTime();
- Container c = writeContainer(cramRecords, samFileReader.getFileHeader());
+ Container c = writeContainer(cramRecords, samFileReader.getFileHeader(), preserveReadNames);
long time2 = System.nanoTime();
System.out.println("Container written in " + (time2 - time1) / 1000000
+ " milli seconds");
@@ -50,7 +50,7 @@
Sam2CramRecordFactory f = new Sam2CramRecordFactory(ref);
f.captureUnmappedBases = true;
f.captureUnmappedScores = true;
- List<CramRecord> cramRecords = new ArrayList<>();
+ List<CramRecord> cramRecords = new ArrayList<CramRecord>() ;
int prevAlStart = samRecords.get(0).getAlignmentStart();
int index = 0;
for (SAMRecord samRecord : samRecords) {
@@ -188,7 +188,7 @@ public static void main(String[] args) throws IOException,
sequence = referenceSequenceFile.getSequence(seqName);
}
- List<SAMRecord> samRecords = new ArrayList<>(params.maxContainerSize);
+ List<SAMRecord> samRecords = new ArrayList<SAMRecord>(params.maxContainerSize);
QualityScorePreservation preservation = new QualityScorePreservation(
params.qsSpec);
@@ -214,7 +214,7 @@ public static void main(String[] args) throws IOException,
samFileReader.getFileHeader(), ref, preservation);
samRecords.clear();
Container container = BLOCK_PROTO.writeContainer(records,
- samFileReader.getFileHeader());
+ samFileReader.getFileHeader(), params.preserveReadNames);
records.clear();
ReadWrite.writeContainer(container, os);
@@ -244,7 +244,7 @@ public static void main(String[] args) throws IOException,
samFileReader.getFileHeader(), ref, preservation);
samRecords.clear();
Container container = BLOCK_PROTO.writeContainer(records,
- samFileReader.getFileHeader());
+ samFileReader.getFileHeader(), params.preserveReadNames);
records.clear();
ReadWrite.writeContainer(container, os);
for (Slice s : container.slices) {
@@ -276,13 +276,13 @@ public static void main(String[] args) throws IOException,
@Parameters(commandDescription = "BAM to CRAM converter. ")
static class Params {
- @Parameter(names = { "--input-bam-file" }, converter = FileConverter.class, description = "Path to a BAM file to be converted to CRAM. Omit if standard input (pipe).")
+ @Parameter(names = { "--input-bam-file", "-I" }, converter = FileConverter.class, description = "Path to a BAM file to be converted to CRAM. Omit if standard input (pipe).")
File bamFile;
- @Parameter(names = { "--reference-fasta-file" }, converter = FileConverter.class, description = "The reference fasta file, uncompressed and indexed (.fai file, use 'samtools faidx'). ")
+ @Parameter(names = { "--reference-fasta-file", "-R" }, converter = FileConverter.class, description = "The reference fasta file, uncompressed and indexed (.fai file, use 'samtools faidx'). ")
File referenceFasta;
- @Parameter(names = { "--output-cram-file" }, converter = FileConverter.class, description = "The path for the output CRAM file. Omit if standard output (pipe).")
+ @Parameter(names = { "--output-cram-file", "-O" }, converter = FileConverter.class, description = "The path for the output CRAM file. Omit if standard output (pipe).")
File outputCramFile = null;
@Parameter(names = { "--max-records" }, description = "Stop after compressing this many records. ")
@@ -315,7 +315,7 @@ public static void main(String[] args) throws IOException,
@Parameter(names = { "--preserve-read-names" }, description = "Preserve all read names.")
boolean preserveReadNames = false;
- @Parameter(names = { "--lossy-quality-score-spec" }, description = "A string specifying what quality scores should be preserved.")
+ @Parameter(names = { "--lossy-quality-score-spec", "-L" }, description = "A string specifying what quality scores should be preserved.")
String qsSpec = "";
}
}
@@ -144,13 +144,13 @@ public static void main(String[] args) throws IOException,
@Parameters(commandDescription = "CRAM to BAM conversion. ")
static class Params {
- @Parameter(names = { "--input-cram-file" }, converter = FileConverter.class, description = "The path to the CRAM file to uncompress. Omit if standard input (pipe).")
+ @Parameter(names = { "--input-cram-file", "-I" }, converter = FileConverter.class, description = "The path to the CRAM file to uncompress. Omit if standard input (pipe).")
File cramFile;
- @Parameter(names = { "--reference-fasta-file" }, converter = FileConverter.class, description = "Path to the reference fasta file, it must be uncompressed and indexed (use 'samtools faidx' for example).")
+ @Parameter(names = { "--reference-fasta-file", "-R" }, converter = FileConverter.class, description = "Path to the reference fasta file, it must be uncompressed and indexed (use 'samtools faidx' for example).")
File reference;
- @Parameter(names = { "--output-bam-file" }, converter = FileConverter.class, description = "The path to the output BAM file.")
+ @Parameter(names = { "--output-bam-file", "-O" }, converter = FileConverter.class, description = "The path to the output BAM file.")
File outputFile;
@Parameter(names = { "-h", "--help" }, description = "Print help and quit")
@@ -1,22 +1,28 @@
package net.sf.cram;
+import java.io.BufferedInputStream;
import java.io.EOFException;
+import java.io.File;
+import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
+import java.util.Iterator;
import java.util.List;
import net.sf.cram.ReadWrite.CramHeader;
import net.sf.cram.structure.Container;
import net.sf.picard.reference.ReferenceSequence;
import net.sf.picard.reference.ReferenceSequenceFile;
import net.sf.picard.util.Log;
+import net.sf.samtools.SAMFileHeader.SortOrder;
import net.sf.samtools.SAMRecord;
+import net.sf.samtools.SAMRecordIterator;
import net.sf.samtools.SAMSequenceRecord;
import net.sf.samtools.util.CloseableIterator;
import net.sf.samtools.util.RuntimeEOFException;
-public class CramFileIterator implements CloseableIterator<SAMRecord> {
+public class CramFileIterator implements SAMRecordIterator {
private static Log log = Log.getInstance(CramFileIterator.class);
private InputStream is;
private CramHeader cramHeader;
@@ -30,17 +36,17 @@ public CramFileIterator(InputStream is,
this.is = is;
this.referenceSequenceFile = referenceSequenceFile;
cramHeader = ReadWrite.readCramHeader(is);
- records = new ArrayList<>(100000) ;
+ records = new ArrayList<SAMRecord>(100000);
}
-
+
public CramHeader getCramHeader() {
return cramHeader;
}
private void nextContainer() throws IOException, IllegalArgumentException,
IllegalAccessException {
if (records == null)
- records = new ArrayList<>(100000);
+ records = new ArrayList<SAMRecord>(100000);
records.clear();
recordCounter = 0;
@@ -91,7 +97,8 @@ public boolean hasNext() {
if (recordCounter + 1 >= records.size()) {
try {
nextContainer();
- if (records.isEmpty()) return false ;
+ if (records.isEmpty())
+ return false;
} catch (Exception e) {
throw new RuntimeEOFException(e);
}
@@ -120,4 +127,33 @@ public void close() {
}
}
+ public static class CramFileIterable implements Iterable<SAMRecord> {
+ private ReferenceSequenceFile referenceSequenceFile;
+ private File cramFile;
+
+ public CramFileIterable(File cramFile, ReferenceSequenceFile referenceSequenceFile) {
+ this.referenceSequenceFile = referenceSequenceFile;
+ this.cramFile = cramFile;
+ }
+
+ @Override
+ public Iterator<SAMRecord> iterator() {
+ try {
+ FileInputStream fis = new FileInputStream(cramFile);
+ BufferedInputStream bis = new BufferedInputStream(fis);
+ CramFileIterator iterator = new CramFileIterator(bis,
+ referenceSequenceFile);
+ return iterator;
+ } catch (IOException e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+ }
+
+ @Override
+ public SAMRecordIterator assertSorted(SortOrder sortOrder) {
+ throw new RuntimeException("Not implemented.") ;
+ }
+
}
@@ -23,7 +23,7 @@
private int alignmentStart = 1;
private byte defaultQualityScore = '?' - '!';
- private Map<Integer, CramRecord> pairingByIndexMap = new HashMap<>();
+ private Map<Integer, CramRecord> pairingByIndexMap = new HashMap<Integer, CramRecord>();
private byte[] ref;
public CramNormalizer(SAMFileHeader header, byte[] ref, int alignmentStart) {
@@ -98,7 +98,7 @@ public void normalize(List<CramRecord> records, boolean resetPairing) {
// assign some read names if needed:
for (CramRecord r : records) {
if (r.getReadName() == null) {
- String name = readNamePrefix + readCounter;
+ String name = readNamePrefix + r.index;
r.setReadName(name);
if (r.next != null)
r.next.setReadName(name);
@@ -0,0 +1,8 @@
+package net.sf.cram;
+
+public class Preservation {
+ public boolean mappedQualityScoreIncluded;
+ public boolean unmappedQualityScoreIncluded;
+ public boolean unmappedPlacedQualityScoreIncluded;
+ public boolean readNamesIncluded;
+}
Oops, something went wrong.

0 comments on commit f7eb497

Please sign in to comment.