本文整理汇总了Java中net.sf.samtools.SAMFileReader.getFileHeader方法的典型用法代码示例。如果您正苦于以下问题:Java SAMFileReader.getFileHeader方法的具体用法?Java SAMFileReader.getFileHeader怎么用?Java SAMFileReader.getFileHeader使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类net.sf.samtools.SAMFileReader
的用法示例。
在下文中一共展示了SAMFileReader.getFileHeader方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: setupChromBamWriters
import net.sf.samtools.SAMFileReader; //导入方法依赖的package包/类
/**
* Creates a collection of SAMFileWriters, one for each chromosome.
*
* The definition of the chromosomes is taken from the header of a template
* bamfile.
*
* @param template
*/
private void setupChromBamWriters(File template) {
SAMFileReader inputSam = new SAMFileReader(template);
SAMFileHeader inputHeader = inputSam.getFileHeader();
ArrayList<SAMSequenceRecord> samchroms;
samchroms = new ArrayList<SAMSequenceRecord>(inputSam.getFileHeader().getSequenceDictionary().getSequences());
// create another list of just chromosome names
ArrayList<String> chroms = new ArrayList<String>();
for (int i = 0; i < samchroms.size(); i++) {
chroms.add(samchroms.get(i).getSequenceName());
}
chroms.add("unmapped");
// create a filewriter for each chromosome
for (int i = 0; i < chroms.size(); i++) {
String nowchrom = chroms.get(i);
SAMFileHeader nowheader = inputHeader.clone();
nowheader.addComment("Merged data using GeneticThesaurus merge2chrom: chromosome " + nowchrom);
SAMFileWriter nowWriter = new SAMFileWriterFactory().makeSAMOrBAMWriter(
nowheader, true, new File(prefix + "." + nowchrom + ".bam"));
chrombams.put(nowchrom, nowWriter);
}
}
示例2: BAMFile
import net.sf.samtools.SAMFileReader; //导入方法依赖的package包/类
protected BAMFile (File file, boolean onlyMapped) throws SequenceFormatException, IOException {
this.file = file;
fileSize = file.length();
name = file.getName();
this.onlyMapped = onlyMapped;
SAMFileReader.setDefaultValidationStringency(SAMFileReader.ValidationStringency.SILENT);
fis = new FileInputStream(file);
br = new SAMFileReader(fis);
header = br.getFileHeader();
it = br.iterator();
readNext();
}
示例3: apply
import net.sf.samtools.SAMFileReader; //导入方法依赖的package包/类
@Override
public String apply(File f) {
if (!detectable(f)) {
throw new IllegalArgumentException("Cannot detect sample name for file: " + f.getPath());
}
final SAMFileReader in = new SAMFileReader(f);
try {
final SAMFileHeader header = in.getFileHeader();
final List<SAMReadGroupRecord> rgs = header.getReadGroups();
assertFalse(rgs.isEmpty(), "Cannot determine sample name: missing read group information for file: " + f.getPath());
assertFalse(rgs.size() > 1, "Cannot determine sample name: more than one read group detected for file: " + f.getPath());
final String sample = rgs.get(0).getSample();
assertFalse(sample == null, "Cannot determine sample name: missing sample name in read group for file: " + f.getPath());
return sample;
} finally {
in.close();
}
}
示例4: BamToSingleEndIterator
import net.sf.samtools.SAMFileReader; //导入方法依赖的package包/类
public BamToSingleEndIterator(File bamFile)
{
reader = new SAMFileReader(bamFile);
header = reader.getFileHeader();
iter = reader.iterator();
nextAlignment=_next();
}
示例5: BamToPairedEndIterator
import net.sf.samtools.SAMFileReader; //导入方法依赖的package包/类
/**
* @param bamFile Input SAM or BAM file to extract header and/or reads from.
* @param
*/
public BamToPairedEndIterator(File bamFile, TranscriptionRead txnRead, String flag, int maxAllowableInsert) {
/**
* @param bamFile Input SAM or BAM file to extract header and/or reads from.
* @param txnRead if first read or second read is in direction of trasncription.
* default: first read. TranscriptionRead.FIRST_OF_PAIR
* @param flag "a" to report paired end reads and unpaired end reads
* "p" to only report the paired end reads.
* @generator an PairedEndAlignment iterator.
*
*/
this.flag=flag;
reader = new SAMFileReader(bamFile);
header = reader.getFileHeader();
//set header to pairedEnd
//header.setAttribute(mateLineFlag, "mergedPairedEndFormat");
iter = reader.iterator();
bufferCollection = new TreeMap<String,Alignment>();
this.txnRead=txnRead;
this.maxAllowableInsert=maxAllowableInsert;
nextAlignment=advance();
}
示例6: doWork
import net.sf.samtools.SAMFileReader; //导入方法依赖的package包/类
@Override
protected int doWork() {
try {
IoUtil.assertFileIsReadable(INPUT);
IoUtil.assertFileIsWritable(OUTPUT);
final SAMFileReader reader = new SAMFileReader(INPUT);
final SAMFileHeader header = reader.getFileHeader();
final SAMFileWriter writer = new SAMFileWriterFactory().makeSAMOrBAMWriter(header, true, OUTPUT);
SAMRecordIterator itr = reader.iterator();
while (itr.hasNext()) {
SAMRecord record = itr.next();
record.setDuplicateReadFlag(false);
writer.addAlignment(record);
}
itr.close();
writer.close();
reader.close();
} catch (Exception e) {
log.error(e);
}
return 0;
}
示例7: getSizesFromSAM
import net.sf.samtools.SAMFileReader; //导入方法依赖的package包/类
public static Map<String, Integer> getSizesFromSAM(String samFileName) {
final SAMFileReader inputSam = new SAMFileReader(new File(samFileName));
SAMFileHeader header = inputSam.getFileHeader();
SAMSequenceDictionary dictionary = header.getSequenceDictionary();
List<SAMSequenceRecord> references = dictionary.getSequences();
Map<String, Integer> sizes = new LinkedHashMap<String, Integer>(references.size());
for(SAMSequenceRecord r : references) {
sizes.put(r.getSequenceName(), r.getSequenceLength());
}
inputSam.close();
return sizes;
}
示例8: doWork
import net.sf.samtools.SAMFileReader; //导入方法依赖的package包/类
@Override
protected int doWork() {
IoUtil.assertFileIsReadable(INPUT);
IoUtil.assertFileIsWritable(OUTPUT);
IoUtil.assertFileIsWritable(STATS);
try {
// Read and filter
SAMFileReader reader = new SAMFileReader(INPUT);
final SAMFileHeader header = reader.getFileHeader();
// In our current pipeline, unsorted BAM files output by BWA alignment have read pairs next to each other.
if (header.getSortOrder() == SAMFileHeader.SortOrder.unsorted) {
log.warn("Treating unsorted SAM file as queryname-sorted. Check that this produces correct behavior.");
}
header.setSortOrder(SAMFileHeader.SortOrder.queryname);
PairedEndReadIterator itr = new PairedEndReadIterator(reader);
header.setSortOrder(SAMFileHeader.SortOrder.unsorted);
SAMFileWriter writer = new SAMFileWriterFactory().makeSAMOrBAMWriter(header, false, OUTPUT);
while (itr.hasNext()) {
Pair<SAMRecord> pair = itr.next();
SAMRecord first = pair.getValue1();
SAMRecord second = pair.getValue2();
if (readMapsToProbe(first, header) || readMapsToProbe(second, header)) {
writer.addAlignment(first);
writer.addAlignment(second);
addStartEndIndices(first, second);
}
}
reader.close();
writer.close();
BufferedWriter bw = new BufferedWriter(new FileWriter(STATS));
bw.write("index\tstart\tend\n");
for (int i = 0; i < startIndex.length; i++) {
bw.write(i + "\t" + startIndex[i] + "\t"+ endIndex[i] + "\n");
}
bw.close();
} catch (Exception e) {
log.error(e);
}
return 0;
}
示例9: main
import net.sf.samtools.SAMFileReader; //导入方法依赖的package包/类
public static void main (String [] args) throws IOException {
ArgumentMap argMap = CLUtil.getParameters(args,USAGE , "default");
String alnFile = argMap.getInput();
String out = argMap.getOutput();
List<String> seqsToChange = new ArrayList<String>();
if(argMap.containsKey("seqsToFix")) {
seqsToChange = CLUtil.listFromArray(argMap.getMandatory("seqsToFix").split(","));
}
SAMFileReader reader = new SAMFileReader(new File(alnFile));
SAMFileWriterFactory samfwf = new SAMFileWriterFactory();
SAMFileHeader oldHeader = reader.getFileHeader();
SAMFileHeader header = oldHeader.clone();
header.setSortOrder(oldHeader.getSortOrder());
oldHeader.getAttributes();
for (Map.Entry<String, String> he : oldHeader.getAttributes()) {
header.setAttribute(he.getKey(), he.getValue());
}
header.addProgramRecord(new SAMProgramRecord("nextgen.core.programs.FixChromosomeNames -in " + alnFile + " -out " + out));
SAMSequenceDictionary ssd = header.getSequenceDictionary();
SAMSequenceDictionary newSSD = new SAMSequenceDictionary();
List<SAMSequenceRecord > sequences = ssd.getSequences();
for (SAMSequenceRecord s : sequences) {
if(seqsToChange.isEmpty() || seqsToChange.contains(s.getSequenceName())) {
SAMSequenceRecord ns = new SAMSequenceRecord("chr" + s.getSequenceName(), s.getSequenceLength());
ns.setAssembly(s.getAssembly());
ns.setSpecies(ns.getSpecies());
for (Map.Entry<String, String> e : s.getAttributes()) {
ns.setAttribute(e.getKey(), e.getValue());
}
newSSD.addSequence(ns);
} else {
newSSD.addSequence(s);
}
}
header.setSequenceDictionary(newSSD);
samfwf.setCreateIndex(true);
SAMFileWriter writer = samfwf.makeBAMWriter(header, true, new File(out)) ;
Iterator<SAMRecord> alnIt = reader.iterator();
while (alnIt.hasNext()) {
SAMRecord a = alnIt.next();
if(seqsToChange.isEmpty() || seqsToChange.contains(a.getReferenceName())) {
a.setReferenceName("chr"+a.getReferenceName());
a.setHeader(header);
}
writer.addAlignment(a);
}
reader.close();
writer.close();
}