Package net.sf.samtools

Examples of net.sf.samtools.SAMFileReader$AssertableIterator


        String bam_file = "/data/kimjh/WGS/simulation_test_chr1/seperate_10p/chr1_sim_70x_sorted_rmdup.bam";
        String bam_index_file = "/data/kimjh/WGS/simulation_test_chr1/seperate_10p/chr1_sim_70x_sorted_rmdup.bam.bai";
        File bam = new File(bam_file);
        File bam_index = new File(bam_index_file);
        SAMFileReader samReader = new SAMFileReader(bam, bam_index);
        String chr_id = "chr1";
        int start = 1;
        int end = 20;
//        int end = 247199724;
        Interval interval = new Interval(chr_id, start, end);
        IntervalList il = new IntervalList(samReader.getFileHeader());
        il.add(interval);
       
        SamLocusIterator sli = new SamLocusIterator(samReader, il, true);

        FileWriter fw = new FileWriter("/data/kimjh/WGS/simulation_test_chr1/seperate_10p/gatk/depth_diff.txt");
        BufferedWriter bw = new BufferedWriter(fw);

        for (Iterator<SamLocusIterator.LocusInfo> iter = sli.iterator(); iter.hasNext();) {
            SamLocusIterator.LocusInfo locusInfo = iter.next();
            List recordList = locusInfo.getRecordAndPositions();
            Iterator it = recordList.iterator();
            String readBase = "";
            String baseQuality = "";
            while(it.hasNext()){
                SamLocusIterator.RecordAndOffset record = (SamLocusIterator.RecordAndOffset) it.next();
                if(baseQuality.equals("")){
//                    readBase += Byte.toString(record.getReadBase());
//                    baseQuality += record.getBaseQuality();
                    readBase += (char)(record.getReadBase()&0xff);
                    baseQuality += (int)((record.getBaseQuality()));
                }else{
                    readBase += ","+(char)(record.getReadBase()&0xff);
                    baseQuality += ","+(int)((record.getBaseQuality()));
                }
            }

            System.out.println("chr1\t"+locusInfo.getPosition()+"\t"+locusInfo.getRecordAndPositions().size()+"\t"+readBase+"\t"+baseQuality+"\n");
//            bw.write("chr1\t"+locusInfo.getPosition()+"\t"+locusInfo.getRecordAndPositions().size()+"\n");
            int pos = locusInfo.getPosition();
            int size = locusInfo.getRecordAndPositions().size();

            if (temp != null) {
                t = temp.split("\t");
                int sam_pos = Integer.parseInt(t[1]);
                int sam_size = Integer.parseInt(t[2]);

                while (sam_pos <= pos && temp != null) {
                    t = temp.split("\t");
                    sam_pos = Integer.parseInt(t[1]);
                    sam_size = Integer.parseInt(t[2]);
                    if (sam_pos == pos) {
                        if (sam_size != size) {
                            if(pos%1000000==0){
                                System.out.println(pos);
                            }                           
                            bw.write(pos + "\t" + size + "\t" + sam_size + "\n");
                        }
                        temp = br.readLine();
                    } else if(sam_pos>pos){                       
                    }else{
                        temp = br.readLine();
                    }
                }
            }
        }
        br.close();
        fr.close();

        bw.flush();
        bw.close();
        fw.close();

        sli.close();
        samReader.close();
    }
View Full Code Here


        File bamFile = new File(inputBam);
//        File bamFile = new File(InputParameter.getBamFile());
        File bamIndexFile = new File(inputBamIndex);
//        File bamIndexFile = new File(InputParameter.getBamIndexFile());
        SAMFileReader samReader = new SAMFileReader(bamFile, bamIndexFile);
        samReader.setValidationStringency(SAMFileReader.ValidationStringency.LENIENT);

        int i = 0;
        while (temp != null) {
            if (!temp.equals("")) {
                if (temp.contains("DEL")) {
                    DeletionInfo di = new DeletionInfo(temp);
                    if (di.getSize() > insertSize) {
//                        di.setDeletionInfo(samReader);
                        deletionList.add(di);
                    }
                }
            }
            temp = br.readLine();
            i++;
            if (i % 100 == 0) {
                System.out.println(i + " th deletion is imported ...");
            }
        }

        samReader.close();

        br.close();
        fr.close();
    }
View Full Code Here

        File bamFile = new File(inputBam);
//        File bamFile = new File(InputParameter.getBamFile());
        File bamIndexFile = new File(inputBamIndex);
//        File bamIndexFile = new File(InputParameter.getBamIndexFile());
        SAMFileReader samReader = new SAMFileReader(bamFile, bamIndexFile);
        samReader.setValidationStringency(SAMFileReader.ValidationStringency.LENIENT);

        int chrNo = deletionList.size();
        for (int i = 1; i < chrNo; i++) {
            ArrayList<DeletionInfo> chrDel = (ArrayList) deletionList.get(i);
            Collections.sort(chrDel, new DeletionComparator());
        }

        int delNo = 0;
        for (int i = 1; i < chrNo; i++) {
            ArrayList<DeletionInfo> chrDel = (ArrayList) deletionList.get(i);
            int chrDelSize = chrDel.size();
            for (int j = 0; j < chrDelSize; j++) {
                DeletionInfo sdi = (DeletionInfo) chrDel.get(j);
                if (!sdi.isGap()) {
                    int window1 = sdi.getWindowStart();
                    int window2 = sdi.getWindowEnd();
                    ArrayList overlappedAreaList = new ArrayList();

                    for (int k = 0; k < chrDelSize; k++) {
                        if (j != k) {
                            DeletionInfo tdi = (DeletionInfo) chrDel.get(k);
                            int tgt1 = tdi.getPos1();
                            int tgt2 = tdi.getPos2();
                            if (tgt1 > window2) {
                                break;
                            }
                            if ((window1 <= tgt1 && window2 >= tgt1) || (window1 <= tgt2 && window2 >= tgt2)) {
                                Integer[] overlappedArea = getOverlappedArea(window1, window2, tgt1, tgt2);
                                overlappedAreaList.add(overlappedArea);
                            }
                        }
                    }

                    sdi.setDeletionInfo(samReader, overlappedAreaList);
                    delNo++;
                    if (delNo % 100 == 0) {
                        System.out.println(delNo + " th deletion's information is analyzed ...");
                    }
                }
            }
        }

        samReader.close();
    }
View Full Code Here

    return next_position_info;
  }

  public SamPositionIterator (File file, int min_coverage, int max_coverage, int min_mapq, int min_mate_distance, int max_mate_distance, int min_base_quality, int min_alignment_score, String sequence, int start, int end) {
    samReader = new SAMFileReader(file, new File(file.getAbsolutePath() + ".bai"));

    assert (samReader.getFileHeader().getSortOrder() == SortOrder.coordinate); // The implementation assumes coordinates sorting.

    samRecordIterator = samReader.query(sequence, start, end, true);
View Full Code Here

    nextRecord();
  }

  public SamPositionIterator (File file, int min_coverage, int max_coverage, int min_mapq, int min_mate_distance, int max_mate_distance, int min_base_quality, int min_alignment_score) {
    samReader = new SAMFileReader(file);

    assert (samReader.getFileHeader().getSortOrder() == SortOrder.coordinate); // The implementation assumes coordinates sorting.
    samRecordIterator = samReader.iterator();

    this.minCoverage = min_coverage;
View Full Code Here

  private File input;
  private SAMFileReader input_reader;

  public AllelicBalancer (File file) {
    input_reader = new SAMFileReader(file);
    //System.out.println(input_reader.getFileHeader().getSequenceDictionary().getSequences().size());
  }
View Full Code Here

    c2r.init(reference);
    this.minBaseQual = minBaseQual;
   
    System.err.println("Processing positions");

    SAMFileReader normalReader = new SAMFileReader(new File(normal));
    normalReader.setValidationStringency(ValidationStringency.SILENT);
   
    SAMFileReader tumorReader = new SAMFileReader(new File(tumor));
    normalReader.setValidationStringency(ValidationStringency.SILENT);
       
    for (LocusInfo locus : loci) {
      locus.normalCounts = getCounts(normalReader, locus);
      locus.tumorCounts = getCounts(tumorReader, locus);
    }
   
    normalReader.close();
    tumorReader.close();
   
    System.err.println("Writing results");
   
    outputResults();
  }
View Full Code Here

    RegionLoader loader = new RegionLoader();
    regions = loader.load(regionsGtf);
   
//    printRegionHeader();
   
    SAMFileReader reader = new SAMFileReader(new File(inputSam));
    reader.setValidationStringency(ValidationStringency.SILENT);

    SAMFileWriter output = new SAMFileWriterFactory().makeSAMOrBAMWriter(
        reader.getFileHeader(), true, new File(outputSam));

    int cnt = 0;
   
    for (SAMRecord read : reader) {
      if (!inRegion(read)) {
        output.addAlignment(read);
      }
     
      cnt++;
      if ((cnt % 1000000) == 0) {
        System.out.println(cnt);
      }
    }
   
    reader.close();
    output.close();
  }
View Full Code Here

    RegionLoader loader = new RegionLoader();
    regions = loader.load(regionsGtf);
   
    printRegionHeader();
   
    SAMFileReader reader = new SAMFileReader(new File(inputSam));
    reader.setValidationStringency(ValidationStringency.SILENT);
   
    for (Feature region : regions) {
      int count = 0;
      SAMRecordIterator iter = reader.queryOverlapping(region.getSeqname(), (int) region.getStart(), (int) region.getEnd());
      while (iter.hasNext()) {
        iter.next();
        count += 1;
      }
      iter.close();
      System.out.print(count + ",");
    }
   
    reader.close();
  }
View Full Code Here

  private int numRecords = 0;

    public SamMultiMappingReader(String filename) {
        File inputFile = new File(filename);
       
        inputSam = new SAMFileReader(inputFile);
        inputSam.setValidationStringency(ValidationStringency.SILENT);
 
        iter = inputSam.iterator();
    }
View Full Code Here

TOP

Related Classes of net.sf.samtools.SAMFileReader$AssertableIterator

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.