<commit_before>package edu.psu.compbio.seqcode.projects.akshay.utils;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.text.ParseException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;

import edu.psu.compbio.seqcode.genome.Genome;
import edu.psu.compbio.seqcode.genome.GenomeConfig;
import edu.psu.compbio.seqcode.genome.location.Point;
import edu.psu.compbio.seqcode.genome.location.Region;
import edu.psu.compbio.seqcode.genome.location.StrandedPoint;
import edu.psu.compbio.seqcode.gse.datasets.motifs.WeightMatrix;
import edu.psu.compbio.seqcode.gse.gsebricks.verbs.motifs.WeightMatrixScoreProfile;
import edu.psu.compbio.seqcode.gse.gsebricks.verbs.motifs.WeightMatrixScorer;
import edu.psu.compbio.seqcode.gse.gsebricks.verbs.sequence.SequenceGenerator;
import edu.psu.compbio.seqcode.gse.tools.utils.Args;
import edu.psu.compbio.seqcode.gse.utils.ArgParser;
import edu.psu.compbio.seqcode.gse.utils.Pair;
import edu.psu.compbio.seqcode.gse.utils.io.RegionFileUtilities;
import edu.psu.compbio.seqcode.projects.shaun.MotifAnalysisSandbox;
import edu.psu.compbio.seqcode.projects.shaun.rnaseq.GTFReader;
import edu.psu.compbio.seqcode.projects.shaun.rnaseq.genemodels.GeneTUnit;

public class ProfileGeneNeighborhood {
	
	private GenomeConfig gcon;
	
	private List<Point> peaks;
	private Map<String,String> peaksSeqs;
	
	private Map<String,List<Point>> peaksAtgenes;
	private Map<String,List<PointCluster>> peakClustersAtgenes;
	
	private Map<String, StrandedPoint> genes;
	private Map<String, Region> geneDomains;
	
	private int radius; // Neighborhood radius
	
	private int cluster_distance;
	
	private List<WeightMatrix> motifs = new ArrayList<WeightMatrix>();
	
	private int win;
	
	private SequenceGenerator<Region> seqgen;
	
	
	@SuppressWarnings("unchecked")
	public ProfileGeneNeighborhood(GenomeConfig g) {
		gcon = g;
		seqgen = gcon.getSequenceGenerator();
	}
	
	/**
	 * 
	 * @param args
	 * @throws ParseException 
	 * @throws IOException 
	 */
	public static void main(String[] args) throws IOException, ParseException{
		ArgParser ap = new ArgParser(args);
		GenomeConfig gc = new GenomeConfig(args);
		ProfileGeneNeighborhood profiler = new ProfileGeneNeighborhood(gc);
		
		int win = ap.hasKey("win") ? new Integer(ap.getKeyValue("win")).intValue():150;
		int rad = ap.hasKey("radius") ? new Integer(ap.getKeyValue("radius")).intValue() : 50000;
		int clusD = ap.hasKey("clusD") ? new Integer(ap.getKeyValue("clusD")).intValue() : 300;
		
		String motiffile = ap.getKeyValue("motiffile");
		String backfile = ap.getKeyValue("back");
		
		List<WeightMatrix> matrixList = MotifAnalysisSandbox.loadMotifFromFile(motiffile, backfile, gc.getGenome());
		
		String peaksFile = ap.getKeyValue("peaks");
		List<Point> peaks = RegionFileUtilities.loadPeaksFromPeakFile(gc.getGenome(), ap.getKeyValue("peaks"), win);
		String genefile = Args.parseString(args, "gtf", null);
		
		//Read selected genes into a list
		String geneListFile = Args.parseString(args, "geneList", null);
		File gFile = new File(geneListFile);
		if(!gFile.isFile()){System.err.println("Invalid positive file name");System.exit(1);}
        BufferedReader reader = new BufferedReader(new FileReader(gFile));
        String line;
        List<String> geneList = new ArrayList<String>();
        while ((line = reader.readLine()) != null) {
        	line.trim();
        	String[] words =line.split("\t");
        	geneList.add(words[0]);
        }
		reader.close();
		
		profiler.setWindow(win);
		profiler.setClusDistance(clusD);
		profiler.setRadius(rad);
		profiler.setPeaks(peaks);
		profiler.setGenes(genefile, geneList);
		profiler.setMotifs(matrixList);
		
		boolean clusterSyntax = ap.hasKey("ClusterSyntax");
		if(clusterSyntax){profiler.printPeakClusterSyntax();}
		boolean peakSyntax = ap.hasKey("PeakSyntax");
		if(peakSyntax){profiler.printPeakSyntax();}
		boolean closePeaks = ap.hasKey("closePeaks");
		if(closePeaks){profiler.printPeaksatGenes();}
		
		profiler.clear();
		
		
		
		
	}
	
	
	
	//Mutators
	public void setWindow(int w){win = w;}<commit_msg>Added more options to neighborhood profiler<commit_after>package edu.psu.compbio.seqcode.projects.akshay.utils;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.text.ParseException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;

import edu.psu.compbio.seqcode.genome.Genome;
import edu.psu.compbio.seqcode.genome.GenomeConfig;
import edu.psu.compbio.seqcode.genome.location.Point;
import edu.psu.compbio.seqcode.genome.location.Region;
import edu.psu.compbio.seqcode.genome.location.StrandedPoint;
import edu.psu.compbio.seqcode.gse.datasets.motifs.WeightMatrix;
import edu.psu.compbio.seqcode.gse.gsebricks.verbs.motifs.WeightMatrixScoreProfile;
import edu.psu.compbio.seqcode.gse.gsebricks.verbs.motifs.WeightMatrixScorer;
import edu.psu.compbio.seqcode.gse.gsebricks.verbs.sequence.SequenceGenerator;
import edu.psu.compbio.seqcode.gse.tools.utils.Args;
import edu.psu.compbio.seqcode.gse.utils.ArgParser;
import edu.psu.compbio.seqcode.gse.utils.Pair;
import edu.psu.compbio.seqcode.gse.utils.io.RegionFileUtilities;
import edu.psu.compbio.seqcode.projects.shaun.MotifAnalysisSandbox;
import edu.psu.compbio.seqcode.projects.shaun.rnaseq.GTFReader;
import edu.psu.compbio.seqcode.projects.shaun.rnaseq.genemodels.GeneTUnit;

public class ProfileGeneNeighborhood {
	
	private GenomeConfig gcon;
	
	private List<Point> peaks;
	private Map<String,String> peaksSeqs;
	
	private Map<String,List<Point>> peaksAtgenes;
	private Map<String,List<PointCluster>> peakClustersAtgenes;
	
	private Map<String, StrandedPoint> genes;
	private Map<String, Region> geneDomains;
	
	private int radius; // Neighborhood radius
	
	private int cluster_distance;
	
	private List<WeightMatrix> motifs = new ArrayList<WeightMatrix>();
	
	private int win;
	
	private SequenceGenerator<Region> seqgen;
	
	
	@SuppressWarnings("unchecked")
	public ProfileGeneNeighborhood(GenomeConfig g) {
		gcon = g;
		seqgen = gcon.getSequenceGenerator();
	}
	
	/**
	 * 
	 * @param args
	 * @throws ParseException 
	 * @throws IOException 
	 */
	public static void main(String[] args) throws IOException, ParseException{
		ArgParser ap = new ArgParser(args);
		GenomeConfig gc = new GenomeConfig(args);
		ProfileGeneNeighborhood profiler = new ProfileGeneNeighborhood(gc);
		
		int win = ap.hasKey("win") ? new Integer(ap.getKeyValue("win")).intValue():150;
		int rad = ap.hasKey("radius") ? new Integer(ap.getKeyValue("radius")).intValue() : 50000;
		int clusD = ap.hasKey("clusD") ? new Integer(ap.getKeyValue("clusD")).intValue() : 300;
		
		String motiffile = ap.getKeyValue("motiffile");
		String backfile = ap.getKeyValue("back");
		
		String peaksFile = ap.getKeyValue("peaks");
		List<Point> peaks = RegionFileUtilities.loadPeaksFromPeakFile(gc.getGenome(), ap.getKeyValue("peaks"), win);
		String genefile = Args.parseString(args, "gtf", null);
		
		//Read selected genes into a list
		String geneListFile = Args.parseString(args, "geneList", null);
		File gFile = new File(geneListFile);
		if(!gFile.isFile()){System.err.println("Invalid positive file name");System.exit(1);}
        BufferedReader reader = new BufferedReader(new FileReader(gFile));
        String line;
        List<String> geneList = new ArrayList<String>();
        while ((line = reader.readLine()) != null) {
        	line.trim();
        	String[] words =line.split("\t");
        	geneList.add(words[0]);
        }
		reader.close();
		
		profiler.setWindow(win);
		profiler.setClusDistance(clusD);
		profiler.setRadius(rad);
		profiler.setPeaks(peaks);
		profiler.setGenes(genefile, geneList);
		
		
		
		if(ap.hasKey("ClusterSyntax")){
			List<WeightMatrix> matrixList = MotifAnalysisSandbox.loadMotifFromFile(motiffile, backfile, gc.getGenome());
			profiler.setMotifs(matrixList);
			profiler.printPeakClusterSyntax();}
		else if(ap.hasKey("PeakSyntax")){
			List<WeightMatrix> matrixList = MotifAnalysisSandbox.loadMotifFromFile(motiffile, backfile, gc.getGenome());
			profiler.setMotifs(matrixList);
			profiler.printPeakSyntax();}
		else if(ap.hasKey("closePeaks")){profiler.printPeaksatGenes();}
		
		profiler.clear();
		
		
		
		
	}
	
	
	
	//Mutators
	public void setWindow(int w){win = w;}
{'fraction_non_alphanumeric': 0.12735132608949642, 'fraction_numerical': 0.0030377380535109243, 'mean_word_length': 5.015460295151089, 'pattern_counts': {'":': 0, '<': 34, '<?xml version=': 0, '>': 34, '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': '5110081', 'n_tokens_mistral': 3127, 'n_tokens_neox': 2877, 'n_words': 489}