@@ -114,18 +114,19 @@ class MAFToGVCF {
114
114
val sampleName = variantsMap.keys.first()
115
115
116
116
// sort the variants by contig and position.
117
- val variants = variantsMap.values.first().sortedWith( VariantContextComparator (contigList))
117
+ val variants = variantsMap.values.first().sortedBy { Position (it.chr,it.startPos) }
118
118
119
- exportVariantContext(sampleName, variants, gvcfOutput, refSeqs)
119
+ exportVariantContext(sampleName, variants, gvcfOutput, refSeqs, outJustGT, delAsSymbolic, maxDeletionSize )
120
120
if (compressAndIndex) {
121
121
// compress and index the file with bgzip and tabix.
122
122
compressAndIndexFile(gvcfOutput)
123
123
}
124
124
} else if (variantsMap.size == 2 ) {
125
125
val outputNames = twoOutputFiles(gvcfOutput)
126
126
variantsMap.entries.forEachIndexed { index, (name, variants) ->
127
- val sortedVariants = variants.sortedWith(VariantContextComparator (contigList))
128
- val outputFile = exportVariantContext(name, sortedVariants, outputNames[index], refSeqs)
127
+ val sortedVariants = variants.sortedBy { Position (it.chr,it.startPos) }
128
+
129
+ val outputFile = exportVariantContext(name, sortedVariants, outputNames[index], refSeqs, outJustGT, delAsSymbolic, maxDeletionSize)
129
130
if (compressAndIndex) {
130
131
compressAndIndexFile(outputNames[index])
131
132
}
@@ -149,28 +150,28 @@ class MAFToGVCF {
149
150
delAsSymbolic : Boolean = false,
150
151
maxDeletionSize : Int = 0,
151
152
anchorwaveLegacy : Boolean = false
152
- ): Map <String , List <VariantContext >> {
153
+ ): Map <String , List <AssemblyVariantInfo >> {
153
154
154
155
val mafRecords = loadMAFRecords(mafFile)
155
156
return if (twoGvcfs) {
156
157
val splitGenomes = splitMafRecordsIntoTwoGenomes(mafRecords)
157
158
158
159
if (splitGenomes.size == 1 ) {
159
160
println (" getVariantContextsfromMAF:twoGvcfs is true but only 1 genome in the MAF file. Processing the single genome" )
160
- mapOf (sampleName to buildVariantsForAllAlignments(sampleName, mafRecords, refSeqs, fillGaps,outJustGT,outputType, delAsSymbolic, maxDeletionSize , anchorwaveLegacy))
161
+ mapOf (sampleName to buildVariantsForAllAlignments(mafRecords, refSeqs, fillGaps, outputType , anchorwaveLegacy))
161
162
} else {
162
- splitGenomes.mapIndexed { index, mafrecs ->
163
+ splitGenomes.mapIndexed { index, splitMafRecords ->
163
164
// append _1 and _2 to the sampleName for the split genomes
164
165
165
166
val genomeName = " ${sampleName} _${index + 1 } "
166
167
println (" MAFToGVCF:getVariantContextsfromMAF: Splitting ${sampleName} into ${genomeName} " )
167
- Pair (genomeName, buildVariantsForAllAlignments(genomeName, mafrecs, refSeqs, fillGaps, outJustGT, outputType, delAsSymbolic, maxDeletionSize , anchorwaveLegacy))
168
+ Pair (genomeName, buildVariantsForAllAlignments(splitMafRecords, refSeqs, fillGaps, outputType, anchorwaveLegacy))
168
169
}.toMap()
169
170
}
170
171
171
172
} else {
172
173
println (" getVariantContextsfromMAF: Processing a single genome" )
173
- mapOf (sampleName to buildVariantsForAllAlignments(sampleName, mafRecords, refSeqs, fillGaps, outJustGT, outputType, delAsSymbolic, maxDeletionSize , anchorwaveLegacy))
174
+ mapOf (sampleName to buildVariantsForAllAlignments(mafRecords, refSeqs, fillGaps, outputType, anchorwaveLegacy))
174
175
}
175
176
176
177
}
@@ -237,16 +238,12 @@ class MAFToGVCF {
237
238
* Function to build the variants for all the alignments.
238
239
*/
239
240
fun buildVariantsForAllAlignments (
240
- sampleName : String ,
241
241
mafRecords : List <MAFRecord >,
242
242
refGenomeSequence : Map <String , NucSeq >,
243
243
fillGaps : Boolean ,
244
- outJustGT : Boolean ,
245
244
outputType : OUTPUT_TYPE ,
246
- delAsSymbolic : Boolean ,
247
- maxDeletionSize : Int ,
248
245
anchorwaveLegacy : Boolean = false
249
- ): List <VariantContext > {
246
+ ): List <AssemblyVariantInfo > {
250
247
var variantInfos = mutableListOf<AssemblyVariantInfo >()
251
248
252
249
for (record in mafRecords) {
@@ -263,7 +260,7 @@ class MAFToGVCF {
263
260
variantInfos = fillInMissingVariantBlocks(variantInfos, refGenomeSequence, true )
264
261
}
265
262
266
- return createVariantContextsFromInfo(sampleName, variantInfos, outJustGT, delAsSymbolic, maxDeletionSize)
263
+ return variantInfos
267
264
}
268
265
269
266
fun removeRefBlocks (variantInfos : MutableList <AssemblyVariantInfo >) : MutableList <AssemblyVariantInfo > {
@@ -1117,9 +1114,12 @@ class MAFToGVCF {
1117
1114
*/
1118
1115
fun exportVariantContext (
1119
1116
sampleName : String ,
1120
- variantContexts : List <VariantContext >,
1117
+ variantContexts : List <AssemblyVariantInfo >,
1121
1118
outputFileName : String ,
1122
- refGenomeSequence : Map <String , NucSeq >
1119
+ refGenomeSequence : Map <String , NucSeq >,
1120
+ outputJustGT : Boolean ,
1121
+ delAsSymbolic : Boolean ,
1122
+ maxDeletionSize : Int
1123
1123
) {
1124
1124
val writer = VariantContextWriterBuilder ()
1125
1125
.unsetOption(Options .INDEX_ON_THE_FLY )
@@ -1132,7 +1132,7 @@ class MAFToGVCF {
1132
1132
addSequenceDictionary(header, refGenomeSequence)
1133
1133
writer.writeHeader(header)
1134
1134
for (variant in variantContexts) {
1135
- writer.add(variant)
1135
+ writer.add(convertVariantInfoToContext(sampleName, variant, outputJustGT, delAsSymbolic, maxDeletionSize) )
1136
1136
}
1137
1137
1138
1138
writer.close()
0 commit comments