Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Mirrors
biopet.biopet
Commits
30633108
Commit
30633108
authored
Jul 21, 2016
by
Peter van 't Hof
Browse files
Added simple test on main
parent
99b31701
Changes
2
Hide whitespace changes
Inline
Side-by-side
biopet-tools/src/main/scala/nl/lumc/sasc/biopet/tools/bamstats/BamStats.scala
View file @
30633108
...
...
@@ -87,12 +87,10 @@ object BamStats extends ToolCommand {
*/
def
init
(
outputDir
:
File
,
bamFile
:
File
,
referenceDict
:
SAMSequenceDictionary
,
binSize
:
Int
,
threadBinSize
:
Int
)
:
Unit
=
{
val
contigsFutures
=
BedRecordList
.
fromDict
(
referenceDict
).
allRecords
.
map
{
contig
=>
Future
{
processContig
(
contig
,
bamFile
,
binSize
,
threadBinSize
,
outputDir
)
}
processContig
(
contig
,
bamFile
,
binSize
,
threadBinSize
,
outputDir
)
}
val
unmappedFuture
=
Future
{
processUnmappedReads
(
bamFile
)
}
val
stats
=
waitOnFutures
(
unmappedFuture
::
contigsFutures
.
toList
)
val
stats
=
waitOnFutures
(
processUnmappedReads
(
bamFile
)
::
contigsFutures
.
toList
)
stats
.
writeStatsToFiles
(
outputDir
)
}
...
...
@@ -106,11 +104,11 @@ object BamStats extends ToolCommand {
* @param threadBinSize Thread binsize
* @return Output stats
*/
def
processContig
(
region
:
BedRecord
,
bamFile
:
File
,
binSize
:
Int
,
threadBinSize
:
Int
,
outputDir
:
File
)
:
Stats
=
{
def
processContig
(
region
:
BedRecord
,
bamFile
:
File
,
binSize
:
Int
,
threadBinSize
:
Int
,
outputDir
:
File
)
:
Future
[
Stats
]
=
Future
{
val
scattersFutures
=
region
.
scatter
(
binSize
)
.
grouped
((
region
.
length
.
toDouble
/
binSize
).
ceil
.
toInt
/
(
region
.
length
.
toDouble
/
threadBinSize
).
ceil
.
toInt
)
.
map
(
scatters
=>
Future
{
processThread
(
scatters
,
bamFile
)
}
)
.
map
(
scatters
=>
processThread
(
scatters
,
bamFile
))
.
toList
val
stats
=
waitOnFutures
(
scattersFutures
,
Some
(
region
.
chr
))
val
contigDir
=
new
File
(
outputDir
,
"contigs"
+
File
.
separator
+
region
.
chr
)
...
...
@@ -153,7 +151,7 @@ object BamStats extends ToolCommand {
* @param bamFile Input bamfile
* @return Output stats
*/
def
processThread
(
scatters
:
List
[
BedRecord
],
bamFile
:
File
)
:
Stats
=
{
def
processThread
(
scatters
:
List
[
BedRecord
],
bamFile
:
File
)
:
Future
[
Stats
]
=
Future
{
val
totalStats
=
Stats
()
val
sortedScatters
=
scatters
.
sortBy
(
_
.
start
)
val
samReader
=
SamReaderFactory
.
makeDefault
().
open
(
bamFile
)
...
...
@@ -203,7 +201,7 @@ object BamStats extends ToolCommand {
* @param bamFile Input bamfile
* @return Output stats
*/
def
processUnmappedReads
(
bamFile
:
File
)
:
Stats
=
{
def
processUnmappedReads
(
bamFile
:
File
)
:
Future
[
Stats
]
=
Future
{
val
stats
=
Stats
()
val
samReader
=
SamReaderFactory
.
makeDefault
().
open
(
bamFile
)
for
(
samRecord
<-
samReader
.
queryUnmapped
())
{
...
...
biopet-tools/src/test/scala/nl/lumc/sasc/biopet/tools/bamstats/BamStatsTest.scala
0 → 100644
View file @
30633108
package
nl.lumc.sasc.biopet.tools.bamstats
import
java.io.File
import
java.nio.file.Paths
import
com.google.common.io.Files
import
org.scalatest.Matchers
import
org.scalatest.testng.TestNGSuite
import
org.testng.annotations.Test
/**
* Created by pjvan_thof on 21-7-16.
*/
class
BamStatsTest
extends
TestNGSuite
with
Matchers
{
@Test
def
testMain
:
Unit
=
{
val
outputDir
=
Files
.
createTempDir
()
outputDir
.
deleteOnExit
()
BamStats
.
main
(
Array
(
"-b"
,
BamStatsTest
.
pairedBam01
.
getAbsolutePath
,
"-o"
,
outputDir
.
getAbsolutePath
))
new
File
(
outputDir
,
"flagstats"
)
should
exist
new
File
(
outputDir
,
"flagstats.summary.json"
)
should
exist
new
File
(
outputDir
,
"mapping_quality.tsv"
)
should
exist
new
File
(
outputDir
,
"insert_size.tsv"
)
should
exist
new
File
(
outputDir
,
"clipping.tsv"
)
should
exist
new
File
(
outputDir
,
"left_clipping.tsv"
)
should
exist
new
File
(
outputDir
,
"right_clipping.tsv"
)
should
exist
new
File
(
outputDir
,
"5_prime_clipping.tsv"
)
should
exist
new
File
(
outputDir
,
"3_prime_clipping.tsv"
)
should
exist
}
}
object
BamStatsTest
{
private
def
resourcePath
(
p
:
String
)
:
String
=
{
Paths
.
get
(
getClass
.
getResource
(
p
).
toURI
).
toString
}
val
pairedBam01
=
new
File
(
resourcePath
(
"/paired01.bam"
))
}
\ No newline at end of file
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment