美文网首页
htsjdk的使用

htsjdk的使用

作者: 生信石头 | 来源:发表于2020-01-30 08:47 被阅读0次

    写在前面

    直接从htsjdk中掌握其使用,以掌握在没有教程的情况下,从api接口文档直接掌握依赖库的使用
    官网API地址: https://samtools.github.io/htsjdk/javadoc/htsjdk/index.html

    官方API文档

    大概看了下文档之后,发现SAMReader可能是使用了我还是比较陌生的工厂模式,需要从一个SAMReaderFactory来获取

    public abstract class SamReaderFactory
    extends java.lang.Object
    Describes the functionality for producing SamReader, and offers a handful of static generators.
    
         SamReaderFactory.makeDefault().open(new File("/my/bam.bam");
     
    Example: Configure a factory
    
          final SamReaderFactory factory =
              SamReaderFactory.makeDefault()
                  .enable(SamReaderFactory.Option.INCLUDE_SOURCE_IN_RECORDS, SamReaderFactory.Option.VALIDATE_CRC_CHECKSUMS)
                  .validationStringency(ValidationStringency.SILENT);
    
     
    Example: Open two bam files from different sources, using different options
    
         final SamReaderFactory factory =
              SamReaderFactory.makeDefault()
                  .enable(SamReaderFactory.Option.INCLUDE_SOURCE_IN_RECORDS, SamReaderFactory.Option.VALIDATE_CRC_CHECKSUMS)
                  .validationStringency(ValidationStringency.SILENT);
    
         // File-based bam
         final SamReader fileReader = factory.open(new File("/my/bam.bam"));
    
         // HTTP-hosted BAM with index from an arbitrary stream
         final SeekableStream myBamIndexStream = ...
         final SamInputResource resource =
              SamInputResource.of(new URL("http://example.com/data.bam")).index(myBamIndexStream);
         final SamReader complicatedReader = factory.open(resource);
    

    简单的快速打开和遍历SAM文件

            SamReader sr = SamReaderFactory.makeDefault().enable(SamReaderFactory.Option.INCLUDE_SOURCE_IN_RECORDS).validationStringency(ValidationStringency.SILENT).open(new File("D:\\Tmp\\StructureScore\\merged.region.sorted.bam"));
            SAMRecordIterator samIterator = sr.iterator();
            while (samIterator.hasNext()) {
                SAMRecord curSAM = samIterator.next();
                System.err.println(curSAM.getReferenceIndex());
                System.err.println(curSAM.getReadName());
                System.err.println(curSAM.getReferenceName());
            }
    

    打开并快速获取BAM文件的某个区域(使用了BAI)

            SamReader sr = SamReaderFactory.makeDefault().enable(SamReaderFactory.Option.INCLUDE_SOURCE_IN_RECORDS).validationStringency(ValidationStringency.SILENT).open(new File("D:\\Tmp\\StructureScore\\merged.region.sorted.bam"));
            SAMRecordIterator samIterator1 = sr.query("miRNA_6", 1116, 1117,true);
            while (samIterator1.hasNext()) {
                SAMRecord curSAM = samIterator1.next();
                System.err.println(curSAM.getReadName());
                System.err.println(curSAM.getReferenceName());
            }
    

    其中miRNA_6是染色体ID,随后是 起始坐标终止坐标

    有帮助的帖子 ,关于 htsjdk 索引的使用

    https://www.biostars.org/p/214515/

    如何做超过两个的分割面板

    https://stackoverflow.com/questions/25593672/creating-jsplitpane-with-3-panels

    相关文章

      网友评论

          本文标题:htsjdk的使用

          本文链接:https://www.haomeiwen.com/subject/psxeuftx.html