private void readNext() {
		try {	
			String line = input.reader().readLine();
			if(line != null){
				Matcher matcher = headerPattern.matcher(line);
				if(state == HaplotypeFileLineType.HEADER && matcher.matches()){
					processHeader(matcher);
					
				} else if (state != HaplotypeFileLineType.HEADER) {
					if(state != HaplotypeFileLineType.HAPLOTYPE) {
						matcher = markerPattern.matcher(line);
						if(matcher.matches()){
							markerPositions[mindex]= Integer.decode(matcher.group(1));
							mindex++;
							if(mindex == snpDomain.cardinality()){
								state = HaplotypeFileLineType.HAPLOTYPE;
								basePairDomain = new NaturalDomain(markerPositions[0], markerPositions[markerPositions.length -1]);
								readNext();
							}
						} 
					} else {
						matcher = haplotypePattern.matcher(line);
						if(matcher.matches()){
							currentHaplotype = Haplotype.decode(line, snpDomain);
						}
					}
				}
			} else {
				state = HaplotypeFileLineType.EOF;
				input.reader().close();
			}
		} catch (Exception e) {
			input.env().log().printError(e);
		}
	}