Examples of AsciiLineReader


Examples of htsjdk.tribble.readers.AsciiLineReader

        int classCol = 11;
        int famCol = 12;

        Map<String, LinkedHashMap<String, String>> fileMappings = new HashMap();

        AsciiLineReader reader = null;
        HashMap<String, PrintWriter> writers = new HashMap();
        try {
            String lastChr = "";
            reader = new AsciiLineReader(new FileInputStream(file));
            // Skip header
            reader.readLine();
            String nextLine;
            while ((nextLine = reader.readLine()) != null) {
                String[] tokens = Globals.tabPattern.split(nextLine, -1);
                String chr = tokens[chrCol];
                if (!chr.equals(lastChr)) {
                    closeWriters(writers);
                }
                lastChr = chr;

                String repClass = tokens[classCol];
                if (repClass.contains("?")) {
                    continue;
                }
                String fileKey = chr + "." + repClass;

                // Get or create file writer for the class + chr combination
                PrintWriter pw = writers.get(fileKey);
                if (pw == null) {

                    File dir = new File(file.getParent(), repClass);
                    if (!dir.exists()) {
                        dir.mkdir();
                        fileMappings.put(repClass, new LinkedHashMap<String, String>());
                    }

                    Map<String, String> fMap = fileMappings.get(repClass);
                    String fn = fileKey + ".bed";
                    fMap.put(chr, fn);

                    File outputFile = new File(dir, fn);
                    pw = new PrintWriter(new FileWriter(outputFile));
                    writers.put(fileKey, pw);
                }

                String name = "Repeat " + tokens[4] + ", family " + tokens[6];

                pw.print(chr);
                pw.print("\t");
                pw.print(Integer.parseInt(tokens[startCol]));
                pw.print("\t");
                pw.print(Integer.parseInt(tokens[endCol]));
                pw.print("\t");
                pw.print(name);
                pw.print("\t");
                pw.print(tokens[strandCol]);
                pw.println();

            }

            // Ouput filemapping files
            for (Map.Entry<String, LinkedHashMap<String, String>> entry : fileMappings.entrySet()) {
                String repClass = entry.getKey();
                File dir = new File(file.getParent(), repClass);
                File listFile = new File(dir, repClass + "_files.list.txt");
                Properties props = new Properties();
                for (Map.Entry<String, String> entry2 : entry.getValue().entrySet()) {
                    props.put(entry2.getKey(), entry2.getValue());
                }
                FileOutputStream os = new FileOutputStream(listFile);
                props.store(os, "");
                os.close();
            }

        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            reader.close();
            closeWriters(writers);
        }

    }
View Full Code Here

Examples of htsjdk.tribble.readers.AsciiLineReader

     * is the track identifier (name) for mutation files.
     *
     * @return
     */
    private Map<String, List<htsjdk.tribble.Feature>> loadMutations() {
        AsciiLineReader reader = null;
        String nextLine = null;

        try {

            if (codec == null) codec = new MUTCodec(locator.getPath(), genome);

            Map<String, List<htsjdk.tribble.Feature>> mutationMap = new LinkedHashMap();

            reader = ParsingUtils.openAsciiReader(locator);

            // Skip header - handled in codec
            while ((nextLine = reader.readLine()) != null) {
                if (nextLine.startsWith("#")) continue;
                else break;

            }

            while ((nextLine = reader.readLine()) != null) {

                Mutation mut = codec.decode(nextLine);

                if (mut != null) {
                    String sampleId = mut.getSampleId();
                    List<htsjdk.tribble.Feature> features = mutationMap.get(sampleId);
                    if (features == null) {
                        features = new ArrayList<Feature>();
                        mutationMap.put(sampleId, features);
                    }


                    features.add(mut);
                }
            }


            return mutationMap;
        } catch (IOException e) {
            log.error("Error loading mutation file", e);
            throw new DataLoadException("IO Exception: " + e.toString(), locator.getPath());
        } finally {
            reader.close();
        }
    }
View Full Code Here

Examples of htsjdk.tribble.readers.AsciiLineReader

        WalkerTestSpec spec = new WalkerTestSpec("-T UnifiedGenotyper -R " + b37KGReference + " -I "
                + privateTestDir + "PCRFree.2x250.Illumina.20_10_11.bam"
                + " -o %s -L 20:10,000,000-10,100,000 -nt 4",
                1, Arrays.asList("vcf.gz"), Arrays.asList(""));
        final File vcf = executeTest("testCompressedVCFOutputWithNT", spec).first.get(0);
        final AsciiLineReader reader = new AsciiLineReader(new BlockCompressedInputStream(vcf));
        int nLines = 0;
        while ( reader.readLine() != null )
            nLines++;
        Assert.assertTrue(nLines > 0);
    }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.