Search in sources :

Example 1 with MappingQualityFilter

use of htsjdk.samtools.filter.MappingQualityFilter in project ASCIIGenome by dariober.

the class UtilsTest method canCountReadsInWindow.

@Test
public void canCountReadsInWindow() throws InvalidGenomicCoordsException, IOException {
    GenomicCoords gc = new GenomicCoords("chr7:5522436-5613572", 80, samSeqDict, fastaFile);
    List<SamRecordFilter> filters = new ArrayList<SamRecordFilter>();
    // Same as
    filters.add(new MappingQualityFilter(30));
    // samtools view -q 30 -f 64
    filters.add(new FirstOfPairFilter(true));
    long t0 = System.currentTimeMillis();
    for (int i = 0; i < 10; i++) {
        assertEquals(42770, Utils.countReadsInWindow("test_data/ear045.oxBS.actb.bam", gc, filters));
    }
    long t1 = System.currentTimeMillis();
    System.out.println("TIME TO FILTER: " + (t1 - t0));
    gc = new GenomicCoords("chr7:5524838-5611878", 80, samSeqDict, fastaFile);
}
Also used : MappingQualityFilter(htsjdk.samtools.filter.MappingQualityFilter) SamRecordFilter(htsjdk.samtools.filter.SamRecordFilter) FirstOfPairFilter(filter.FirstOfPairFilter) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 2 with MappingQualityFilter

use of htsjdk.samtools.filter.MappingQualityFilter in project ASCIIGenome by dariober.

the class TrackSet method setSamFilterForRegex.

/**
 * Method to set any of the three alignment filters: -F,-f, mapq
 * @throws SQLException
 * @throws InvalidRecordException
 * @throws InvalidGenomicCoordsException
 * @throws IOException
 * @throws ClassNotFoundException
 * @throws MalformedURLException
 */
public void setSamFilterForRegex(List<String> cmdInput) throws InvalidCommandLineException, MalformedURLException, ClassNotFoundException, IOException, InvalidGenomicCoordsException, InvalidRecordException, SQLException {
    // MEMO of subcommand syntax:
    // "-F INT -f INT -q INT re1 re2 ..."
    // * All optional. But -F, -f, -q are given they take one INT as arg.
    List<String> args = new ArrayList<String>();
    for (String x : cmdInput) {
        args.add(x);
    }
    // Remove name of command
    args.remove(0);
    // Defaults:
    int f = Integer.valueOf(Filter.DEFAULT_f_FLAG.getValue());
    int F = Integer.valueOf(Filter.DEFAULT_F_FLAG.getValue());
    int q = Integer.valueOf(Filter.DEFAULT_MAPQ.getValue());
    // Get args:
    boolean invertSelection = Utils.argListContainsFlag(args, "-v");
    if (args.contains("-f")) {
        int idx = args.indexOf("-f") + 1;
        f = Integer.parseInt(args.get(idx));
        args.remove(idx);
        args.remove("-f");
    }
    if (args.contains("-F")) {
        int idx = args.indexOf("-F") + 1;
        F = Integer.parseInt(args.get(idx));
        if ((4 & F) == 0) {
            F += 4;
        }
        args.remove(idx);
        args.remove("-F");
    }
    if (args.contains("-q")) {
        int idx = args.indexOf("-q") + 1;
        q = Integer.parseInt(args.get(idx));
        args.remove(idx);
        args.remove("-q");
    }
    // What is left is positional args of regexes
    List<String> trackNameRegex = new ArrayList<String>();
    trackNameRegex.addAll(args);
    if (trackNameRegex.size() == 0) {
        // Default regex for matching tracks
        trackNameRegex.add(".*");
    }
    // Get tracks to reset:
    List<Track> tracksToReset = this.matchTracks(trackNameRegex, true, invertSelection);
    if (tracksToReset.size() == 0) {
        System.err.println("No track matching regex " + trackNameRegex);
    }
    for (Track tr : tracksToReset) {
        tr.set_f_flag(f);
        tr.set_F_flag(F);
        tr.setMapq(q);
        List<SamRecordFilter> filters = new ArrayList<SamRecordFilter>();
        filters.addAll(FlagToFilter.flagToFilterList(f, F));
        filters.add(new MappingQualityFilter(q));
        tr.setSamRecordFilter(filters);
    }
}
Also used : MappingQualityFilter(htsjdk.samtools.filter.MappingQualityFilter) SamRecordFilter(htsjdk.samtools.filter.SamRecordFilter) ArrayList(java.util.ArrayList)

Example 3 with MappingQualityFilter

use of htsjdk.samtools.filter.MappingQualityFilter in project ASCIIGenome by dariober.

the class TrackPileupTest method canFilterReadsSamtools.

@Test
public void canFilterReadsSamtools() throws InvalidGenomicCoordsException, IOException, ClassNotFoundException, InvalidRecordException, SQLException, InvalidColourException {
    GenomicCoords gc = new GenomicCoords("chr7:5566778", 80, null, null);
    TrackPileup tr = new TrackPileup("test_data/ds051.short.bam", gc);
    tr.setNoFormat(true);
    // Before filtering
    assertTrue(tr.getTitle().contains("22.0"));
    List<SamRecordFilter> samRecordFilter = new ArrayList<SamRecordFilter>();
    samRecordFilter.add(new MappingQualityFilter(51));
    tr.setSamRecordFilter(samRecordFilter);
    assertEquals("", tr.printToScreen().trim());
    samRecordFilter = new ArrayList<SamRecordFilter>();
    samRecordFilter.add(new MappingQualityFilter(11));
    tr.setSamRecordFilter(samRecordFilter);
    assertTrue(tr.getTitle().contains("17.0"));
}
Also used : GenomicCoords(samTextViewer.GenomicCoords) MappingQualityFilter(htsjdk.samtools.filter.MappingQualityFilter) SamRecordFilter(htsjdk.samtools.filter.SamRecordFilter) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 4 with MappingQualityFilter

use of htsjdk.samtools.filter.MappingQualityFilter in project ASCIIGenome by dariober.

the class UtilsTest method canCountReadsInWindow2.

@Test
public void canCountReadsInWindow2() throws InvalidGenomicCoordsException, IOException {
    GenomicCoords gc = new GenomicCoords("chr7:5524838-5611878", 80, samSeqDict, fastaFile);
    List<SamRecordFilter> filters = new ArrayList<SamRecordFilter>();
    assertEquals(100377, Utils.countReadsInWindow("test_data/ear045.oxBS.actb.bam", gc, filters));
    filters.add(new AlignedFilter(true));
    assertEquals(100265, Utils.countReadsInWindow("test_data/ear045.oxBS.actb.bam", gc, filters));
    filters = new ArrayList<SamRecordFilter>();
    filters.add(new AlignedFilter(true));
    filters.add(new ReadNegativeStrandFilter(false));
    assertEquals(50157, Utils.countReadsInWindow("test_data/ear045.oxBS.actb.bam", gc, filters));
    filters = new ArrayList<SamRecordFilter>();
    filters.add(new AlignedFilter(true));
    filters.add(new ReadNegativeStrandFilter(true));
    assertEquals(50108, Utils.countReadsInWindow("test_data/ear045.oxBS.actb.bam", gc, filters));
    filters = FlagToFilter.flagToFilterList(80, 1026);
    assertEquals(2729, Utils.countReadsInWindow("test_data/ear045.oxBS.actb.bam", gc, filters));
    filters = FlagToFilter.flagToFilterList(80, 1026);
    filters.add(new MappingQualityFilter(30));
    assertEquals(1592, Utils.countReadsInWindow("test_data/ear045.oxBS.actb.bam", gc, filters));
}
Also used : MappingQualityFilter(htsjdk.samtools.filter.MappingQualityFilter) SamRecordFilter(htsjdk.samtools.filter.SamRecordFilter) AlignedFilter(htsjdk.samtools.filter.AlignedFilter) ArrayList(java.util.ArrayList) ReadNegativeStrandFilter(filter.ReadNegativeStrandFilter) Test(org.junit.Test)

Aggregations

MappingQualityFilter (htsjdk.samtools.filter.MappingQualityFilter)4 SamRecordFilter (htsjdk.samtools.filter.SamRecordFilter)4 ArrayList (java.util.ArrayList)4 Test (org.junit.Test)3 FirstOfPairFilter (filter.FirstOfPairFilter)1 ReadNegativeStrandFilter (filter.ReadNegativeStrandFilter)1 AlignedFilter (htsjdk.samtools.filter.AlignedFilter)1 GenomicCoords (samTextViewer.GenomicCoords)1