本文整理汇总了Java中htsjdk.samtools.SAMFileWriterFactory.makeBAMWriter方法的典型用法代码示例。如果您正苦于以下问题:Java SAMFileWriterFactory.makeBAMWriter方法的具体用法?Java SAMFileWriterFactory.makeBAMWriter怎么用?Java SAMFileWriterFactory.makeBAMWriter使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类htsjdk.samtools.SAMFileWriterFactory
的用法示例。
在下文中一共展示了SAMFileWriterFactory.makeBAMWriter方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: open
import htsjdk.samtools.SAMFileWriterFactory; //导入方法依赖的package包/类
public void open(final SAMFileHeader src)
{
SAMFileWriterFactory samFileWriterFactory=writingBamArgs.createSAMFileWriterFactory();
samFileWriterFactory.setMaxRecordsInRam(writingSortingCollection.getMaxRecordsInRam());
samFileWriterFactory.setTempDirectory(writingSortingCollection.getTmpDirectories().get(0));
final File fileout=getFile();
LOG.info("opening BAM file "+fileout);
final File parent=fileout.getParentFile();
if(parent!=null) {
parent.mkdirs();
samFileWriterFactory.setTempDirectory(writingSortingCollection.getTmpDirectories().get(0));
}
this.header= src.clone();
this.header.addComment(
"Processed with "+getProgramCommandLine()+
" version:"+getVersion()+
"CommandLine:"+getProgramCommandLine()
);
this.header.setSortOrder(SortOrder.coordinate);
samFileWriterFactory.setCreateIndex(true);
this._writer = samFileWriterFactory.makeBAMWriter(
this.header,
true,
fileout
);
}
示例2: main
import htsjdk.samtools.SAMFileWriterFactory; //导入方法依赖的package包/类
public static void main(String[] args) throws IOException, ParseException {
EvidenceRecordFileIterator iterator = new EvidenceRecordFileIterator(new File(args[0]));
Read context = new Read();
SAMFileHeader header = new SAMFileHeader();
header.setSortOrder(SAMFileHeader.SortOrder.unsorted);
SAMSequenceRecord samSequenceRecord = new SAMSequenceRecord("chr10", 135534747);
samSequenceRecord.setAttribute(SAMSequenceRecord.ASSEMBLY_TAG, iterator.assembly_ID);
String readGroup = String.format("%s-%s", iterator.assembly_ID, iterator.chromosome);
SAMReadGroupRecord readGroupRecord = new SAMReadGroupRecord(readGroup);
readGroupRecord.setAttribute(SAMReadGroupRecord.READ_GROUP_SAMPLE_TAG, iterator.sample);
readGroupRecord.setAttribute(SAMReadGroupRecord.PLATFORM_UNIT_TAG, readGroup);
readGroupRecord.setAttribute(SAMReadGroupRecord.SEQUENCING_CENTER_TAG, "\"Complete Genomics\"");
Date date = new SimpleDateFormat("yyyy-MMM-dd hh:mm:ss.S").parse(iterator.generatedAt);
readGroupRecord.setAttribute(SAMReadGroupRecord.DATE_RUN_PRODUCED_TAG,
new SimpleDateFormat("yyyy-MM-dd").format(date));
readGroupRecord.setAttribute(SAMReadGroupRecord.PLATFORM_TAG, "\"Complete Genomics\"");
header.addReadGroup(readGroupRecord);
header.addSequence(samSequenceRecord);
SAMFileWriterFactory f = new SAMFileWriterFactory();
SAMFileWriter samWriter;
if (args.length > 1)
samWriter = f.makeBAMWriter(header, false, new File(args[1]));
else
samWriter = f.makeSAMWriter(header, false, System.out);
int i = 0;
long time = System.currentTimeMillis();
DedupIterator dedupIt = new DedupIterator(iterator);
while (dedupIt.hasNext()) {
EvidenceRecord evidenceRecord = dedupIt.next();
if (evidenceRecord == null)
throw new RuntimeException();
try {
context.reset(evidenceRecord);
context.parse();
} catch (Exception e) {
System.err.println("Failed on line:");
System.err.println(evidenceRecord.line);
throw new RuntimeException(e);
}
SAMRecord[] samRecords = context.toSAMRecord(header);
for (SAMRecord samRecord : samRecords) {
samRecord.setAttribute(SAMTag.RG.name(), readGroup);
samWriter.addAlignment(samRecord);
}
i++;
if (i % 1000 == 0) {
if (System.currentTimeMillis() - time > 10 * 1000) {
time = System.currentTimeMillis();
System.err.println(i);
}
}
if (i > 10000)
break;
}
samWriter.close();
}
示例3: main
import htsjdk.samtools.SAMFileWriterFactory; //导入方法依赖的package包/类
public static void main(String[] args) throws IOException {
Params params = new Params();
JCommander jc = new JCommander(params);
jc.parse(args);
Log.setGlobalLogLevel(params.logLevel);
if (args.length == 0 || params.help) {
usage(jc);
System.exit(1);
}
if (params.reference == null) {
System.out.println("Reference file not found, will try downloading...");
}
ReferenceSource referenceSource = null;
if (params.reference != null) {
System.setProperty("reference", params.reference.getAbsolutePath());
referenceSource = new ReferenceSource(params.reference);
} else {
String prop = System.getProperty("reference");
if (prop != null) {
referenceSource = new ReferenceSource(new File(prop));
}
}
SamReaderFactory factory = SamReaderFactory.make().validationStringency(params.validationLevel);
SamInputResource r;
if ("file".equalsIgnoreCase(params.url.getProtocol()))
r = SamInputResource.of(params.url.getPath());
else
r = SamInputResource.of(params.url);
SamReader reader = factory.open(r);
SAMRecordIterator iterator = reader.iterator();
SAMFileWriterFactory writerFactory = new SAMFileWriterFactory();
SAMFileWriter writer = null;
OutputStream os = new BufferedOutputStream(new FileOutputStream(params.outputFile));
switch (params.outputFormat) {
case BAM:
writer = writerFactory.makeBAMWriter(reader.getFileHeader(),
reader.getFileHeader().getSortOrder() == SortOrder.coordinate, os);
break;
case CRAM:
writer = writerFactory.makeCRAMWriter(reader.getFileHeader(), os, params.reference);
break;
default:
System.out.println("Unknown output format: " + params.outputFormat);
System.exit(1);
}
while (iterator.hasNext()) {
writer.addAlignment(iterator.next());
}
writer.close();
reader.close();
}
示例4: main
import htsjdk.samtools.SAMFileWriterFactory; //导入方法依赖的package包/类
public static void main(String[] args) throws IOException {
// Logger.LEVEL = Logger.Level.TRACE;
String ref = "/home/lmose/dev/reference/hg38b/hg38.fa";
CompareToReference2 c2r = new CompareToReference2();
c2r.init(ref);
ChromosomeChunker cc = new ChromosomeChunker(c2r);
cc.init();
// SamReader reader = SAMRecordUtils.getSamReader("/home/lmose/dev/abra2_dev/sort_issue3/0.5.bam");
// SamReader reader = SAMRecordUtils.getSamReader("/home/lmose/dev/abra2_dev/sort_issue4/1.6.bam");
SamReader reader = SAMRecordUtils.getSamReader("/home/lmose/dev/abra2_dev/mate_fix/0.87.bam");
SAMFileHeader header = reader.getFileHeader();
header.setSortOrder(SortOrder.coordinate);
int maxRecordsInRam = 1000000;
SAMRecord[] readsByNameArray = new SAMRecord[maxRecordsInRam];
SAMRecord[] readsByCoordArray = new SAMRecord[maxRecordsInRam];
SortedSAMWriter writer = new SortedSAMWriter(new String[] { "/home/lmose/dev/abra2_dev/mate_fix" }, "/home/lmose/dev/abra2_dev/mate_fix", new SAMFileHeader[] { reader.getFileHeader() }, true, cc,
1,true,1000,false, false, false, maxRecordsInRam);
SAMFileWriterFactory writerFactory = new SAMFileWriterFactory();
SAMFileWriter out = writerFactory.makeBAMWriter(reader.getFileHeader(), true, new File("/home/lmose/dev/abra2_dev/mate_fix/test.bam"),1);
long start = System.currentTimeMillis();
writer.processChromosome(out, 0, "chr12", readsByNameArray, readsByCoordArray);
out.close();
long stop = System.currentTimeMillis();
System.out.println("Elapsed msecs: " + (stop-start));
}