package com.bina.varsim.util;

import com.bina.varsim.types.ReadMapRecord;
import org.apache.log4j.Logger;

import java.io.BufferedReader;
import java.io.File;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.HashMap;
import java.util.Map;

/**
 * Created by mohiyudm on 2/29/16.
 */
public class ReadMap extends GzFileParser<ReadMapRecord>{
    private final static Logger log = Logger.getLogger(ReadMap.class.getName());

    protected Map<String, ReadMapRecord> readMap = new HashMap<>();

    public ReadMap(final File file) throws IOException {
        log.info("Loading read alignment map from " + file);
        bufferedReader = new BufferedReader(new InputStreamReader(decompressStream(file)));
        while (hasMoreInput()) {
            readLine();
            log.trace("Parsing line " + line);
            if (line == null || line.trim().isEmpty()) {
                break;
            }
            final ReadMapRecord record = parseLine();
            readMap.put(record.getReadName(), record);
        }
        log.info("Done loading read alignment map");
    }

    public ReadMapRecord parseLine() {
        return hasMoreInput() ? new ReadMapRecord(line.trim()) : null;
    }

    public ReadMapRecord getReadMapRecord(final String readName) {
        return readMap.containsKey(readName) ? readMap.get(readName) : null;
    }
}

@@ -862,12 +862,49 @@
 null
- %7C%7C 
+)%0A                break;%0A            if (
 line
@@ -921,18 +921,16 @@
 Empty())
- %7B
 %0A       
@@ -942,28 +942,17 @@
     
-break;%0A            %7D
+continue;
 %0A   

fix an issue for map file containing empty lines