Search in sources :

Example 96 with GenomicCoords

use of samTextViewer.GenomicCoords in project ASCIIGenome by dariober.

the class TrackIntervalFeatureTest method canApplyAwk_getFeaturesInInterval.

@Test
public void canApplyAwk_getFeaturesInInterval() throws IOException, InvalidGenomicCoordsException, ClassNotFoundException, InvalidRecordException, SQLException {
    String intervalFileName = "test_data/hg19_genes_head.gtf.gz";
    GenomicCoords gc = new GenomicCoords("chr1:10000-100000", 80, null, null);
    TrackIntervalFeature tif = new TrackIntervalFeature(intervalFileName, gc);
    String awk = "'$3 == \"start_codon\" && $9 !~ \"OR4F\"'";
    // Note use single quotes
    tif.setAwk(awk);
    // Check -F arg has been prepended.
    assertEquals("-F '\\t' " + awk, tif.getAwk());
    List<IntervalFeature> subset = tif.getFeaturesInInterval("chr1", 1, 500000000);
    assertEquals(40, subset.size());
    // Filter for feature size > x
    tif.setAwk("-F \\t '($5 - $4) > 1000'");
    subset = tif.getFeaturesInInterval("chr1", 1, 500000000);
    assertEquals(23, subset.size());
    // Remove filter w/o args.
    tif.setAwk("  ");
    subset = tif.getFeaturesInInterval("chr1", 1, 500000000);
    assertEquals(1000, subset.size());
    // Invalid script: Ugly stackTrace printed. All records returned
    boolean pass = false;
    try {
        tif.setAwk("$foo");
    } catch (InvalidGenomicCoordsException e) {
        pass = true;
    }
    assertTrue(pass);
    // Faulty script has been removed.
    assertEquals("", tif.getAwk());
    subset = tif.getFeaturesInInterval("chr1", 1, 500000000);
    assertEquals(1000, subset.size());
    // awk output is neither empty nor equal to input
    // Exception expected.
    pass = false;
    try {
        tif.setAwk("'{print 999}'");
    } catch (InvalidGenomicCoordsException e) {
        pass = true;
    }
    assertTrue(pass);
}
Also used : GenomicCoords(samTextViewer.GenomicCoords) InvalidGenomicCoordsException(exceptions.InvalidGenomicCoordsException) Test(org.junit.Test)

Example 97 with GenomicCoords

use of samTextViewer.GenomicCoords in project ASCIIGenome by dariober.

the class TrackIntervalFeatureTest method canConstructTrackfromGtf.

@Test
public void canConstructTrackfromGtf() throws IOException, InvalidGenomicCoordsException, ClassNotFoundException, InvalidRecordException, SQLException {
    String intervalFileName = "test_data/hg19_genes.gtf.gz";
    GenomicCoords gc = new GenomicCoords("chr1:1-13000", 80, null, null);
    TrackIntervalFeature tif = new TrackIntervalFeature(intervalFileName, gc);
    gc = new GenomicCoords("chr7:5566000-5571000", 80, null, null);
    tif = new TrackIntervalFeature(intervalFileName, gc);
    System.out.println(tif);
}
Also used : GenomicCoords(samTextViewer.GenomicCoords) Test(org.junit.Test)

Example 98 with GenomicCoords

use of samTextViewer.GenomicCoords in project ASCIIGenome by dariober.

the class TrackIntervalFeatureTest method canFetchInterval.

@Test
public void canFetchInterval() throws IOException, InvalidGenomicCoordsException, ClassNotFoundException, InvalidRecordException, SQLException {
    GenomicCoords gc = new GenomicCoords("chr18:1-10000", 80, null, null);
    TrackIntervalFeature tif = new TrackIntervalFeature("test_data/refSeq.hg19.short.bed", gc);
    List<IntervalFeature> interval = tif.getFeaturesInInterval("chr1", 20000000, 40000000);
    // Note adding 1 because bed is 0-based
    assertEquals(25167428 + 1, interval.get(0).getFrom());
    assertEquals(33586132, interval.get(interval.size() - 1).getTo());
    // Nothing to fetch: Range not in bed
    tif = new TrackIntervalFeature("test_data/refSeq.hg19.short.bed", gc);
    interval = tif.getFeaturesInInterval("chr1", 500000000, 600000000);
    assertEquals(0, interval.size());
    // Nothing to fetch: chrom not in bed:
    interval = tif.getFeaturesInInterval("chrNonSense", 1, 10);
    assertEquals(0, interval.size());
}
Also used : GenomicCoords(samTextViewer.GenomicCoords) Test(org.junit.Test)

Example 99 with GenomicCoords

use of samTextViewer.GenomicCoords in project ASCIIGenome by dariober.

the class TrackIntervalFeatureTest method canReadTabixGTFFromHTTP.

@Test
public void canReadTabixGTFFromHTTP() throws IOException, InvalidGenomicCoordsException, ClassNotFoundException, InvalidRecordException, SQLException {
    // If this file does not exist, put any valid tabix file and its index on Dropbox/Public and use
    // the dropbox link here.
    GenomicCoords gc = new GenomicCoords("chr1:64000-74000", 80, null, null);
    TrackIntervalFeature tif = new TrackIntervalFeature("https://raw.githubusercontent.com/dariober/ASCIIGenome/master/test_data/hg19_genes_head.gtf.gz", gc);
    // We check the working file is on the remote server.
    assertEquals("http", tif.getFilename().substring(0, 4));
    // Check we are using the remote file as working file. I.e. no need to download and index.
    assertEquals("http", tif.getWorkFilename().substring(0, 4));
    assertEquals(4, tif.getIntervalFeatureList().size());
}
Also used : GenomicCoords(samTextViewer.GenomicCoords) Test(org.junit.Test)

Example 100 with GenomicCoords

use of samTextViewer.GenomicCoords in project ASCIIGenome by dariober.

the class TrackIntervalFeatureTest method canFindAllRegex.

@Test
public void canFindAllRegex() throws IOException, InvalidGenomicCoordsException, ClassNotFoundException, InvalidRecordException, SQLException {
    GenomicCoords gc = new GenomicCoords("chr18:1-10000", 80, null, null);
    TrackIntervalFeature tif = new TrackIntervalFeature("test_data/hg19_genes_head.gtf", gc);
    GenomicCoords matched = tif.genomicCoordsAllChromMatchInGenome(Pattern.compile(".*\"WASH7P\".*"), gc);
    assertEquals("chr1", matched.getChrom());
    assertEquals(14362, (int) matched.getFrom());
    assertEquals(29370, (int) matched.getTo());
    // No match
    gc = new GenomicCoords("chr18:1-10000", 80, null, null);
    tif = new TrackIntervalFeature("test_data/hg19_genes_head.gtf", gc);
    matched = tif.genomicCoordsAllChromMatchInGenome(Pattern.compile(".*\"FOOBAR\".*"), gc);
    assertEquals("chr18", matched.getChrom());
    assertEquals(1, (int) matched.getFrom());
    assertEquals(10000, (int) matched.getTo());
}
Also used : GenomicCoords(samTextViewer.GenomicCoords) Test(org.junit.Test)

Aggregations

GenomicCoords (samTextViewer.GenomicCoords)156 Test (org.junit.Test)147 File (java.io.File)10 ArrayList (java.util.ArrayList)9 Config (coloring.Config)8 VCFFileReader (htsjdk.variant.vcf.VCFFileReader)8 VCFHeader (htsjdk.variant.vcf.VCFHeader)8 SAMRecord (htsjdk.samtools.SAMRecord)6 InvalidCommandLineException (exceptions.InvalidCommandLineException)3 InvalidGenomicCoordsException (exceptions.InvalidGenomicCoordsException)1 MappingQualityFilter (htsjdk.samtools.filter.MappingQualityFilter)1 SamRecordFilter (htsjdk.samtools.filter.SamRecordFilter)1 IOException (java.io.IOException)1 TrackReads (tracks.TrackReads)1