Examples of ReferenceSequenceFile


Examples of htsjdk.samtools.reference.ReferenceSequenceFile

        if (!ASSUME_SORTED && sam.getFileHeader().getSortOrder() != SAMFileHeader.SortOrder.coordinate) {
            throw new PicardException("Header of input file " + INPUT.getAbsolutePath() + " indicates that it is not coordinate sorted.  " +
            "If you believe the records are in coordinate order, pass option ASSUME_SORTED=true.  If not, sort the file with SortSam.");
        }
        final PeekableIterator<SAMRecord> iterator = new PeekableIterator<SAMRecord>(sam.iterator());
        final ReferenceSequenceFile referenceFile = ReferenceSequenceFileFactory.getReferenceSequenceFile(REFERENCE_SEQUENCE);

        {
            // Check that the sequence dictionaries match if present
            final SAMSequenceDictionary referenceDictionary= referenceFile.getSequenceDictionary();
            final SAMSequenceDictionary samFileDictionary = sam.getFileHeader().getSequenceDictionary();
            if (referenceDictionary != null && samFileDictionary != null) {
                SequenceUtil.assertSequenceDictionariesEqual(referenceDictionary, samFileDictionary);
            }
        }

        ////////////////////////////////////////////////////////////////////////////
        // Loop over the reference and the reads and calculate the basic metrics
        ////////////////////////////////////////////////////////////////////////////
        ReferenceSequence ref = null;
        final ProgressLogger
                progress = new ProgressLogger(log);
        while ((ref = referenceFile.nextSequence()) != null) {
            final byte[] refBases = ref.getBases();
            StringUtil.toUpperCase(refBases);
            final int refLength = refBases.length;
            final int lastWindowStart = refLength - WINDOW_SIZE;
View Full Code Here

Examples of htsjdk.samtools.reference.ReferenceSequenceFile

        IOUtil.assertFileIsReadable(INTERVAL_LIST);
        IOUtil.assertFileIsReadable(REFERENCE_SEQUENCE);
        IOUtil.assertFileIsWritable(OUTPUT);

        final IntervalList intervals = IntervalList.fromFile(INTERVAL_LIST);
        final ReferenceSequenceFile ref = ReferenceSequenceFileFactory.getReferenceSequenceFile(REFERENCE_SEQUENCE);
        SequenceUtil.assertSequenceDictionariesEqual(intervals.getHeader().getSequenceDictionary(), ref.getSequenceDictionary());

        final BufferedWriter out = IOUtil.openFileForBufferedWriting(OUTPUT);

        for (final Interval interval : intervals) {
            final ReferenceSequence seq = ref.getSubsequenceAt(interval.getSequence(), interval.getStart(), interval.getEnd());
            final byte[] bases = seq.getBases();
            if (interval.isNegativeStrand()) SequenceUtil.reverseComplement(bases);

            try {
                out.write(">");
View Full Code Here

Examples of htsjdk.samtools.reference.ReferenceSequenceFile

    @Override
    protected int doWork() {
        IOUtil.assertFileIsReadable(REFERENCE);
        IOUtil.assertFileIsWritable(OUTPUT);

        final ReferenceSequenceFile refFile = ReferenceSequenceFileFactory.getReferenceSequenceFile(REFERENCE, true);

        // get the intervals
        final IntervalList intervals = segregateReference(refFile, MAX_TO_MERGE);

        log.info(String.format("Found %d intervals in %d loci during %s seconds", intervalProgress.getCount(), locusProgress.getCount(), locusProgress.getElapsedSeconds()));
View Full Code Here

Examples of htsjdk.samtools.reference.ReferenceSequenceFile

        IOUtil.assertFileIsReadable(REFERENCE);
        IOUtil.assertFileIsWritable(OUTPUT);

        final SAMFileReader in = new SAMFileReader(INPUT);

        ReferenceSequenceFile reference = ReferenceSequenceFileFactory.getReferenceSequenceFile(REFERENCE);
        SAMSequenceDictionary refDict = reference.getSequenceDictionary();

        if (refDict == null) {
          log.error("No reference sequence dictionary found. Aborting.  You can create a sequence dictionary for the reference fasta using CreateSequenceDictionary.jar.");
          in.close();
          return 1;
View Full Code Here

Examples of htsjdk.samtools.reference.ReferenceSequenceFile

     * Read all the sequences from the given reference file, and convert into SAMSequenceRecords
     * @param referenceFile fasta or fasta.gz
     * @return SAMSequenceRecords containing info from the fasta, plus from cmd-line arguments.
     */
    SAMSequenceDictionary makeSequenceDictionary(final File referenceFile) {
        final ReferenceSequenceFile refSeqFile =
                ReferenceSequenceFileFactory.getReferenceSequenceFile(referenceFile, TRUNCATE_NAMES_AT_WHITESPACE);
        ReferenceSequence refSeq;
        final List<SAMSequenceRecord> ret = new ArrayList<SAMSequenceRecord>();
        final Set<String> sequenceNames = new HashSet<String>();
        for (int numSequences = 0; numSequences < NUM_SEQUENCES && (refSeq = refSeqFile.nextSequence()) != null; ++numSequences) {
            if (sequenceNames.contains(refSeq.getName())) {
                throw new PicardException("Sequence name appears more than once in reference: " + refSeq.getName());
            }
            sequenceNames.add(refSeq.getName());
            ret.add(makeSequenceRecord(refSeq));
View Full Code Here

Examples of htsjdk.samtools.reference.ReferenceSequenceFile

        if (INPUT.getAbsoluteFile().equals(OUTPUT.getAbsoluteFile())) {
            throw new IllegalArgumentException("Input and output cannot be the same file.");
        }

        final ReferenceSequenceFile ref = ReferenceSequenceFileFactory.getReferenceSequenceFile(INPUT, TRUNCATE_SEQUENCE_NAMES_AT_WHITESPACE);
        final BufferedWriter out = IOUtil.openFileForBufferedWriting(OUTPUT);

        ReferenceSequence seq = null;
        while ((seq = ref.nextSequence()) != null) {
            final String name  = seq.getName();
            final byte[] bases = seq.getBases();

            try {
                out.write(">");
View Full Code Here

Examples of htsjdk.samtools.reference.ReferenceSequenceFile

    }

    @Override
    protected int doWork() {
        IOUtil.assertFileIsReadable(INPUT);
        ReferenceSequenceFile reference = null;
        if (REFERENCE_SEQUENCE != null) {
            IOUtil.assertFileIsReadable(REFERENCE_SEQUENCE);
            reference = ReferenceSequenceFileFactory.getReferenceSequenceFile(REFERENCE_SEQUENCE);

        }
View Full Code Here

Examples of htsjdk.samtools.reference.ReferenceSequenceFile

        SequenceUtil.assertSequenceDictionariesEqual(
                reader.getFileHeader().getSequenceDictionary(),
                getProbeIntervals().getHeader().getSequenceDictionary()
        );

        ReferenceSequenceFile ref = null;
        if (REFERENCE_SEQUENCE != null) {
            IOUtil.assertFileIsReadable(REFERENCE_SEQUENCE);
            ref = ReferenceSequenceFileFactory.getReferenceSequenceFile(REFERENCE_SEQUENCE);
            SequenceUtil.assertSequenceDictionariesEqual(
                    reader.getFileHeader().getSequenceDictionary(), ref.getSequenceDictionary(),
                    INPUT, REFERENCE_SEQUENCE
            );
        }

        final COLLECTOR collector = makeCollector(
View Full Code Here

Examples of htsjdk.samtools.reference.ReferenceSequenceFile

        final SAMSequenceRecord record = new SAMSequenceRecord("fake1", referenceString.length());
        final SAMSequenceDictionary dictionary = new SAMSequenceDictionary();
        dictionary.addSequence(record);

        final ReferenceSequenceFile reference = new ReferenceSequenceFile() {

            boolean done = false;

            @Override
            public SAMSequenceDictionary getSequenceDictionary() {
View Full Code Here

Examples of net.sf.picard.reference.ReferenceSequenceFile

    }

    WriteHeader(OUTPUT_FORMAT, out);

    //initialize reference
    ReferenceSequenceFile reference_file = ReferenceSequenceFileFactory.getReferenceSequenceFile(REFERENCE_SEQUENCE);

    //initialize auxiliary data
    InitKnownCalls();
    InitSummaryMetrics();

    //initialize SAM/BAM data iterators

    List<SamPositionIterator> positionIterators = new ArrayList<SamPositionIterator>();

    if (REGION_FILE != null) {
      BufferedReader region_reader = null;
      String line = null;
      try {
        region_reader = new BufferedReader(new FileReader(REGION_FILE));
      } catch (FileNotFoundException e) {
        e.printStackTrace()//To change body of catch statement use File | Settings | File Templates.
      }

      try {

        while ((line = region_reader.readLine()) != null) {
          String[] tokens = line.split(":");

          String seq_name = tokens[0];
          String positions = tokens[1];

          tokens = positions.split("-");

          int start = 0, end = 0;
          try {
            start = Integer.parseInt(tokens[0]);
            end = Integer.parseInt(tokens[1]);
          } catch (Exception e) {
            System.err.println("Error parsing definition string");
          }

          SamPositionIterator position_iterator = new SamPositionIterator(INPUT, MINIMUM_COVERAGE, MAXIMUM_COVERAGE, MINIMUM_MAPQ, MIN_MATE_DISTANCE, MAX_MATE_DISTANCE, MINIMUM_BASE_QUALITY, MIN_ALIGNMENT_SCORE, seq_name, start, end);
          positionIterators.add(position_iterator);
        }
      } catch (IOException e) {
        e.printStackTrace()//To change body of catch statement use File | Settings | File Templates.
      }
    } else if (REGION.equals("")) {
      SamPositionIterator position_iterator = new SamPositionIterator(INPUT, MINIMUM_COVERAGE, MAXIMUM_COVERAGE, MINIMUM_MAPQ, MIN_MATE_DISTANCE, MAX_MATE_DISTANCE, MINIMUM_BASE_QUALITY, MIN_ALIGNMENT_SCORE);
      positionIterators.add(position_iterator);
    } else {
      //split the region string into sequence name/beginning/end
      String[] tokens = REGION.split(",");
      int start = 0, end = 0;

      try {
        start = Integer.parseInt(tokens[1]);
        end = Integer.parseInt(tokens[2]);
      } catch (Exception e) {
        System.err.println("Error parsing definition string");
      }
      SamPositionIterator position_iterator = new SamPositionIterator(INPUT, MINIMUM_COVERAGE, MAXIMUM_COVERAGE, MINIMUM_MAPQ, MIN_MATE_DISTANCE, MAX_MATE_DISTANCE, MINIMUM_BASE_QUALITY, MIN_ALIGNMENT_SCORE, tokens[0], start, end);
      positionIterators.add(position_iterator);
    }

    SolSNPCaller s = new SolSNPCaller(STRAND_MODE, CALL_BIAS, PLOIDY);
    SNPCall SNP = new SNPCall();
    SNPCall known_call = new SNPCall();

    int coverage;
    int previous_position = 0;

    final Map<SNPCallPair, TreeMap<Integer, Long>> calltable_validation = new HashMap<SNPCallPair, TreeMap<Integer, Long>>();

    ReferenceSequence reference = null;

    while ((reference = reference_file.nextSequence()) != null) {
      for (SamPositionIterator position_iterator : positionIterators) {
        position_iterator.nextSequence();
        String ref_name = reference.getName();

        if (!position_iterator.getCurrentSequence().equals(ref_name))
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.