Search in sources :

Example 21 with SamReaderFactory

use of htsjdk.samtools.SamReaderFactory in project jvarkit by lindenb.

the class BamStats01 method doWork.

@Override
public int doWork(final List<String> inputs) {
    final List<String> args = new ArrayList<>(IOUtils.unrollFiles(inputs));
    try {
        this.out = super.openFileOrStdoutAsPrintStream(this.outputFile);
        out.print("#Filename\tSample");
        for (Category2 cat2 : Category2.values()) {
            for (Category cat1 : Category.values()) {
                // je je suis libertineuuh, je suis une cat1
                out.print("\t" + cat2 + "_" + cat1);
            }
            if (bedFile == null)
                break;
        }
        out.println();
        final SamReaderFactory srf = super.createSamReaderFactory();
        if (args.isEmpty()) {
            final SamReader r = srf.open(SamInputResource.of(stdin()));
            run("stdin", r);
            r.close();
        } else {
            for (final String filename : args) {
                LOG.info("Reading from " + filename);
                final SamReader sfr = srf.open(new File(filename));
                run(filename, sfr);
                sfr.close();
            }
        }
        out.flush();
        this.out.flush();
        this.out.close();
        return RETURN_OK;
    } catch (Exception e) {
        LOG.error(e);
        return -1;
    } finally {
        CloserUtil.close(out);
    }
}
Also used : SamReader(htsjdk.samtools.SamReader) SamReaderFactory(htsjdk.samtools.SamReaderFactory) ArrayList(java.util.ArrayList) File(java.io.File) IOException(java.io.IOException)

Example 22 with SamReaderFactory

use of htsjdk.samtools.SamReaderFactory in project jvarkit by lindenb.

the class BamStats02 method doWork.

@Override
public int doWork(List<String> args) {
    SamReader samFileReader = null;
    PrintWriter out = null;
    try {
        if (bedFile != null) {
            LOG.info("Reading BED file " + bedFile);
            this.intervals = super.readBedFileAsBooleanIntervalTreeMap(bedFile);
        }
        out = super.openFileOrStdoutAsPrintWriter(outputFile);
        boolean first = true;
        out.print("#");
        for (final STRING_PROPS p : STRING_PROPS.values()) {
            if (!first)
                out.print("\t");
            first = false;
            out.print(p.name());
        }
        for (final INT_PROPS p : INT_PROPS.values()) {
            out.print("\t");
            out.print(p.name());
        }
        for (final SAMFlag flg : SAMFlag.values()) {
            out.print("\t");
            out.print(flg.name());
        }
        out.print("\t");
        out.print("count");
        out.println();
        final SamReaderFactory srf = super.createSamReaderFactory();
        if (args.isEmpty()) {
            LOG.info("Reading from stdin");
            samFileReader = srf.open(SamInputResource.of(stdin()));
            run("stdin", samFileReader, out);
            samFileReader.close();
            samFileReader = null;
        } else {
            for (final String filename : IOUtils.unrollFiles(args)) {
                LOG.info("Reading from " + filename);
                samFileReader = srf.open(new File(filename));
                run(filename, samFileReader, out);
                samFileReader.close();
                samFileReader = null;
            }
        }
        out.flush();
        return RETURN_OK;
    } catch (Exception err) {
        LOG.error(err);
        return -1;
    } finally {
        CloserUtil.close(samFileReader);
        CloserUtil.close(out);
    }
}
Also used : SamReader(htsjdk.samtools.SamReader) SamReaderFactory(htsjdk.samtools.SamReaderFactory) SAMFlag(htsjdk.samtools.SAMFlag) File(java.io.File) PrintWriter(java.io.PrintWriter)

Example 23 with SamReaderFactory

use of htsjdk.samtools.SamReaderFactory in project jvarkit by lindenb.

the class Biostar172515 method doWork.

@Override
public int doWork(final List<String> inputFiles) {
    final SamReaderFactory samReaderFactory = SamReaderFactory.makeDefault().setOption(SamReaderFactory.Option.CACHE_FILE_BASED_INDEXES, Boolean.TRUE).validationStringency(ValidationStringency.LENIENT);
    OutputStream stream = null;
    SamReader samReader = null;
    Set<String> args = IOUtils.unrollFiles(inputFiles);
    try {
        stream = super.openFileOrStdoutAsStream(this.outputFile);
        XMLOutputFactory xof = XMLOutputFactory.newFactory();
        this.w = xof.createXMLStreamWriter(stream);
        this.w.writeStartDocument("UTF-8", "1.0");
        this.w.writeStartElement("bai-list");
        for (final String filename : args) {
            this.w.writeStartElement("bam");
            this.w.writeAttribute("bam", filename);
            samReader = samReaderFactory.open(SamInputResource.of(filename));
            this.w.writeAttribute("has-index", String.valueOf(samReader.hasIndex()));
            if (!samReader.hasIndex()) {
                this.w.writeEndElement();
                samReader.close();
                continue;
            }
            final SamReader.Indexing indexing = samReader.indexing();
            if (!indexing.hasBrowseableIndex()) {
                this.w.writeComment("no browseable index");
                this.w.writeEndElement();
                samReader.close();
                continue;
            }
            final SAMSequenceDictionary dict = samReader.getFileHeader().getSequenceDictionary();
            this.w.writeAttribute("n_ref", String.valueOf(dict.size()));
            final BrowseableBAMIndex baiFile;
            try {
                baiFile = indexing.getBrowseableIndex();
            } catch (Exception err) {
                this.w.writeComment("no browseable index");
                this.w.writeEndElement();
                samReader.close();
                continue;
            }
            for (int tid = 0; tid < dict.size(); ++tid) {
                final SAMSequenceRecord ssr = dict.getSequence(tid);
                final BAMIndexMetaData baiMetaData = baiFile.getMetaData(tid);
                this.w.writeStartElement("reference");
                this.w.writeAttribute("ref-id", String.valueOf(tid));
                this.w.writeAttribute("ref-name", ssr.getSequenceName());
                this.w.writeAttribute("ref-length", String.valueOf(ssr.getSequenceLength()));
                this.w.writeAttribute("n_aligned", String.valueOf(baiMetaData.getAlignedRecordCount()));
                BinList binList = baiFile.getBinsOverlapping(tid, 1, ssr.getSequenceLength());
                int n_bin = 0;
                for (@SuppressWarnings("unused") final Bin binItem : binList) n_bin++;
                this.w.writeAttribute("n_bin", String.valueOf(n_bin));
                this.w.writeAttribute("n_no_coor", String.valueOf(baiMetaData.getUnalignedRecordCount()));
                for (final Bin binItem : binList) {
                    this.w.writeStartElement("bin");
                    this.w.writeAttribute("first-locus", String.valueOf(baiFile.getFirstLocusInBin(binItem)));
                    this.w.writeAttribute("last-locus", String.valueOf(baiFile.getLastLocusInBin(binItem)));
                    this.w.writeAttribute("level", String.valueOf(baiFile.getLevelForBin(binItem)));
                    final BAMFileSpan span = baiFile.getSpanOverlapping(binItem);
                    this.w.writeAttribute("first-offset", String.valueOf(span.getFirstOffset()));
                    final List<Chunk> chunks = span.getChunks();
                    this.w.writeAttribute("n_chunk", String.valueOf(chunks.size()));
                    for (final Chunk chunk : chunks) {
                        this.w.writeEmptyElement("chunk");
                        this.w.writeAttribute("chunk_beg", String.valueOf(chunk.getChunkStart()));
                        this.w.writeAttribute("chunk_end", String.valueOf(chunk.getChunkEnd()));
                    }
                    this.w.writeEndElement();
                }
                this.w.writeEndElement();
            }
            this.w.writeEndElement();
            samReader.close();
        }
        this.w.writeEndElement();
        this.w.flush();
        this.w.close();
        return 0;
    } catch (final Exception err) {
        LOG.error(err);
        return -1;
    } finally {
        CloserUtil.close(this.w);
        CloserUtil.close(stream);
        CloserUtil.close(samReader);
        this.w = null;
    }
}
Also used : BrowseableBAMIndex(htsjdk.samtools.BrowseableBAMIndex) XMLOutputFactory(javax.xml.stream.XMLOutputFactory) SamReaderFactory(htsjdk.samtools.SamReaderFactory) BAMIndexMetaData(htsjdk.samtools.BAMIndexMetaData) Bin(htsjdk.samtools.Bin) OutputStream(java.io.OutputStream) BAMFileSpan(htsjdk.samtools.BAMFileSpan) SAMSequenceRecord(htsjdk.samtools.SAMSequenceRecord) Chunk(htsjdk.samtools.Chunk) SAMSequenceDictionary(htsjdk.samtools.SAMSequenceDictionary) SamReader(htsjdk.samtools.SamReader) BinList(htsjdk.samtools.BinList)

Example 24 with SamReaderFactory

use of htsjdk.samtools.SamReaderFactory in project jvarkit by lindenb.

the class BioAlcidae method execute_bam.

private int execute_bam(String source) throws IOException {
    SamReader in = null;
    SAMRecordIterator iter = null;
    try {
        SamReaderFactory srf = SamReaderFactory.makeDefault().validationStringency(ValidationStringency.SILENT);
        if (source == null) {
            in = srf.open(SamInputResource.of(stdin()));
        } else {
            in = srf.open(SamInputResource.of(source));
        }
        iter = in.iterator();
        bindings.put("header", in.getFileHeader());
        bindings.put("iter", iter);
        bindings.put("format", "sam");
        this.script.eval(bindings);
        this.writer.flush();
        return RETURN_OK;
    } catch (Exception e) {
        LOG.error(e);
        return -1;
    } finally {
        CloserUtil.close(in);
        CloserUtil.close(iter);
        bindings.remove("header");
        bindings.remove("iter");
        bindings.remove("format");
    }
}
Also used : SamReader(htsjdk.samtools.SamReader) SAMRecordIterator(htsjdk.samtools.SAMRecordIterator) SamReaderFactory(htsjdk.samtools.SamReaderFactory) RuntimeIOException(htsjdk.samtools.util.RuntimeIOException) XMLStreamException(javax.xml.stream.XMLStreamException) IOException(java.io.IOException) JAXBException(javax.xml.bind.JAXBException)

Example 25 with SamReaderFactory

use of htsjdk.samtools.SamReaderFactory in project jvarkit by lindenb.

the class IgvReview method start.

@Override
public void start(final Stage stage) throws Exception {
    stage.setTitle(getClass().getSimpleName());
    Predicate<VariantContext> ctxFilter;
    Map<String, String> params = super.getParameters().getNamed();
    if (params.containsKey("--filter")) {
        ctxFilter = JexlVariantPredicate.create(params.get("--filter"));
    } else {
        ctxFilter = V -> true;
    }
    final List<String> args = super.getParameters().getUnnamed();
    final File configFile;
    if (args.isEmpty()) {
        final FileChooser fc = new FileChooser();
        final String lastDirStr = preferences.get(LAST_USED_DIR_KEY, null);
        if (lastDirStr != null && !lastDirStr.isEmpty()) {
            fc.setInitialDirectory(new File(lastDirStr));
        }
        fc.getExtensionFilters().addAll(Collections.singletonList(new FileChooser.ExtensionFilter("Config file", "*.config", "*.cfg", "*.list")));
        configFile = fc.showOpenDialog(stage);
    } else if (args.size() == 1) {
        configFile = new File(args.get(0));
    } else {
        configFile = null;
    }
    if (configFile == null || !configFile.exists()) {
        JfxUtils.dialog().cause("Illegal number of arguments or file doesn't exists.").show(stage);
        Platform.exit();
        return;
    }
    if (configFile.isFile() && configFile.getParentFile() != null) {
        this.preferences.put(LAST_USED_DIR_KEY, configFile.getParentFile().getPath());
    }
    final List<String> configLines = Files.readAllLines(configFile.toPath());
    final Predicate<String> ignoreComment = (S) -> !S.startsWith("#");
    final Predicate<String> predVcf = S -> S.endsWith(".vcf") || S.endsWith(".vcf.gz");
    if (configLines.stream().filter(ignoreComment).filter(predVcf).count() != 1) {
        JfxUtils.dialog().cause("Found more than one vcf file in " + configFile).show(stage);
        Platform.exit();
        return;
    }
    final File vcfFile = configLines.stream().filter(ignoreComment).filter(predVcf).map(S -> new File(S)).findFirst().get();
    LOG.info("Opening vcf file and loading in memory");
    VCFFileReader vfr = null;
    CloseableIterator<VariantContext> iter = null;
    final Set<String> sampleNames;
    try {
        this.variants.clear();
        vfr = new VCFFileReader(vcfFile, false);
        this.vcfHeader = vfr.getFileHeader();
        sampleNames = new HashSet<>(this.vcfHeader.getSampleNamesInOrder());
        if (sampleNames.isEmpty()) {
            JfxUtils.dialog().cause("No Genotypes in " + vcfFile).show(stage);
            Platform.exit();
            return;
        }
        iter = vfr.iterator();
        this.variants.addAll(iter.stream().filter(ctxFilter).filter(CTX -> CTX.isVariant()).collect(Collectors.toList()));
    } catch (final Exception err) {
        JfxUtils.dialog().cause(err).show(stage);
        Platform.exit();
        return;
    } finally {
        CloserUtil.close(iter);
        CloserUtil.close(vfr);
    }
    if (this.variants.isEmpty()) {
        JfxUtils.dialog().cause("No Variants").show(stage);
        Platform.exit();
        return;
    }
    final SAMSequenceDictionary dict = this.vcfHeader.getSequenceDictionary();
    if (dict == null || dict.isEmpty()) {
        JfxUtils.dialog().cause(JvarkitException.VcfDictionaryMissing.getMessage(vcfFile.getPath())).show(stage);
        Platform.exit();
        return;
    }
    final SamReaderFactory srf = SamReaderFactory.makeDefault().validationStringency(ValidationStringency.LENIENT);
    configLines.stream().filter(ignoreComment).filter(S -> S.endsWith(".bam")).map(S -> new File(S)).forEach(F -> {
        final SamReader samIn = srf.open(F);
        final SAMFileHeader header = samIn.getFileHeader();
        CloserUtil.close(samIn);
        String sample = null;
        for (final SAMReadGroupRecord rg : header.getReadGroups()) {
            String s = rg.getSample();
            if (s == null)
                continue;
            if (sample == null) {
                sample = s;
            } else if (!sample.equals(s)) {
                JfxUtils.dialog().cause("Two samples in " + F).show(stage);
                Platform.exit();
                return;
            }
        }
        if (sample == null) {
            JfxUtils.dialog().cause("No sample in " + F + ". Ignoring").show(stage);
            return;
        }
        if (!sampleNames.contains(sample)) {
            JfxUtils.dialog().cause("Not in VCF header " + sample + " / " + F + ". Ignoring").show(stage);
            return;
        }
        this.sample2bamFile.put(sample, F);
    });
    if (this.sample2bamFile.isEmpty()) {
        JfxUtils.dialog().cause("No valid bam file in " + configFile).show(stage);
        return;
    }
    sampleNames.retainAll(this.sample2bamFile.keySet());
    if (sampleNames.isEmpty()) {
        JfxUtils.dialog().cause("No Sample associated to bam").show(stage);
        return;
    }
    ObservableList<VariantAndGenotype> genotypes = FXCollections.observableArrayList(this.variants.stream().flatMap(CTX -> CTX.getGenotypes().stream().filter(G -> sampleNames.contains(G.getSampleName())).map(G -> new VariantAndGenotype(CTX, G))).collect(Collectors.toList()));
    if (genotypes.isEmpty()) {
        JfxUtils.dialog().cause("No Genotype to show").show(stage);
        return;
    }
    Menu menu = new Menu("File");
    MenuItem menuItem = new MenuItem("Save as...");
    menuItem.setOnAction(AE -> {
        saveVariantsAs(stage);
    });
    menu.getItems().add(menuItem);
    menuItem = new MenuItem("Save");
    menuItem.setOnAction(AE -> {
        if (this.saveAsFile != null) {
            saveVariants(stage, this.saveAsFile);
        } else {
            saveVariantsAs(stage);
        }
    });
    menu.getItems().add(menuItem);
    menu.getItems().add(new SeparatorMenuItem());
    menuItem = new MenuItem("Quit");
    menuItem.setOnAction(AE -> {
        Platform.exit();
    });
    menu.getItems().add(menuItem);
    MenuBar bar = new MenuBar(menu);
    this.genotypeTable = new TableView<>(genotypes);
    this.genotypeTable.getColumns().add(makeColumn("CHROM", G -> G.ctx.getContig()));
    this.genotypeTable.getColumns().add(makeColumn("POS", G -> G.ctx.getStart()));
    this.genotypeTable.getColumns().add(makeColumn("ID", G -> G.ctx.getID()));
    this.genotypeTable.getColumns().add(makeColumn("REF", G -> G.ctx.getReference().getDisplayString()));
    this.genotypeTable.getColumns().add(makeColumn("ALT", G -> G.ctx.getAlternateAlleles().stream().map(A -> A.getDisplayString()).collect(Collectors.joining(","))));
    this.genotypeTable.getColumns().add(makeColumn("Sample", G -> G.g.getSampleName()));
    this.genotypeTable.getColumns().add(makeColumn("Type", G -> G.g.getType().name()));
    this.genotypeTable.getColumns().add(makeColumn("Alleles", G -> G.g.getAlleles().stream().map(A -> A.getDisplayString()).collect(Collectors.joining(","))));
    TableColumn<VariantAndGenotype, String> reviewCol = new TableColumn<>("Review");
    reviewCol.setCellValueFactory(C -> C.getValue().getReviewProperty());
    reviewCol.setCellFactory(TextFieldTableCell.forTableColumn());
    reviewCol.setOnEditCommit((E) -> {
        int y = E.getTablePosition().getRow();
        this.genotypeTable.getItems().get(y).setReview(E.getNewValue());
    });
    reviewCol.setEditable(true);
    this.genotypeTable.getColumns().add(reviewCol);
    this.genotypeTable.getSelectionModel().cellSelectionEnabledProperty().set(true);
    this.genotypeTable.setEditable(true);
    final ContextMenu cm = new ContextMenu();
    MenuItem mi1 = new MenuItem("Menu 1");
    cm.getItems().add(mi1);
    MenuItem mi2 = new MenuItem("Menu 2");
    cm.getItems().add(mi2);
    this.genotypeTable.setOnMousePressed(event -> {
        if (event.isPrimaryButtonDown() && (event.getClickCount() == 3 || event.isShiftDown())) {
            moveIgvTo(stage, genotypeTable.getSelectionModel().getSelectedItem());
        } else if (event.isSecondaryButtonDown()) {
            cm.show(genotypeTable, event.getScreenX(), event.getScreenY());
        }
    });
    final BorderPane pane2 = new BorderPane(this.genotypeTable);
    pane2.setPadding(new Insets(10, 10, 10, 10));
    VBox vbox1 = new VBox(bar, pane2);
    final Scene scene = new Scene(vbox1, 500, 300);
    stage.setScene(scene);
    stage.show();
}
Also used : JexlVariantPredicate(com.github.lindenb.jvarkit.util.vcf.JexlVariantPredicate) VCFFileReader(htsjdk.variant.vcf.VCFFileReader) VCFHeader(htsjdk.variant.vcf.VCFHeader) VariantContextWriterBuilder(htsjdk.variant.variantcontext.writer.VariantContextWriterBuilder) VBox(javafx.scene.layout.VBox) SAMFileHeader(htsjdk.samtools.SAMFileHeader) Application(javafx.application.Application) Vector(java.util.Vector) ContextMenu(javafx.scene.control.ContextMenu) IgvConstants(com.github.lindenb.jvarkit.util.igv.IgvConstants) Map(java.util.Map) TableView(javafx.scene.control.TableView) CloserUtil(htsjdk.samtools.util.CloserUtil) PrintWriter(java.io.PrintWriter) MenuItem(javafx.scene.control.MenuItem) GenotypeBuilder(htsjdk.variant.variantcontext.GenotypeBuilder) Predicate(java.util.function.Predicate) Logger(com.github.lindenb.jvarkit.util.log.Logger) Set(java.util.Set) Collectors(java.util.stream.Collectors) JvarkitException(com.github.lindenb.jvarkit.lang.JvarkitException) Platform(javafx.application.Platform) SeparatorMenuItem(javafx.scene.control.SeparatorMenuItem) List(java.util.List) SAMReadGroupRecord(htsjdk.samtools.SAMReadGroupRecord) VariantContextWriter(htsjdk.variant.variantcontext.writer.VariantContextWriter) VariantContext(htsjdk.variant.variantcontext.VariantContext) ObservableList(javafx.collections.ObservableList) BorderPane(javafx.scene.layout.BorderPane) SamReaderFactory(htsjdk.samtools.SamReaderFactory) VariantContextBuilder(htsjdk.variant.variantcontext.VariantContextBuilder) Genotype(htsjdk.variant.variantcontext.Genotype) CloseableIterator(htsjdk.samtools.util.CloseableIterator) Scene(javafx.scene.Scene) Socket(java.net.Socket) SimpleStringProperty(javafx.beans.property.SimpleStringProperty) FXCollections(javafx.collections.FXCollections) HashMap(java.util.HashMap) BackingStoreException(java.util.prefs.BackingStoreException) TextFieldTableCell(javafx.scene.control.cell.TextFieldTableCell) Function(java.util.function.Function) ValidationStringency(htsjdk.samtools.ValidationStringency) ArrayList(java.util.ArrayList) TableColumn(javafx.scene.control.TableColumn) HashSet(java.util.HashSet) Insets(javafx.geometry.Insets) Launcher(com.github.lindenb.jvarkit.util.jcommander.Launcher) VCFHeaderLineType(htsjdk.variant.vcf.VCFHeaderLineType) MenuBar(javafx.scene.control.MenuBar) Files(java.nio.file.Files) SAMSequenceDictionary(htsjdk.samtools.SAMSequenceDictionary) IOException(java.io.IOException) SamReader(htsjdk.samtools.SamReader) InputStreamReader(java.io.InputStreamReader) File(java.io.File) Preferences(java.util.prefs.Preferences) Menu(javafx.scene.control.Menu) FileChooser(javafx.stage.FileChooser) Stage(javafx.stage.Stage) Closeable(java.io.Closeable) JfxUtils(com.github.lindenb.jvarkit.jfx.components.JfxUtils) VCFFormatHeaderLine(htsjdk.variant.vcf.VCFFormatHeaderLine) Window(javafx.stage.Window) BufferedReader(java.io.BufferedReader) Collections(java.util.Collections) BorderPane(javafx.scene.layout.BorderPane) Insets(javafx.geometry.Insets) SAMReadGroupRecord(htsjdk.samtools.SAMReadGroupRecord) VCFFileReader(htsjdk.variant.vcf.VCFFileReader) VariantContext(htsjdk.variant.variantcontext.VariantContext) MenuBar(javafx.scene.control.MenuBar) ContextMenu(javafx.scene.control.ContextMenu) SAMSequenceDictionary(htsjdk.samtools.SAMSequenceDictionary) SamReader(htsjdk.samtools.SamReader) FileChooser(javafx.stage.FileChooser) ContextMenu(javafx.scene.control.ContextMenu) Menu(javafx.scene.control.Menu) SamReaderFactory(htsjdk.samtools.SamReaderFactory) MenuItem(javafx.scene.control.MenuItem) SeparatorMenuItem(javafx.scene.control.SeparatorMenuItem) SeparatorMenuItem(javafx.scene.control.SeparatorMenuItem) Scene(javafx.scene.Scene) TableColumn(javafx.scene.control.TableColumn) JvarkitException(com.github.lindenb.jvarkit.lang.JvarkitException) BackingStoreException(java.util.prefs.BackingStoreException) IOException(java.io.IOException) SAMFileHeader(htsjdk.samtools.SAMFileHeader) File(java.io.File) VBox(javafx.scene.layout.VBox)

Aggregations

SamReaderFactory (htsjdk.samtools.SamReaderFactory)57 SamReader (htsjdk.samtools.SamReader)51 File (java.io.File)43 SAMRecord (htsjdk.samtools.SAMRecord)27 IOException (java.io.IOException)26 SAMFileHeader (htsjdk.samtools.SAMFileHeader)18 SAMRecordIterator (htsjdk.samtools.SAMRecordIterator)17 SAMSequenceDictionary (htsjdk.samtools.SAMSequenceDictionary)17 IndexedFastaSequenceFile (htsjdk.samtools.reference.IndexedFastaSequenceFile)14 ArrayList (java.util.ArrayList)13 List (java.util.List)11 SAMFileWriterFactory (htsjdk.samtools.SAMFileWriterFactory)10 HashSet (java.util.HashSet)10 SAMReadGroupRecord (htsjdk.samtools.SAMReadGroupRecord)9 SAMFileWriter (htsjdk.samtools.SAMFileWriter)8 SAMSequenceRecord (htsjdk.samtools.SAMSequenceRecord)8 URL (java.net.URL)8 HashMap (java.util.HashMap)8 BufferedReader (java.io.BufferedReader)7 PrintWriter (java.io.PrintWriter)7