// Path: src/libra/common/helpers/PathHelper.java
// public class PathHelper {
//     
//     private static final String[] COMPRESSED_EXT = {"gz", "bz2"};
//     
//     public static String getParent(String path) {
//         // check root
//         if(path.equals("/")) {
//             return null;
//         }
//         
//         int lastIdx = path.lastIndexOf("/");
//         if(lastIdx > 0) {
//             return path.substring(0, lastIdx);
//         } else {
//             return "/";
//         }
//     }
//     
//     public static String concatPath(String path1, String path2) {
//         StringBuffer sb = new StringBuffer();
//         
//         if(path1 != null && !path1.isEmpty()) {
//             sb.append(path1);
//         }
//         
//         if(!path1.endsWith("/")) {
//             sb.append("/");
//         }
//         
//         if(path2 != null && !path2.isEmpty()) {
//             if(path2.startsWith("/")) {
//                 sb.append(path2.substring(1, path2.length()));
//             } else {
//                 sb.append(path2);
//             }
//         }
//         
//         return sb.toString();
//     }
//     
//     public static String getExtensionOfDecompressedFile(String name) {
//         String myname = name;
//         int idx = myname.lastIndexOf(".");
//         if(idx > 0) {
//             String ext = myname.substring(idx + 1);
//             for(String cext : COMPRESSED_EXT) {
//                 if(cext.equalsIgnoreCase(ext)) {
//                     // compressed
//                     myname = myname.substring(0, idx);
//                     break;
//                 }
//             }
//         } else {
//             return null;
//         }
//         
//         idx = myname.lastIndexOf(".");
//         if(idx > 0) {
//             return myname.substring(idx + 1);
//         }
//         return null;
//     }
// }
// 
// Path: src/libra/preprocess/common/PreprocessorConstants.java
// public class PreprocessorConstants {
//     public static final String FILE_TABLE_FILENAME_EXTENSION = "ftbl";
//     public static final String KMER_FILTER_TABLE_FILENAME_EXTENSION = "kflt";
//     public static final String KMER_INDEX_TABLE_FILENAME_EXTENSION = "kidx";
//     public static final String KMER_INDEX_DATA_FILENAME_EXTENSION = "kidxc";
//     public static final String KMER_STATISTICS_TABLE_FILENAME_EXTENSION = "kstat";
//     
//     public static final String FILE_TABLE_DIRNAME = "filetable";
//     public static final String KMER_FILTER_DIRNAME = "filter";
//     public static final String KMER_INDEX_DIRNAME = "kmerindex";
//     public static final String KMER_STATISITCS_DIRNAME = "statistics";
// }
// 
// Path: src/libra/preprocess/common/kmerstatistics/KmerStatisticsPartTablePathFilter.java
// public class KmerStatisticsPartTablePathFilter implements PathFilter {
// 
//     @Override
//     public boolean accept(Path path) {
//         return KmerStatisticsHelper.isKmerStatisticsPartTableFile(path);
//     }
// }


import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import libra.common.helpers.PathHelper;
import libra.preprocess.common.PreprocessorConstants;
import libra.preprocess.common.kmerstatistics.KmerStatisticsPartTablePathFilter;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FileStatus;
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path;
    public static String makeKmerStatisticsDirPath(String rootPath) {
        return PathHelper.concatPath(rootPath, PreprocessorConstants.KMER_STATISITCS_DIRNAME);
    }
    
    public static boolean isKmerStatisticsTableFile(Path path) {
        return isKmerStatisticsTableFile(path.getName());
    }
    
    public static boolean isKmerStatisticsTableFile(String path) {
        Matcher matcher = KMER_STATISTICS_TABLE_PATH_PATTERN.matcher(path.toLowerCase());
        if(matcher.matches()) {
            return true;
        }
        return false;
    }
    
    public static boolean isKmerStatisticsPartTableFile(Path path) {
        return isKmerStatisticsPartTableFile(path.getName());
    }
    
    public static boolean isKmerStatisticsPartTableFile(String path) {
        Matcher matcher = KMER_STATISTICS_PART_TABLE_PATH_PATTERN.matcher(path.toLowerCase());
        if(matcher.matches()) {
            return true;
        }
        return false;
    }
    
    public static Path[] getKmerStatisticsPartTableFilePaths(Configuration conf, Path inputPath) throws IOException {
        List<Path> inputFiles = new ArrayList<Path>();
// Path: src/libra/common/helpers/PathHelper.java
// public class PathHelper {
//     
//     private static final String[] COMPRESSED_EXT = {"gz", "bz2"};
//     
//     public static String getParent(String path) {
//         // check root
//         if(path.equals("/")) {
//             return null;
//         }
//         
//         int lastIdx = path.lastIndexOf("/");
//         if(lastIdx > 0) {
//             return path.substring(0, lastIdx);
//         } else {
//             return "/";
//         }
//     }
//     
//     public static String concatPath(String path1, String path2) {
//         StringBuffer sb = new StringBuffer();
//         
//         if(path1 != null && !path1.isEmpty()) {
//             sb.append(path1);
//         }
//         
//         if(!path1.endsWith("/")) {
//             sb.append("/");
//         }
//         
//         if(path2 != null && !path2.isEmpty()) {
//             if(path2.startsWith("/")) {
//                 sb.append(path2.substring(1, path2.length()));
//             } else {
//                 sb.append(path2);
//             }
//         }
//         
//         return sb.toString();
//     }
//     
//     public static String getExtensionOfDecompressedFile(String name) {
//         String myname = name;
//         int idx = myname.lastIndexOf(".");
//         if(idx > 0) {
//             String ext = myname.substring(idx + 1);
//             for(String cext : COMPRESSED_EXT) {
//                 if(cext.equalsIgnoreCase(ext)) {
//                     // compressed
//                     myname = myname.substring(0, idx);
//                     break;
//                 }
//             }
//         } else {
//             return null;
//         }
//         
//         idx = myname.lastIndexOf(".");
//         if(idx > 0) {
//             return myname.substring(idx + 1);
//         }
//         return null;
//     }
// }
// 
// Path: src/libra/preprocess/common/PreprocessorConstants.java
// public class PreprocessorConstants {
//     public static final String FILE_TABLE_FILENAME_EXTENSION = "ftbl";
//     public static final String KMER_FILTER_TABLE_FILENAME_EXTENSION = "kflt";
//     public static final String KMER_INDEX_TABLE_FILENAME_EXTENSION = "kidx";
//     public static final String KMER_INDEX_DATA_FILENAME_EXTENSION = "kidxc";
//     public static final String KMER_STATISTICS_TABLE_FILENAME_EXTENSION = "kstat";
//     
//     public static final String FILE_TABLE_DIRNAME = "filetable";
//     public static final String KMER_FILTER_DIRNAME = "filter";
//     public static final String KMER_INDEX_DIRNAME = "kmerindex";
//     public static final String KMER_STATISITCS_DIRNAME = "statistics";
// }
// 
// Path: src/libra/preprocess/common/kmerstatistics/KmerStatisticsPartTablePathFilter.java
// public class KmerStatisticsPartTablePathFilter implements PathFilter {
// 
//     @Override
//     public boolean accept(Path path) {
//         return KmerStatisticsHelper.isKmerStatisticsPartTableFile(path);
//     }
// }


// Path: src/libra/preprocess/common/helpers/KmerStatisticsHelper.java
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import libra.common.helpers.PathHelper;
import libra.preprocess.common.PreprocessorConstants;
import libra.preprocess.common.kmerstatistics.KmerStatisticsPartTablePathFilter;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FileStatus;
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path;

    public static String makeKmerStatisticsDirPath(String rootPath) {
        return PathHelper.concatPath(rootPath, PreprocessorConstants.KMER_STATISITCS_DIRNAME);
    }
    
    public static boolean isKmerStatisticsTableFile(Path path) {
        return isKmerStatisticsTableFile(path.getName());
    }
    
    public static boolean isKmerStatisticsTableFile(String path) {
        Matcher matcher = KMER_STATISTICS_TABLE_PATH_PATTERN.matcher(path.toLowerCase());
        if(matcher.matches()) {
            return true;
        }
        return false;
    }
    
    public static boolean isKmerStatisticsPartTableFile(Path path) {
        return isKmerStatisticsPartTableFile(path.getName());
    }
    
    public static boolean isKmerStatisticsPartTableFile(String path) {
        Matcher matcher = KMER_STATISTICS_PART_TABLE_PATH_PATTERN.matcher(path.toLowerCase());
        if(matcher.matches()) {
            return true;
        }
        return false;
    }
    
    public static Path[] getKmerStatisticsPartTableFilePaths(Configuration conf, Path inputPath) throws IOException {
        List<Path> inputFiles = new ArrayList<Path>();
        KmerStatisticsPartTablePathFilter filter = new KmerStatisticsPartTablePathFilter();