package com.bina.varsim.types;

import com.bina.varsim.fastqLiftover.types.GenomeLocation;
import com.google.common.base.Joiner;

import java.util.ArrayList;
import java.util.Collection;

/**
 * Created by mohiyudm on 2/22/16.
 */
public class ReadMapRecord {
    protected String readName;
    private static final Joiner joiner = Joiner.on(",").skipNulls();

    protected Collection<GenomeLocation> alignmentLocations;

    public ReadMapRecord(final String readName, final Collection<GenomeLocation> alignmentLocations) {
        this.readName = readName;
        this.alignmentLocations = alignmentLocations;
    }

    public ReadMapRecord(final String line) {
        final String[] fields = line.split("\t");
        readName = fields[0];
        alignmentLocations = new ArrayList<>();
        final String locationStrings[] = fields[1].split(",", -1);
        for (String locationString : locationStrings) {
            if (!("".equals(locationString))) {
                alignmentLocations.add(new GenomeLocation(locationString));
            }
        }
    }

    public String toString() {
        return readName + "\t" + joiner.join(alignmentLocations);
    }
}

@@ -74,24 +74,24 @@
 s.Genome
-Location
+Interval
 ;%0Aimport
@@ -151,16 +151,41 @@
 ayList;%0A
+import java.util.Arrays;%0A
 import j
@@ -209,110 +209,173 @@
 on;%0A
-%0A/**%0A * Created by mohiyudm on 2/22/16.%0A */%0Apublic class ReadMapRecord %7B%0A    protected String readName
+import java.util.List;%0A%0Apublic class ReadMapRecord %7B%0A    public static final String COLUMN_SEPARATOR = %22%5Ct%22;%0A    public static final String MAP_BLOCK_SEPARATOR = %22:%22
 ;%0A  
@@ -423,19 +423,35 @@
 iner.on(
-%22,%22
+MAP_BLOCK_SEPARATOR
 ).skipNu
@@ -476,52 +476,88 @@
 ted 
-Collection%3CGenomeLocation%3E alignmentLocation
+String readName;%0A%0A    protected List%3CCollection%3CReadMapBlock%3E%3E multiReadMapBlock
 s;%0A%0A
@@ -610,16 +610,21 @@
 , final 
+List%3C
 Collecti
@@ -630,132 +630,346 @@
 ion%3C
-GenomeLocation%3E alignmentLocations) %7B%0A        this.readName = readName;%0A        this.alignmentLocations = alignmentLocations
+ReadMapBlock%3E%3E multiReadMapBlocks) %7B%0A        this.readName = readName;%0A        this.multiReadMapBlocks = multiReadMapBlocks;%0A    %7D%0A%0A    public ReadMapRecord(final String readName, final Collection%3CReadMapBlock%3E ... multiReadMapBlocks) %7B%0A        this.readName = readName;%0A        this.multiReadMapBlocks = Arrays.asList(multiReadMapBlocks)
 ;%0A  
@@ -1062,20 +1062,32 @@
 e.split(
-%22%5Ct%22
+COLUMN_SEPARATOR
 );%0A     
@@ -1119,33 +1119,161 @@
         
-alignmentLocation
+multiReadMapBlocks = new ArrayList%3C%3E();%0A        for (int i = 1; i %3C fields.length; i++) %7B%0A            final Collection%3CReadMapBlock%3E readMapBlock
 s = new 
@@ -1287,32 +1287,36 @@
 st%3C%3E();%0A        
+    
 final String loc
@@ -1308,32 +1308,31 @@
 inal String 
-location
+readMap
 Strings%5B%5D = 
@@ -1342,17 +1342,17 @@
 lds%5B
-1
+i
 %5D.split(
 %22,%22,
@@ -1351,11 +1351,27 @@
 lit(
-%22,%22
+MAP_BLOCK_SEPARATOR
 , -1
@@ -1385,28 +1385,37 @@
     
+    
 for (
+final 
 String 
-location
+readMap
 Stri
@@ -1419,24 +1419,23 @@
 tring : 
-location
+readMap
 Strings)
@@ -1453,40 +1453,62 @@
     
-if (!(%22%22.equals(location
+    readMapBlocks.add(new ReadMapBlock(readMap
 String))
 ) %7B%0A
@@ -1503,19 +1503,17 @@
 String))
-) %7B
+;
 %0A       
@@ -1521,197 +1521,506 @@
     
-    alignmentLocations.add(new GenomeLocation(locationString));%0A            %7D%0A        %7D%0A    %7D%0A%0A    public String toString() %7B%0A        return readName + %22%5Ct%22 + joiner.join(alignmentLocations
+%7D%0A            multiReadMapBlocks.add(readMapBlocks);%0A        %7D%0A    %7D%0A%0A    public String toString() %7B%0A        final StringBuilder stringBuilder = new StringBuilder();%0A        stringBuilder.append(readName);%0A        stringBuilder.append(COLUMN_SEPARATOR);%0A        for (final Collection%3CReadMapBlock%3E readMapBlocks : multiReadMapBlocks) %7B%0A            stringBuilder.append(COLUMN_SEPARATOR);%0A            stringBuilder.append(joiner.join(readMapBlocks));%0A        %7D%0A        return stringBuilder.toString(
 );%0A 

fix parsing and printing of readmaprecord