<commit_before>package edu.psu.compbio.seqcode.deepseq.hitloaders;

import java.io.IOException;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Set;
import java.util.TreeMap;

import edu.psu.compbio.seqcode.genome.Genome;
import edu.psu.compbio.seqcode.genome.location.Region;
import edu.psu.compbio.seqcode.gse.datasets.seqdata.SeqAlignment;
import edu.psu.compbio.seqcode.gse.datasets.seqdata.SeqExpt;
import edu.psu.compbio.seqcode.gse.datasets.seqdata.SeqDataLoader;
import edu.psu.compbio.seqcode.gse.datasets.seqdata.SeqLocator;
import edu.psu.compbio.seqcode.gse.projects.readdb.*;
import edu.psu.compbio.seqcode.gse.utils.NotFoundException;
import edu.psu.compbio.seqcode.gse.utils.Pair;

/**
 * ReadDBHitLoader: load read alignment five primes from a collection of ReadDB alignments (SeqLocators)
 * @author mahony
 *
 */
public class ReadDBHitLoader extends HitLoader{
	
	private Genome gen=null;
	private Client client=null; //ReadDB client
	private List<SeqLocator> exptLocs;
	private List<String> exptNames =new ArrayList<String>();
	private List<SeqAlignment> aligns = new ArrayList<SeqAlignment>();
	private Collection<String> alignIDs= new ArrayList<String>();
	private final int MAXRDBLOAD = 1000000; //Maximum number of hits to load from ReadDB in one chunk
	
	/**
	 * Constructor: initialize the experiments
	 * @param g Genome
	 * @param locs ChipSeqLocator
	 */
	public ReadDBHitLoader(Genome g, List<SeqLocator> locs){
		super();
		gen=g;
		exptLocs = locs;
		if(gen==null){
			System.err.println("ReadDBHitLoader: null genome provided. ReadDB requires a defined genome. ");
		}
        if (exptLocs.size() == 0) {
            System.err.println("Created a ReadDBHitLoader with no ChipSeqLocators");
        }

		try {
			
			//Initialize ChipSeqLoaders
            SeqDataLoader loader = new SeqDataLoader(false); 
			for(SeqLocator locator : exptLocs){
				String exptName = locator.getExptName(); exptNames.add(exptName);
				if (locator.getAlignName() == null) {
		            if(locator.getReplicates().isEmpty()) { //No alignment name, no replicate names
		            	Collection<SeqExpt> expts = loader.loadExperiments(locator.getExptName());
		        		for(SeqExpt expt : expts) { 
		                	Collection<SeqAlignment> aligns;
							aligns = loader.loadAllAlignments(expt);
							for (SeqAlignment currentAlign : aligns) {
		            			if (currentAlign.getGenome().equals(g)) { 
		            				aligns.add(currentAlign);
		    						break;
		    					}
		            		}
		    			}
		            } else { //No alignment name, given replicate names
		                for(String repName : locator.getReplicates()) { 
		                    SeqExpt expt = loader.loadExperiment(locator.getExptName(), repName);
		                    SeqAlignment alignment = 
		                        loader.loadAlignment(expt, locator.getAlignName(), g);
		                    if(alignment != null) { 
		                        aligns.add(alignment);
		                        break;
		                    }
		                }
		            }
		        } else {
		        	if(locator.getReplicates().isEmpty()) {//Given alignment name, no replicate names
		        		Collection<SeqExpt> expts = loader.loadExperiments(locator.getExptName());
                        System.err.println("Have name but no replicates.  Got " + expts.size() + " experiments for " + locator.getExptName());
		        		for(SeqExpt expt : expts) { 
		                	Collection<SeqAlignment> alignments;
							alignments = loader.loadAllAlignments(expt);
							for (SeqAlignment currentAlign : alignments) {
                                System.err.println("  " + currentAlign);
		            			if (currentAlign.getGenome().equals(g) && currentAlign.getName().equals(locator.getAlignName())) { 
		            				aligns.add(currentAlign);
		    						break;
		    					}
		            		}
		    			}
		            }else{
		            	for (String replicate : locator.getReplicates()) {//Given alignment name, given replicate names
		            		SeqAlignment a = loader.loadAlignment(loader.loadExperiment(locator.getExptName(),replicate),locator.getAlignName(),g);
							if(a!=null)
								aligns.add(a);
		        		}
		            }
		        }
			}
	        for(SeqAlignment alignment : aligns) {
	            alignIDs.add(Integer.toString(alignment.getDBID()));
	            this.sourceName=this.sourceName+Integer.toString(alignment.getDBID())+";";
	        }
	        
            if (exptLocs.size() != 0 && aligns.size() == 0) {<commit_msg>Changing getSource to provide experiment name rathter than ID<commit_after>package edu.psu.compbio.seqcode.deepseq.hitloaders;

import java.io.IOException;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Set;
import java.util.TreeMap;

import edu.psu.compbio.seqcode.genome.Genome;
import edu.psu.compbio.seqcode.genome.location.Region;
import edu.psu.compbio.seqcode.gse.datasets.seqdata.SeqAlignment;
import edu.psu.compbio.seqcode.gse.datasets.seqdata.SeqExpt;
import edu.psu.compbio.seqcode.gse.datasets.seqdata.SeqDataLoader;
import edu.psu.compbio.seqcode.gse.datasets.seqdata.SeqLocator;
import edu.psu.compbio.seqcode.gse.projects.readdb.*;
import edu.psu.compbio.seqcode.gse.utils.NotFoundException;
import edu.psu.compbio.seqcode.gse.utils.Pair;

/**
 * ReadDBHitLoader: load read alignment five primes from a collection of ReadDB alignments (SeqLocators)
 * @author mahony
 *
 */
public class ReadDBHitLoader extends HitLoader{
	
	private Genome gen=null;
	private Client client=null; //ReadDB client
	private List<SeqLocator> exptLocs;
	private List<String> exptNames =new ArrayList<String>();
	private List<SeqAlignment> aligns = new ArrayList<SeqAlignment>();
	private Collection<String> alignIDs= new ArrayList<String>();
	private final int MAXRDBLOAD = 1000000; //Maximum number of hits to load from ReadDB in one chunk
	
	/**
	 * Constructor: initialize the experiments
	 * @param g Genome
	 * @param locs ChipSeqLocator
	 */
	public ReadDBHitLoader(Genome g, List<SeqLocator> locs){
		super();
		gen=g;
		exptLocs = locs;
		if(gen==null){
			System.err.println("ReadDBHitLoader: null genome provided. ReadDB requires a defined genome. ");
		}
        if (exptLocs.size() == 0) {
            System.err.println("Created a ReadDBHitLoader with no ChipSeqLocators");
        }

		try {
			
			//Initialize ChipSeqLoaders
            SeqDataLoader loader = new SeqDataLoader(false); 
			for(SeqLocator locator : exptLocs){
				String exptName = locator.getExptName(); exptNames.add(exptName);
				if (locator.getAlignName() == null) {
		            if(locator.getReplicates().isEmpty()) { //No alignment name, no replicate names
		            	Collection<SeqExpt> expts = loader.loadExperiments(locator.getExptName());
		        		for(SeqExpt expt : expts) { 
		                	Collection<SeqAlignment> aligns;
							aligns = loader.loadAllAlignments(expt);
							for (SeqAlignment currentAlign : aligns) {
		            			if (currentAlign.getGenome().equals(g)) { 
		            				aligns.add(currentAlign);
		    						break;
		    					}
		            		}
		    			}
		            } else { //No alignment name, given replicate names
		                for(String repName : locator.getReplicates()) { 
		                    SeqExpt expt = loader.loadExperiment(locator.getExptName(), repName);
		                    SeqAlignment alignment = 
		                        loader.loadAlignment(expt, locator.getAlignName(), g);
		                    if(alignment != null) { 
		                        aligns.add(alignment);
		                        break;
		                    }
		                }
		            }
		        } else {
		        	if(locator.getReplicates().isEmpty()) {//Given alignment name, no replicate names
		        		Collection<SeqExpt> expts = loader.loadExperiments(locator.getExptName());
                        System.err.println("Have name but no replicates.  Got " + expts.size() + " experiments for " + locator.getExptName());
		        		for(SeqExpt expt : expts) { 
		                	Collection<SeqAlignment> alignments;
							alignments = loader.loadAllAlignments(expt);
							for (SeqAlignment currentAlign : alignments) {
                                System.err.println("  " + currentAlign);
		            			if (currentAlign.getGenome().equals(g) && currentAlign.getName().equals(locator.getAlignName())) { 
		            				aligns.add(currentAlign);
		    						break;
		    					}
		            		}
		    			}
		            }else{
		            	for (String replicate : locator.getReplicates()) {//Given alignment name, given replicate names
		            		SeqAlignment a = loader.loadAlignment(loader.loadExperiment(locator.getExptName(),replicate),locator.getAlignName(),g);
							if(a!=null)
								aligns.add(a);
		        		}
		            }
		        }
			}
	        for(SeqAlignment alignment : aligns) {
	            alignIDs.add(Integer.toString(alignment.getDBID()));
	            this.sourceName=this.sourceName.equals("") ? 
			Integer.toString(alignment.getName()) : ";"+Integer.toString(alignment.getName());
	        }
	        
            if (exptLocs.size() != 0 && aligns.size() == 0) {
{'fraction_non_alphanumeric': 0.11032292218104818, 'fraction_numerical': 0.0021175224986765486, 'mean_word_length': 2.397841726618705, 'pattern_counts': {'":': 0, '<': 27, '<?xml version=': 0, '>': 27, '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': '1373411', 'n_tokens_mistral': 3223, 'n_tokens_neox': 2778, 'n_words': 542}