Guest User

Untitled

a guest
Sep 21st, 2018
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.14 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. if [ $# -lt 1 ]; then
  4. echo `basename $0` "<PET RNAseq SAM filename>"
  5. exit
  6. fi
  7.  
  8. F=$1
  9.  
  10. # chromosome length file
  11. G=ce10.len
  12.  
  13. # a temporary name
  14. TNAME=`mktemp -u`
  15. TNAME=$1`basename $TNAME`
  16.  
  17. # convert SAM to BAM
  18. samtools view -bS $F -o ${TNAME}.bam
  19. # sort BAM
  20. samtools sort ${TNAME}.bam ${TNAME}.sorted
  21. # keep only paired reads
  22. samtools view -b -f 2 ${TNAME}.sorted.bam > ${TNAME}.sorted.paired.bam
  23. # convert to bed12
  24. bamToBed -i ${TNAME}.sorted.paired.bam -bed12 > ${TNAME}.sorted.paired.bed12
  25. # fix chromosome names from wormbase/ensembl convention to UCSC style
  26. perl -pi -e '$_="chr".$_;s/MtDNA/M/' ${TNAME}.sorted.paired.bed12
  27.  
  28. # count total reads number and calculate scaling factor for RPM values
  29. TOTAL=`wc -l ${TNAME}.sorted.paired.bed12|cut -f 1 -d " "`
  30. SCALE_FACTOR=`echo "scale=5;1000000.0/"$TOTAL | bc`
  31.  
  32. # compute coverage file in bedGraph, for RPM values
  33. genomeCoverageBed -split -scale ${SCALE_FACTOR} -i ${TNAME}.sorted.paired.bed12 -bga -g ${G} > ${F}.bdg
  34.  
  35. # convert bedGraph to bigWig
  36. bedClip ${F}.bdg ${G} ${TNAME}.bdg.clip
  37. bedGraphToBigWig ${TNAME}.bdg.clip ${G} ${F}.bw
  38.  
  39. # clean temporary files
  40. rm -f ${TNAME}.*
  41.  
  42. echo "Check ${F}.bw"
Add Comment
Please, Sign In to add comment