2009-06-10 09:52:25 +08:00
|
|
|
package org.broadinstitute.sting.gatk.walkers;
|
|
|
|
|
|
|
|
|
|
import org.broadinstitute.sting.BaseTest;
|
2009-06-12 02:13:22 +08:00
|
|
|
import org.broadinstitute.sting.gatk.datasources.shards.Shard;
|
|
|
|
|
import org.broadinstitute.sting.gatk.datasources.providers.ShardDataProvider;
|
2010-05-20 07:27:55 +08:00
|
|
|
import org.broadinstitute.sting.gatk.contexts.ReferenceContext;
|
2009-06-10 09:52:25 +08:00
|
|
|
import org.broadinstitute.sting.utils.sam.ArtificialReadsTraversal;
|
|
|
|
|
import org.broadinstitute.sting.utils.sam.ArtificialSAMFileWriter;
|
2009-06-12 01:46:06 +08:00
|
|
|
import org.broadinstitute.sting.utils.sam.ArtificialSAMUtils;
|
2009-06-10 09:52:25 +08:00
|
|
|
import org.junit.Before;
|
|
|
|
|
import org.junit.Test;
|
|
|
|
|
import static org.junit.Assert.assertEquals;
|
|
|
|
|
import static org.junit.Assert.assertTrue;
|
|
|
|
|
import net.sf.samtools.SAMRecord;
|
|
|
|
|
import net.sf.samtools.SAMFileHeader;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Copyright (c) 2009 The Broad Institute
|
|
|
|
|
*
|
|
|
|
|
* Permission is hereby granted, free of charge, to any person
|
|
|
|
|
* obtaining a copy of this software and associated documentation
|
|
|
|
|
* files (the "Software"), to deal in the Software without
|
|
|
|
|
* restriction, including without limitation the rights to use,
|
|
|
|
|
* copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
|
* copies of the Software, and to permit persons to whom the
|
|
|
|
|
* Software is furnished to do so, subject to the following
|
|
|
|
|
* conditions:
|
|
|
|
|
*
|
|
|
|
|
* The above copyright notice and this permission notice shall be
|
|
|
|
|
* included in all copies or substantial portions of the Software.
|
|
|
|
|
*
|
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
|
|
|
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
|
|
|
|
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
|
|
|
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
|
|
|
|
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
|
|
|
|
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
|
|
|
|
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
|
|
|
|
* OTHER DEALINGS IN THE SOFTWARE.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @author aaron
|
|
|
|
|
* <p/>
|
2010-04-08 14:14:15 +08:00
|
|
|
* Class PrintReadsWalkerUnitTest
|
2009-06-10 09:52:25 +08:00
|
|
|
* <p/>
|
|
|
|
|
* This tests the print reads walker, using the artificial reads traversal
|
|
|
|
|
*/
|
2010-04-08 14:14:15 +08:00
|
|
|
public class PrintReadsWalkerUnitTest extends BaseTest {
|
2009-06-10 09:52:25 +08:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* our private fake reads traversal. This traversal seeds the
|
|
|
|
|
* the walker with a specified number of fake reads, which are named sequentially
|
|
|
|
|
*/
|
|
|
|
|
private ArtificialReadsTraversal trav;
|
|
|
|
|
private int readTotal = 0;
|
2010-05-20 07:27:55 +08:00
|
|
|
//private char bases[] = {'a', 't'};
|
|
|
|
|
private ReferenceContext bases = null;
|
|
|
|
|
//private ReferenceContext ref = new ReferenceContext()
|
2009-06-10 09:52:25 +08:00
|
|
|
|
|
|
|
|
@Before
|
|
|
|
|
public void before() {
|
|
|
|
|
trav = new ArtificialReadsTraversal();
|
|
|
|
|
readTotal = ( ( trav.endingChr - trav.startingChr ) + 1 ) * trav.readsPerChr + trav.unMappedReads;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/** test that we get out the same number of reads we put in */
|
|
|
|
|
@Test
|
|
|
|
|
public void testReadCount() {
|
|
|
|
|
PrintReadsWalker walker = new PrintReadsWalker();
|
|
|
|
|
ArtificialSAMFileWriter writer = new ArtificialSAMFileWriter();
|
2010-02-25 08:16:50 +08:00
|
|
|
trav.traverse(walker, null, writer);
|
2009-06-10 09:52:25 +08:00
|
|
|
assertEquals(readTotal, writer.getRecords().size());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/** test that we're ok with a null read */
|
|
|
|
|
@Test
|
|
|
|
|
public void testNullRead() {
|
|
|
|
|
PrintReadsWalker walker = new PrintReadsWalker();
|
|
|
|
|
|
2010-03-03 23:56:44 +08:00
|
|
|
SAMRecord rec = walker.map(bases, null, null);
|
2009-06-10 09:52:25 +08:00
|
|
|
assertTrue(rec == null);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/** tes that we get the read we put into the map function */
|
|
|
|
|
@Test
|
|
|
|
|
public void testReturnRead() {
|
|
|
|
|
PrintReadsWalker walker = new PrintReadsWalker();
|
2009-06-12 01:46:06 +08:00
|
|
|
SAMFileHeader head = ArtificialSAMUtils.createArtificialSamHeader(3,1,1000);
|
|
|
|
|
SAMRecord rec = ArtificialSAMUtils.createArtificialRead(head, "FakeRead", 1, 1, 50);
|
2010-03-03 23:56:44 +08:00
|
|
|
SAMRecord ret = walker.map(bases, rec,null);
|
2009-06-10 09:52:25 +08:00
|
|
|
assertTrue(ret == rec);
|
|
|
|
|
assertTrue(ret.getReadName().equals(rec.getReadName()));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/** test that the read makes it to the output source */
|
|
|
|
|
@Test
|
|
|
|
|
public void testReducingRead() {
|
|
|
|
|
PrintReadsWalker walker = new PrintReadsWalker();
|
2009-06-12 01:46:06 +08:00
|
|
|
SAMFileHeader head = ArtificialSAMUtils.createArtificialSamHeader(3,1,1000);
|
|
|
|
|
SAMRecord rec = ArtificialSAMUtils.createArtificialRead(head, "FakeRead", 1, 1, 50);
|
2009-06-10 09:52:25 +08:00
|
|
|
ArtificialSAMFileWriter writer = new ArtificialSAMFileWriter();
|
2010-03-03 23:56:44 +08:00
|
|
|
SAMRecord ret = walker.map(bases, null,null);
|
2009-06-10 09:52:25 +08:00
|
|
|
walker.reduce(ret,writer);
|
|
|
|
|
|
|
|
|
|
assertTrue(writer.getRecords().size() == 1);
|
|
|
|
|
}
|
|
|
|
|
|
2009-10-03 03:35:35 +08:00
|
|
|
|
2009-06-10 09:52:25 +08:00
|
|
|
}
|