diff --git a/PEASFeatureExtraction.sh b/PEASFeatureExtraction.sh index cceff4b..21fb757 100644 --- a/PEASFeatureExtraction.sh +++ b/PEASFeatureExtraction.sh @@ -56,7 +56,7 @@ macs2 callpeak -t ${prefix}_sorted.bam.${nfrsize}.bam -f BAMPE -n ${prefix} -g ' #Filter error prone regions echo "--- Filtering peaks. ---" -java -jar "${jarpath}PEASTools.jar" filter "${prefix}_peaks.narrowPeak" "${filterpeaks}" "${prefix}_peaks.filtered" +java -jar "${jarpath}PEASTools.jar" filter "${prefix}_peaks.narrowPeak" "${filterpeaks}" "${prefix}_peaks.filtered"${CHRFILE} echo "--- Calling annotations & known motifs. ---" diff --git a/PEASTools/src/org/jax/peastools/filter/FilterRegions.java b/PEASTools/src/org/jax/peastools/filter/FilterRegions.java index 31e8b6f..fa00521 100644 --- a/PEASTools/src/org/jax/peastools/filter/FilterRegions.java +++ b/PEASTools/src/org/jax/peastools/filter/FilterRegions.java @@ -6,6 +6,7 @@ import java.io.FileWriter; import java.io.IOException; import java.util.TreeMap; +import java.util.TreeSet; import org.jax.peastools.util.Location; import org.jax.peastools.util.Util; @@ -15,17 +16,46 @@ public class FilterRegions { public static void main(String[] args){ FilterRegions fb = new FilterRegions(); try { - fb.filter(args[0], args[1], args[2]); + TreeSet chromosomes = new TreeSet(); + if(args.length > 3) { + chromosomes = fb.getChromosomes(args[3]); + } + else { + chromosomes = fb.getDefaultChromosomes(); + } + + fb.filter(args[0], args[1], chromosomes, args[2]); } catch (IOException e) { e.printStackTrace(); } } + + private TreeSet getDefaultChromosomes(){ + TreeSet rv = new TreeSet(); + for(int i = 1; i< 23; i++) { + rv.add("chr"+Integer.toString(i)); + } + return rv; + } + + private TreeSet getChromosomes(String file) throws IOException{ + BufferedReader br = new BufferedReader(new FileReader(file)); + + TreeSet rv = new TreeSet(); + + while(br.ready()) { + rv.add(br.readLine()); + } + + br.close(); + + return rv; + } - public void filter(String peakfile, String filter, String out) throws IOException{ + public void filter(String peakfile, String filter, TreeSet chromosomes, String out) throws IOException{ Util u = new Util(); BEDPeak[] allpeaks = readPeaks(peakfile).values().toArray(new BEDPeak[0]); Location[] blacklistpeaks = u.readLocationsWithIds(filter); - TreeMap allsorted = u.getChrStartSorted(allpeaks); TreeMap blsorted = u.getChrStartSorted(blacklistpeaks); @@ -34,15 +64,8 @@ public void filter(String peakfile, String filter, String out) throws IOExceptio BufferedWriter bw = new BufferedWriter(new FileWriter(out)); for(int i = 0; i < chrs.length; i++){ String curchr = chrs[i]; - int chridx = 23; - try{ - chridx = Integer.parseInt(curchr.replace("chr", "")); - } - catch(NumberFormatException e){ - } - - //Only chromosomes 1-22 - if(chridx < 1 || chridx >= 23){ + + if(!chromosomes.contains(curchr)){ continue; } diff --git a/singularity/PEAS-singularity.def b/singularity/PEAS-singularity.def index 92fab0f..cacc17c 100644 --- a/singularity/PEAS-singularity.def +++ b/singularity/PEAS-singularity.def @@ -45,7 +45,7 @@ From: ubuntu:18.04 mkdir /PEAS cd /PEAS - wget https://github.com/UcarLab/PEAS/releases/download/v1.2/PEAS_v1.2.zip + wget https://github.com/UcarLab/PEAS/releases/download/v1.2.1/PEAS_v1.2.1.zip unzip PEAS_v1.2.zip