Package net.sf.samtools

Examples of net.sf.samtools.SAMRecord


    factory.preserveReadNames = true;

    List<CramRecord> cramRecords = new ArrayList<CramRecord>();
    List<SAMRecord> samRecords = new ArrayList<SAMRecord>();
    for (int i = 0; i < 100000; i++) {
      SAMRecord samRecord = iterator.next();
      samRecords.add(samRecord);
      CramRecord cramRecord = factory.createCramRecord(samRecord);
      // cramRecord.setReadName(samRecord.getReadName()) ;
      cramRecord.counter = i;
      cramRecords.add(cramRecord);

      // a.addSAMRecord(samRecord) ;
    }
    reader.close();

    long time1 = System.nanoTime();
    new SpotAssemblyTest().connect(cramRecords);
    long time2 = System.nanoTime();

    long time3 = System.nanoTime();
    new SpotAssemblyTest().restoreReadNames(cramRecords);
    long time4 = System.nanoTime();

    System.out.printf("%.3f\t%.3f\n", (time2 - time1) / 1000000f, (time4 - time3) / 1000000f);

    PairedTemplateAssembler a = new PairedTemplateAssembler();
    for (SAMRecord record : samRecords) {
      a.addSAMRecord(record);
    }

    time1 = System.nanoTime();
    int next = 0, fetch = 0; long maxD= 0;
    for (int i = 0; i < samRecords.size(); i++) {
      SAMRecord record = a.nextSAMRecord();
      if (a == null) {
        record = a.fetchNextSAMRecord();
        fetch++;
      } else
        next++;
View Full Code Here


    definition.formatMajor = 1;
    definition.formatMinor = 0;
    definition.magick = "CRAM".getBytes();
    Format format = new FormatFactory().createFormat(definition);

    SAMRecord samRecord = null;
    CramHeader cramHeader = createCramHeader(reader.getFileHeader());
    ByteArrayOutputStream hBaos= new ByteArrayOutputStream() ;
    Container hC = new Container() ;
    Block hBlock = new Block() ;
    hBlock.contentId=0;
    hBlock.contentType=0;
    hBlock.method = CompressionMethod.GZIP.byteValue() ;
    hC.blocks = new Block[]{hBlock} ;
    hC.containers= new Container[0] ;
    CramHeaderIO.write(cramHeader, hBaos) ;
    hBlock.data = hBaos.toByteArray() ;
    format.writeContainer(hC, hBaos) ;
    System.out.println("Header size: " + hBaos.size());
   
    for (int b = 0; b < maxRecords; b+=recordsPerBlock) {
      bases = 0 ;
      size = 0 ;
      for (int i = 0; i < recordsPerBlock; i++) {
        samRecord = iterator.next();
        a.addSAMRecord(samRecord);
        bases += samRecord.getReadLength();
      }

      for (int i = 0; i < recordsPerBlock; i++) {
        while ((samRecord = a.nextSAMRecord()) != null) {
          CramRecord cramRecord = scFactory.createCramRecord(samRecord);
View Full Code Here

      seqNameToIndexMap.put(seq.getSequenceName(), seq.getSequenceIndex());
    }

    ReadFeatures2Cigar readFeatures2Cigar = new ReadFeatures2Cigar();
    List<SAMRecord> samRecords = new ArrayList<SAMRecord>();
    SAMRecord samRecord = null;
    int counter = 0;
    for (CramRecord record : readRecords) {
      CramRecord cramRecord = record;
      samRecord = new SAMRecord(header);
      if (record.tags != null && !record.tags.isEmpty()) {
        for (ReadTag rt : record.tags) {
          samRecord.setAttribute(rt.getKey(), rt.getValue());
        }
      }

      if (readGroups != null && !readGroups.isEmpty()) {
        String rgId = readGroups.get(cramRecord.getReadGroupID());
        if (rgId != null)
          samRecord.setAttribute("RG", rgId);
      }

      if (cramRecord.next != null || cramRecord.previous != null) {
        CramRecord mate = cramRecord.next == null ? cramRecord.previous : cramRecord.next;
        samRecord.setReadPairedFlag(true);
        samRecord.setMateAlignmentStart((int) mate.getAlignmentStart());
        samRecord.setMateNegativeStrandFlag(mate.isNegativeStrand());
        samRecord.setInferredInsertSize(record.insertSize);

        if (SAMRecord.NO_ALIGNMENT_REFERENCE_NAME.equals(mate.getSequenceName())) {
          samRecord.setMateReferenceIndex(SAMRecord.NO_ALIGNMENT_REFERENCE_INDEX);
          samRecord.setMateUnmappedFlag(!mate.isReadMapped());
          if (cramRecord.isFirstInPair()) {
            samRecord.setFirstOfPairFlag(true);
            samRecord.setSecondOfPairFlag(false);
          } else {
            samRecord.setFirstOfPairFlag(false);
            samRecord.setSecondOfPairFlag(true);
          }
        } else {
          if (mate.getSequenceName() == null || !seqNameToIndexMap.containsKey(mate.getSequenceName())) {
            samRecord.setReadPairedFlag(false);
            samRecord.setMateAlignmentStart(SAMRecord.NO_ALIGNMENT_START);
            samRecord.setMateNegativeStrandFlag(false);
          } else {
            int seqIndex = seqNameToIndexMap.get(mate.getSequenceName());
            samRecord.setMateReferenceIndex(seqIndex);
            samRecord.setMateUnmappedFlag(!mate.isReadMapped());
            if (cramRecord.isFirstInPair()) {
              samRecord.setFirstOfPairFlag(true);
              samRecord.setSecondOfPairFlag(false);
            } else {
              samRecord.setFirstOfPairFlag(false);
              samRecord.setSecondOfPairFlag(true);
            }
          }
        }
        samRecord.setReadName(cramRecord.getReadName());
      } else {
        String readName = cramRecord.getReadName();
        if (readName == null)
          readName = String.valueOf(counter);

        if (!cramRecord.isLastFragment()) {
          samRecord.setFirstOfPairFlag(cramRecord.isFirstInPair());
          samRecord.setSecondOfPairFlag(!cramRecord.isFirstInPair());
          samRecord.setReadPairedFlag(true);
        } else {
          if (cramRecord.isLastFragment()) {
            samRecord.setReadName(readName);
            samRecord.setReadPairedFlag(false);
            samRecord.setFirstOfPairFlag(false);
            samRecord.setSecondOfPairFlag(false);
          } else {
            samRecord.setReadName(readName);
            samRecord.setFirstOfPairFlag(cramRecord.isFirstInPair());
            samRecord.setSecondOfPairFlag(!cramRecord.isFirstInPair());
            samRecord.setReadPairedFlag(true);
          }
        }
      }

      samRecord.setMappingQuality((int) cramRecord.getMappingQuality() & 0xFF);
      if (cramRecord.isReadMapped()) {
        samRecord.setAlignmentStart((int) cramRecord.getAlignmentStart());
        samRecord.setReadBases(cramRecord.getReadBases());
        byte[] scores = cramRecord.getQualityScores();
        scores = cramRecord.getQualityScores();

        injectQualityScores(scores, samRecord);
      } else {
        samRecord.setAlignmentStart((int) cramRecord.getAlignmentStart());
        samRecord.setReadBases(cramRecord.getReadBases());
        byte[] scores = cramRecord.getQualityScores();
        injectQualityScores(scores, samRecord);
      }
      samRecord.setCigar(readFeatures2Cigar.getCigar2(cramRecord.getReadFeatures(),
          (int) cramRecord.getReadLength()));
      samRecord.setReadUnmappedFlag(!cramRecord.isReadMapped());
      samRecord.setReadNegativeStrandFlag(cramRecord.isNegativeStrand());
      samRecord.setReferenceName(seqName);
      samRecord.setProperPairFlag(cramRecord.isProperPair());
      samRecord.setDuplicateReadFlag(cramRecord.isDuplicate());
      samRecord.setReadFailsVendorQualityCheckFlag(cramRecord.vendorFiltered);

      if (SAMRecord.NO_ALIGNMENT_REFERENCE_NAME.equals(samRecord.getReferenceName()))
        samRecord.setAlignmentStart(SAMRecord.NO_ALIGNMENT_START);

      if (samRecord.getReadUnmappedFlag()) {
        samRecord.setMappingQuality(SAMRecord.NO_MAPPING_QUALITY);
        samRecord.setCigarString(SAMRecord.NO_ALIGNMENT_CIGAR);
      }
      samRecords.add(samRecord);
    }
    return samRecords;
  }
View Full Code Here

        long numGC = 0;


        while(iter.hasNext()){

            SAMRecord read = null;

            try {
                read = iter.next();
            } catch (RuntimeException e) {
                logger.warn( e.getMessage() );
            }

            if (read == null) {
                continue;
            }


            byte[] readBases = read.getReadBases();

            for (byte base : readBases) {
                switch (base) {
                    case 'A':
                        numBases++;
View Full Code Here

         System.out.println(getNextFastqPair());
    }

    public String getNextFastqPair() throws Exception {
        while (recordIterator.hasNext()) {
            SAMRecord currentRecord = recordIterator.next();
            // Skip non-PF reads as necessary
            if (currentRecord.getReadFailsVendorQualityCheckFlag()) continue;

            final String currentReadName = currentRecord.getReadName() ;
            final SAMRecord firstRecord = firstSeenMates.get(currentReadName);
            if (firstRecord == null) {
                firstSeenMates.put(currentReadName, currentRecord) ;
            }
            else {
                assertPairedMates(firstRecord, currentRecord);
View Full Code Here

        try {

            for (final SAMRecord currentRecord : reader ) {

                final String currentReadName = currentRecord.getReadName() ;
                final SAMRecord firstRecord = firstSeenMates.get(currentReadName);

                // Skip non-PF reads as necessary
                if (currentRecord.getReadFailsVendorQualityCheckFlag() && !INCLUDE_NON_PF_READS) {
                    if (currentRecord.getReadPairedFlag()) {
                        failedReadNames.add(currentReadName);
View Full Code Here

    }

    protected void doGroupedPaired(final Map<String,SAMRecord> firstSeenMates,
                                final Map<SAMReadGroupRecord, List<FastqWriter>> writers, final SAMRecord currentRecord) {
        final String currentReadName = currentRecord.getReadName() ;
        final SAMRecord firstRecord = firstSeenMates.remove(currentReadName);

        if (firstRecord == null) {
            firstSeenMates.put(currentReadName, currentRecord) ;
        }
        else {
View Full Code Here

TOP

Related Classes of net.sf.samtools.SAMRecord

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.