<commit_before>package edu.toronto.bb.core;

import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.Collection;
import java.util.LinkedHashMap;

import org.biojava3.core.sequence.DNASequence;
import org.biojava3.core.sequence.compound.DNACompoundSet;
import org.biojava3.core.sequence.compound.NucleotideCompound;
import org.biojava3.core.sequence.io.FastaReader;
import org.biojava3.core.sequence.io.FastaWriter;
import org.biojava3.core.sequence.io.FileProxyDNASequenceCreator;
import org.biojava3.core.sequence.io.GenericFastaHeaderParser;
import org.biojava3.core.sequence.io.template.FastaHeaderFormatInterface;
import org.biojava3.core.sequence.io.template.SequenceCreatorInterface;

import edu.toronto.bb.core.phred.PhredReader;
import edu.toronto.bb.core.phred.PhredScoreSequence;
import edu.toronto.bb.core.phred.PhredWriter;

public class BarcodeBooster {

    private File fnaIn;
    private File fnaOut;
    private File qualIn;
    private File qualOut;
    
    private InputStream fnaInputStream;    
    private InputStream qualInputStream;    
    private FileOutputStream fnaOutputStream;
    private FileOutputStream qualOutputStream;
    
    private FastaReader<DNASequence, NucleotideCompound> fastaReader;
    private FastaWriter<DNASequence, NucleotideCompound> fastaWriter;
    private PhredReader phredReader;
    private PhredWriter phredWriter;
    
    private LinkedHashMap<String,DNASequence> dnaSequences;
    private LinkedHashMap<String,PhredScoreSequence> qualSequences;
    
    private String barcodes; // contains the CSV formats of the barcode
    
    public BarcodeBooster(File fnaIn, File fnaOut, File qualIn, File qualOut) throws FileNotFoundException {
        this.fnaIn = fnaIn;
        this.fnaOut = fnaOut;
        this.qualIn = qualIn;
        this.qualOut = qualOut;       
        
        initIO();        
    }
    
    public void process() throws IOException {
        dnaSequences = fastaReader.process();
        qualSequences = phredReader.process();
        closeIO();
    }
    
    private void initIO() throws FileNotFoundException {        
        fnaInputStream = new FileInputStream(fnaIn);
        fnaOutputStream = new FileOutputStream(fnaOut);
        qualInputStream = new FileInputStream(qualIn);
        qualOutputStream = new FileOutputStream(qualOut);
        
        fastaReader = new FastaReader<DNASequence, NucleotideCompound>(fnaIn, 
                new GenericFastaHeaderParser<DNASequence, NucleotideCompound>(), 
                (SequenceCreatorInterface<NucleotideCompound>) new FileProxyDNASequenceCreator(fnaIn, DNACompoundSet.getDNACompoundSet()));
                
        BufferedOutputStream fnaBO = new BufferedOutputStream(fnaOutputStream);
        fastaWriter = new FastaWriter<DNASequence, NucleotideCompound>(fnaBO, 
                dnaSequences.values(),
                (FastaHeaderFormatInterface<DNASequence, NucleotideCompound>) new GenericFastaHeaderParser<DNASequence, NucleotideCompound>());
        
        phredReader = new PhredReader(qualInputStream);
        
        BufferedOutputStream qualBO = new BufferedOutputStream(qualOutputStream);
        phredWriter = new PhredWriter(qualBO, qualSequences.values());        
    }
    
    private void closeIO() throws IOException {
        fnaInputStream.close();
        fnaOutputStream.close();
        qualInputStream.close();
        qualOutputStream.close();
    }
}<commit_msg>setup the calling skeleton.  Next is to implement SearchAndInsert Function<commit_after>package edu.toronto.bb.core;

import java.io.BufferedOutputStream;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.Collection;
import java.util.LinkedHashMap;

import org.biojava3.core.sequence.DNASequence;
import org.biojava3.core.sequence.compound.DNACompoundSet;
import org.biojava3.core.sequence.compound.NucleotideCompound;
import org.biojava3.core.sequence.io.FastaReader;
import org.biojava3.core.sequence.io.FastaWriter;
import org.biojava3.core.sequence.io.FileProxyDNASequenceCreator;
import org.biojava3.core.sequence.io.GenericFastaHeaderParser;
import org.biojava3.core.sequence.io.template.FastaHeaderFormatInterface;
import org.biojava3.core.sequence.io.template.SequenceCreatorInterface;

import edu.toronto.bb.core.phred.PhredReader;
import edu.toronto.bb.core.phred.PhredScoreSequence;
import edu.toronto.bb.core.phred.PhredWriter;

public class BarcodeBooster {

    private File fnaIn;
    private File fnaOut;
    private File qualIn;
    private File qualOut;
    
    private InputStream fnaInputStream;    
    private InputStream qualInputStream;    
    private FileOutputStream fnaOutputStream;
    private FileOutputStream qualOutputStream;
    
    private FastaReader<DNASequence, NucleotideCompound> fastaReader;
    private FastaWriter<DNASequence, NucleotideCompound> fastaWriter;
    private PhredReader phredReader;
    private PhredWriter phredWriter;
    
    private LinkedHashMap<String,DNASequence> dnaSequences;
    private LinkedHashMap<String,PhredScoreSequence> qualSequences;
    
    private String barcodes; // contains the CSV formats of the barcode
    private final String pathToBarcodes = "config/barcodes";
    
    private String key = "";  // key to be inserted

    public BarcodeBooster(File fnaIn, File fnaOut, File qualIn, File qualOut) throws FileNotFoundException {
        this.fnaIn = fnaIn;
        this.fnaOut = fnaOut;
        this.qualIn = qualIn;
        this.qualOut = qualOut;       
                
        initIO();        
    }
    
    public void process() throws Throwable {
        barcodes = loadBarcodes();
        
        dnaSequences = fastaReader.process();
        qualSequences = phredReader.process();
        
        searchForBarcodeAndInsertKeyToSequence();
        
        fastaWriter.process();
        phredWriter.process();
        
        closeIO();
    }    
    
    public String getKey() {
        return key;
    }

    public void setKey(String key) {
        this.key = key;
    }
    
    private void searchForBarcodeAndInsertKeyToSequence() {
        
    }    
        
    private void initIO() throws FileNotFoundException {        
        fnaInputStream = new FileInputStream(fnaIn);
        fnaOutputStream = new FileOutputStream(fnaOut);
        qualInputStream = new FileInputStream(qualIn);
        qualOutputStream = new FileOutputStream(qualOut);
        
        fastaReader = new FastaReader<DNASequence, NucleotideCompound>(fnaIn, 
                new GenericFastaHeaderParser<DNASequence, NucleotideCompound>(), 
                (SequenceCreatorInterface<NucleotideCompound>) new FileProxyDNASequenceCreator(fnaIn, DNACompoundSet.getDNACompoundSet()));
                
        BufferedOutputStream fnaBO = new BufferedOutputStream(fnaOutputStream);
        fastaWriter = new FastaWriter<DNASequence, NucleotideCompound>(fnaBO, 
                dnaSequences.values(),
                (FastaHeaderFormatInterface<DNASequence, NucleotideCompound>) new GenericFastaHeaderParser<DNASequence, NucleotideCompound>());
        
        phredReader = new PhredReader(qualInputStream);
        
        BufferedOutputStream qualBO = new BufferedOutputStream(qualOutputStream);
        phredWriter = new PhredWriter(qualBO, qualSequences.values());        
    }
    
    private void closeIO() throws IOException {
        fnaInputStream.close();
        fnaOutputStream.close();
        qualInputStream.close();
        qualOutputStream.close();
    }
    
    private String loadBarcodes() throws IOException {
        FileInputStream barcodeFile = new FileInputStream(pathToBarcodes);
        InputStreamReader reader = new InputStreamReader(barcodeFile);
        BufferedReader br = new BufferedReader(reader);
        
        StringBuilder sb = new StringBuilder();         
        String delimiter =",";
        String line = br.readLine();
        
        while (line != null ) {
            sb.append(line);
            sb.append(delimiter);
            line = br.readLine();
        }
        
        return sb.toString();
    }
}
{'fraction_non_alphanumeric': 0.07879216796414248, 'fraction_numerical': 0.0021231422505307855, 'mean_word_length': 3.212121212121212, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 23, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1680155', 'n_tokens_mistral': 2422, 'n_tokens_neox': 2313, 'n_words': 465}