#/data/results/tools/solid/qc-filter/SOLiD_preprocess_filter_v2_MR1.pl --help
#-p|p_cnt - Polyclonal analysis count required - optional (default 1) 
#	- This is the count required for the polyclonal analysis. 
#	  This number must be between [0-10].  Zero is equivalent to having the 
#	  polyclonal analysis turned off.  For example if this is set to 5, 
#	  then at least 5 of the first 10 positions must exceed the passed 
#	  polyclonal QV score.
#-q|p_qv - Polyclonal analysis min QV score - optional (default 25) 
#	- This is the minimum score for the polyclonal analysis. 
#	  This must be a number between 0-34 since there are currently 
#	  no scores above 34.
#-u|tr_len - desired length of read after truncation - optional 
#	- This is the length of the sequence desired, any color calls after this 
#	  length are removed. This option must be filled in if truncation is turned on 
#	  and be an integer greater than 0. 
#-a|qv_analysis - turn on/off analysis of quality values - optional (default off) 
#	- Analysis of the quality values for all of the inputted reads and 
#	  the passing reads.  Analysis returns a file with a matrix of a count 
#	  of scores by position. 
#	  [on,yes,y,off,no,n]
#example: SOLiD_preprocess_filter_v2_MR1.pl -i mp -f a_F3.csfasta -g a_F3_QV.qual -r b_R3.csfasta 
# -s b_R3_QV.qual -p 3 -q 22 -e 10 -d 9 -v off -o test_test 


cd /data/images/proton/DKlab/mr/parclip/raw
#errors (encoded by ".") are counted only in the first 20 colors
/data/results/tools/solid/qc-filter/SOLiD_preprocess_filter_v2_MR1.pl -a on -o IGGfilt2 -f IGG/ugc_604_12_F3.csfasta -g IGG/ugc_604_12_F3.QV.qual
#/data/results/tools/solid/qc-filter/SOLiD_preprocess_filter_v2_MR1.pl -a on -o 0hrep1filt2 -f 0hrep1/ugc_604_1_F3.csfasta -g 0hrep1/ugc_604_1_F3.QV.qual 
/data/results/tools/solid/qc-filter/SOLiD_preprocess_filter_v2_MR1.pl -a on -o 0hrep2filt2 -f 0hrep2/ugc_604_4_F3.csfasta -g 0hrep2/ugc_604_4_F3.QV.qual
/data/results/tools/solid/qc-filter/SOLiD_preprocess_filter_v2_MR1.pl -a on -o 0hrep3filt2 -f 0hrep3/ugc_604_7_F3.csfasta -g 0hrep3/ugc_604_7_F3.QV.qual
/data/results/tools/solid/qc-filter/SOLiD_preprocess_filter_v2_MR1.pl -a on -o  2hrep1filt2 -f  2hrep1/ugc_604_2_F3.csfasta -g  2hrep1/ugc_604_2_F3.QV.qual
/data/results/tools/solid/qc-filter/SOLiD_preprocess_filter_v2_MR1.pl -a on -o 2hrep2filt2 -f 2hrep2/ugc_604_5_F3.csfasta -g 2hrep2/ugc_604_5_F3.QV.qual
/data/results/tools/solid/qc-filter/SOLiD_preprocess_filter_v2_MR1.pl -a on -o 2hrep3filt2 -f 2hrep3/ugc_604_8_F3.csfasta -g 2hrep3/ugc_604_8_F3.QV.qual
/data/results/tools/solid/qc-filter/SOLiD_preprocess_filter_v2_MR1.pl -a on -o  6hrep1filt2 -f  6hrep1/ugc_604_3_F3.csfasta -g  6hrep1/ugc_604_3_F3.QV.qual
/data/results/tools/solid/qc-filter/SOLiD_preprocess_filter_v2_MR1.pl -a on -o 6hrep2filt2 -f 6hrep2/ugc_604_6_F3.csfasta -g 6hrep2/ugc_604_6_F3.QV.qual
/data/results/tools/solid/qc-filter/SOLiD_preprocess_filter_v2_MR1.pl -a on -o 6hrep3filt2 -f 6hrep3/ugc_604_9_F3.csfasta -g 6hrep3/ugc_604_9_F3.QV.qual
/data/results/tools/solid/qc-filter/SOLiD_preprocess_filter_v2_MR1.pl -a on -o  IL4filt2 -f  IL4/ugc_604_11_F3.csfasta -g  IL4/ugc_604_11_F3.QV.qual
/data/results/tools/solid/qc-filter/SOLiD_preprocess_filter_v2_MR1.pl -a on -o IFNfilt2 -f IFN/ugc_604_10_F3.csfasta -g IFN/ugc_604_10_F3.QV.qual


for i in  *_T_*csfasta
 do
 echo $i
 cat  $i | /data/images/proton/DKlab/mr/parclip/parpipe/PARpipe-master/scripts/collapseFA.pl > $i".coll"
 done
#cat  0hrep1filt2_T_F3.csfasta | /data/images/proton/DKlab/mr/parclip/parpipe/PARpipe-master/scripts/collapseFA.pl > test.fasta

./SeqTrimMap4Paralyzer -m 10 -l 18 -v 2 -p 10 -i -o 0hrep1F-4p3  0hrep1filt2_T_F3.csfasta.coll  /data/results/reference/mmu/mm9/bowtie1/mm9c
./SeqTrimMap4Paralyzer -m 10 -l 18 -v 2 -p 10 -i -o 0hrep2F-4p3  0hrep2filt2_T_F3.csfasta.coll  /data/results/reference/mmu/mm9/bowtie1/mm9c
./SeqTrimMap4Paralyzer -m 10 -l 18 -v 2 -p 10 -i -o 0hrep3F-4p3  0hrep3filt2_T_F3.csfasta.coll  /data/results/reference/mmu/mm9/bowtie1/mm9c

./SeqTrimMap4Paralyzer -m 10 -l 18 -v 2 -p 10 -i -o 2hrep1F-4p3  2hrep1filt2_T_F3.csfasta.coll  /data/results/reference/mmu/mm9/bowtie1/mm9c
./SeqTrimMap4Paralyzer -m 10 -l 18 -v 2 -p 10 -i -o 2hrep2F-4p3  2hrep2filt2_T_F3.csfasta.coll  /data/results/reference/mmu/mm9/bowtie1/mm9c
./SeqTrimMap4Paralyzer -m 10 -l 18 -v 2 -p 10 -i -o 2hrep3F-4p3  2hrep3filt2_T_F3.csfasta.coll  /data/results/reference/mmu/mm9/bowtie1/mm9c

./SeqTrimMap4Paralyzer2 -m 10 -l 18 -v 2 -p 10 -i -o IGGF-4p3 IGGfilt2_T_F3.csfasta.coll  /data/results/reference/mmu/mm9/bowtie1/mm9c
./SeqTrimMap4Paralyzer2 -m 10 -l 18 -v 2 -p 10 -i -o IL4F-4p3  IL4filt2_T_F3.csfasta.coll  /data/results/reference/mmu/mm9/bowtie1/mm9c
./SeqTrimMap4Paralyzer2 -m 10 -l 18 -v 2 -p 10 -i -o IFNF-4p3  IFNfilt2_T_F3.csfasta.coll  /data/results/reference/mmu/mm9/bowtie1/mm9c

./SeqTrimMap4Paralyzer2 -m 10 -l 18 -v 2 -p 10 -i -o 6hrep1F-4p3  6hrep1filt2_T_F3.csfasta.coll  /data/results/reference/mmu/mm9/bowtie1/mm9c
./SeqTrimMap4Paralyzer2 -m 10 -l 18 -v 2 -p 10 -i -o 6hrep2F-4p3  6hrep2filt2_T_F3.csfasta.coll  /data/results/reference/mmu/mm9/bowtie1/mm9c
./SeqTrimMap4Paralyzer2 -m 10 -l 18 -v 2 -p 10 -i -o 6hrep3F-4p3  6hrep3filt2_T_F3.csfasta.coll  /data/results/reference/mmu/mm9/bowtie1/mm9c


/data/results/tools/samtools/samtools-1.3/misc/bowtie2sam.pl /data/images/proton/DKlab/mr/parclip/raw/0hrep1F-4p3.bowtie > 0hrep1F-4p3.sam
/data/results/tools/samtools/samtools-1.3/misc/bowtie2sam.pl /data/images/proton/DKlab/mr/parclip/raw/0hrep2F-4p3.bowtie > 0hrep2F-4p3.sam
/data/results/tools/samtools/samtools-1.3/misc/bowtie2sam.pl /data/images/proton/DKlab/mr/parclip/raw/0hrep3F-4p3.bowtie > 0hrep3F-4p3.sam

/data/results/tools/samtools/samtools-1.3/misc/bowtie2sam.pl /data/images/proton/DKlab/mr/parclip/raw/2hrep1F-4p3.bowtie > 2hrep1F-4p3.sam
/data/results/tools/samtools/samtools-1.3/misc/bowtie2sam.pl /data/images/proton/DKlab/mr/parclip/raw/2hrep2F-4p3.bowtie > 2hrep2F-4p3.sam
/data/results/tools/samtools/samtools-1.3/misc/bowtie2sam.pl /data/images/proton/DKlab/mr/parclip/raw/2hrep3F-4p3.bowtie > 2hrep3F-4p3.sam
/data/results/tools/samtools/samtools-1.3/misc/bowtie2sam.pl /data/images/proton/DKlab/mr/parclip/raw/6hrep1F-4p3.bowtie > 6hrep1F-4p3.sam
/data/results/tools/samtools/samtools-1.3/misc/bowtie2sam.pl /data/images/proton/DKlab/mr/parclip/raw/6hrep2F-4p3.bowtie > 6hrep2F-4p3.sam
/data/results/tools/samtools/samtools-1.3/misc/bowtie2sam.pl /data/images/proton/DKlab/mr/parclip/raw/6hrep3F-4p3.bowtie > 6hrep3F-4p3.sam

/data/results/tools/samtools/samtools-1.3/misc/bowtie2sam.pl /data/images/proton/DKlab/mr/parclip/raw/IGGF-4p3.bowtie > IGGF-4p3.sam
/data/results/tools/samtools/samtools-1.3/misc/bowtie2sam.pl /data/images/proton/DKlab/mr/parclip/raw/IFNF-4p3.bowtie > IFNF-4p3.sam
/data/results/tools/samtools/samtools-1.3/misc/bowtie2sam.pl /data/images/proton/DKlab/mr/parclip/raw/IL4F-4p3.bowtie > IL4F-4p3.sam


#samtools view -bhS 0hF-4p_PARalyzer_Utilized.sam  | samtools sort -o - - > test.bam

#time ./PARalyzer 50G sample.ini-IGG-b 
#I identified a total of 4237592 reads mapping to 1072388 Unique genomic coordinates
#Making up 58618 groups
#Consisting of 21306 clusters

#@ 1rep IGG, filtered reads, PAPpipe settings

cd /data/images/proton/DKlab/mr/parclip/paralyzer/PARalyzer_v1_5
./PARalyzer 5G /data/images/proton/DKlab/mr/parclip/paralyzer/PARalyzer_v1_5/sample.ini-IGGF-4p3-HAFNER_APPROACH.ini
./PARalyzer 5G /data/images/proton/DKlab/mr/parclip/paralyzer/PARalyzer_v1_5/sample.ini-IFNF-4p3-HAFNER_APPROACH.ini
./PARalyzer 5G /data/images/proton/DKlab/mr/parclip/paralyzer/PARalyzer_v1_5/sample.ini-IL4F-4p3-HAFNER_APPROACH.ini
./PARalyzer 9G /data/images/proton/DKlab/mr/parclip/paralyzer/PARalyzer_v1_5/sample.ini-0hF-4p3-HAFNER_APPROACH.ini
./PARalyzer 9G /data/images/proton/DKlab/mr/parclip/paralyzer/PARalyzer_v1_5/sample.ini-2hF-4p3-HAFNER_APPROACH.ini
./PARalyzer 9G /data/images/proton/DKlab/mr/parclip/paralyzer/PARalyzer_v1_5/sample.ini-6hF-4p3-HAFNER_APPROACH.ini 
#mod HERE

./prepParPipe1.sh 0hF-4p3-HAFNER_APPROACH
./prepParPipe1.sh IGGF-4p3-HAFNER_APPROACH

# cp IGGF-4p2_PARalyzer_Utilized.sam test.sam
# samtools view -bS -t /data/results/reference/mmu/Mus_musculus/UCSC/mm9/Sequence/WholeGenomeFasta/genome.fa.fai test.sam  | samtools sort -o - - > test.bam
# samtools index test.bam
# Stage readAttributes
#/data/images/proton/DKlab/mr/parclip/parpipe/PARpipe-master/scripts/readAttributesTC_MR1.pl test.sam > test.attr
# Stage annotateReads
#mod HERE
#cp clusters-IGGF-4p2.txt test.clusters
#cp groups-IGGF-4p2.txt test.groups
#cp test.attr test.clusters test.groups /data/images/proton/DKlab/mr/parclip/parpipe/PARpipe-master/test3
#cd /data/images/proton/DKlab/mr/parclip/parpipe/PARpipe-master/test3
#./anno-mm9.sh
#cp test.clusterbed test.readcsv test.groupbed /data/images/proton/DKlab/mr/parclip/paralyzer/PARalyzer_v1_5/
# Stage read_bed
/data/images/proton/DKlab/mr/parclip/parpipe/PARpipe-master/scripts/reads2bed.py test.readcsv > test.readbed
# Stage annotateClusters
# Stage addInfo
intersectBed -a test.readbed -b test.clusterbed -wao -s | 		awk -F "	" 'BEGIN{OFS=",";} { print  		$5,$7,$8,$9,$11,$12}' | sed '/,\-1/d' | 		/data/images/proton/DKlab/mr/parclip/parpipe/PARpipe-master/scripts/editClustersTC.pl .6 > test.clusters.csv
# Stage visbed
cat test.clusters.csv | /data/images/proton/DKlab/mr/parclip/parpipe/PARpipe-master/scripts/visclusterbed.py > test.clusters.bed
# Stage geneLvl
perl /data/images/proton/DKlab/mr/parclip/parpipe/PARpipe-master/scripts/geneLevel.pl test.clusters.csv /data/images/proton/DKlab/mr/parclip/parpipe/PARpipe-master/files/gencode.v11.annotation.gtf > test.gene_cl.csv
# Stage annotateGroups
#/data/images/proton/DKlab/mr/parclip/parpipe/PARpipe-master/scripts/annotate.pl -g /data/images/proton/DKlab/mr/parclip/parpipe/PARpipe-master/files/gencode.v11.annotation.gtf -p /data/images/proton/DKlab/mr/parclip/parpipe/PARpipe-master/scripts/annotationRank.txt -r /data/images/proton/DKlab/mr/parclip/parpipe/PARpipe-master/files/mm9_rmsk.bed.gz -s /data/images/proton/DKlab/mr/parclip/parpipe/PARpipe-master/files/mm9_rmsk_info -strict -oi test.groups | /data/images/proton/DKlab/mr/parclip/parpipe/PARpipe-master/scripts/PARclusters2bed.py > test.groupbed
# Stage addInfoGroups
intersectBed -a test.readbed -b test.groupbed -wao -s | 		awk -F "	" 'BEGIN{OFS=",";} { print  		$5,$7,$8,$9,$11,$12}' | sed '/,\-1/d' | 		/data/images/proton/DKlab/mr/parclip/parpipe/PARpipe-master/scripts/editClustersTC.pl > test.groups.csv
# Stage geneLvlGroups
perl /data/images/proton/DKlab/mr/parclip/parpipe/PARpipe-master/scripts/geneLevel.pl test.groups.csv /data/images/proton/DKlab/mr/parclip/parpipe/PARpipe-master/files/gencode.v11.annotation.gtf > test.gene_gr.csv
# Stage statsTable
/data/images/proton/DKlab/mr/parclip/parpipe/PARpipe-master/scripts/extractDataTC_MR1.pl test > test.clusters.txt
# Stage spatialPerl
perl /data/images/proton/DKlab/mr/parclip/parpipe/PARpipe-master/scripts/Spatial.pl -g /data/images/proton/DKlab/mr/parclip/parpipe/PARpipe-master/files/gencode.v11.annotation.gtf -a test -strict -t /data/images/proton/DKlab/mr/parclip/parpipe/PARpipe-master/files/isoforms.fpkm_tracking

# Stage spatialR
unset TMP; unset TEMP; TEMPDIR="/tmp/47609700210084528-0"  setsid  Rscript - <<'!'
            
		yn<-'n'
		fn<-'test'
		resolution<-3
		install.packages('/data/images/proton/DKlab/mr/parclip/parpipe/PARpipe-master/scripts/colorRamps_2.3.tar.gz', lib='/data/images/proton/DKlab/mr/parclip/parpipe/PARpipe-master/scripts/')
		install.packages('/data/images/proton/DKlab/mr/parclip/parpipe/PARpipe-master/scripts/schoolmath_0.4.tar.gz', lib='/data/images/proton/DKlab/mr/parclip/parpipe/PARpipe-master/scripts/')
		install.packages('/data/images/proton/DKlab/mr/parclip/parpipe/PARpipe-master/scripts/gtools_3.4.1.tar.gz', lib='/data/images/proton/DKlab/mr/parclip/parpipe/PARpipe-master/scripts/')
		install.packages('/data/images/proton/DKlab/mr/parclip/parpipe/PARpipe-master/scripts/ellipse_0.3-8.tar.gz', lib='/data/images/proton/DKlab/mr/parclip/parpipe/PARpipe-master/scripts/')
		install.packages('/data/images/proton/DKlab/mr/parclip/parpipe/PARpipe-master/scripts/RColorBrewer_1.1-2.tar.gz', lib='/data/images/proton/DKlab/mr/parclip/parpipe/PARpipe-master/scripts/')
		install.packages('/data/images/proton/DKlab/mr/parclip/parpipe/PARpipe-master/scripts/LSD_2.5.tar.gz', lib='/data/images/proton/DKlab/mr/parclip/parpipe/PARpipe-master/scripts/')
		library(colorRamps, lib.loc='/data/images/proton/DKlab/mr/parclip/parpipe/PARpipe-master/scripts/')
		library(schoolmath, lib.loc='/data/images/proton/DKlab/mr/parclip/parpipe/PARpipe-master/scripts/')
		library(gtools, lib.loc='/data/images/proton/DKlab/mr/parclip/parpipe/PARpipe-master/scripts/')
		library(ellipse, lib.loc='/data/images/proton/DKlab/mr/parclip/parpipe/PARpipe-master/scripts/')
		library(RColorBrewer, lib.loc='/data/images/proton/DKlab/mr/parclip/parpipe/PARpipe-master/scripts/')
		library(LSD, lib.loc='/data/images/proton/DKlab/mr/parclip/parpipe/PARpipe-master/scripts/')
		library(parallel)
		source('/data/images/proton/DKlab/mr/parclip/parpipe/PARpipe-master/scripts/Spatial.R')
	
!

