Changeset 5836


Ignore:
Timestamp:
Feb 24, 2020, 1:38:11 PM (22 months ago)
Author:
Nicklas Nordborg
Message:

References #1218: Implement MIPs alignment

Added functions for converting FASTQ to BAM and annotating with UMI information.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • other/pipeline/trunk/mips_functions.sh

    r5834 r5836  
    6161# Run two Trimmomatic steps. First trim adapters and then quality
    6262# Parameters:
    63 #   $1: Prefix to FASTQ files "_R?.fastq.gz" is added automatilly
    64 #   $2: Prefix for generated files
     63#   $1: Prefix to FASTQ files "_R?.fastq.gz" is added automatically
     64#   $2: Prefix for generated files (counter)
    6565# Global parameters:
    6666#   $JAVA: Path to Java exectable
     
    8181    fastq/${prefix}_R1.fastq.gz fastq/${prefix}_R2.fastq.gz \
    8282    tmp/${n}.adaptrim.1.fastq tmp/${n}.adaptrim.u.1.fastq tmp/${n}.adaptrim.2.fastq tmp/${n}.adaptrim.u.2.fastq \
    83     ${TrimOptionsAdapter}
     83    ${TrimOptionsAdapter} \
    8484    >> trimmomatic.out
    8585   
     
    9797    tmp/${n}.adaptrim.1.fastq tmp/${n}.adaptrim.2.fastq \
    9898    tmp/${n}.qualtrim.1.fastq tmp/${n}.qualtrim.u.1.fastq tmp/${n}.qualtrim.2.fastq tmp/${n}.qualtrim.u.2.fastq \
    99     ${TrimOptionsQual}
     99    ${TrimOptionsQual} \
    100100    >> trimmomatic.out
    101101   
     
    123123}
    124124
     125# Read RG file and convert to Picard2 syntax.
     126# Parameters:
     127#   $1: Path to RG file
     128# Returns:
     129#   Converted RG value
     130function read_and_fix_rg {
     131  local rg=$1
     132 
     133  read -r DATA < ${rg}
     134 
     135  DATA=${DATA/RG=/-READ_GROUP_NAME }
     136  DATA=${DATA/SM=/-SAMPLE_NAME }
     137  DATA=${DATA/LB=/-LIBRARY_NAME }
     138  DATA=${DATA/PU=/-PLATFORM_UNIT }
     139  DATA=${DATA/DT=/-RUN_DATE }
     140  DATA=${DATA/PL=/-PLATFORM  }
     141  DATA=${DATA/CN=/-SEQUENCING_CENTER }
     142 
     143  echo ${DATA}
     144}
    125145
     146# Run Picard to convert FASTQ files to BAM file
     147# Parameters:
     148#   $1: Prefix to RG file ".rg" is added automatically
     149#   $2: Prefix for generated files (counter)
     150function fastq_to_bam {
     151  local prefix=$1
     152  local n=$2
     153 
     154  if [ ! -f tmp/${n}.qualtrim.1.fastq ]; then
     155    return
     156  fi
     157 
     158  local rg=$(read_and_fix_rg "fastq/${prefix}.rg")
     159 
     160  ./stdwrap.sh ./picard2 FastqToSam \
     161    -SORT_ORDER queryname \
     162    -QUALITY_FORMAT Standard \
     163    ${rg} \
     164    -FASTQ tmp/${n}.qualtrim.1.fastq \
     165    -FASTQ2 tmp/${n}.qualtrim.2.fastq \
     166    -OUTPUT tmp/${n}.u.bam \
     167    >> fastqtosam.out
     168}
     169
     170# Run FgBio to annotate the BAM file with UMI information
     171# Parameters:
     172#   $1: Prefix to UMI file "_UMI.fastq.gz" is added automatically
     173#   $2: Prefix for generated files (counter)
     174# Global parameters:
     175#   $JAVA: Path to Java exectable
     176#   $FgBioJAR: Path to FgBio JAR file
     177function annotate_umi {
     178  local prefix=$1
     179  local n=$2
     180 
     181  if [ ! -f tmp/${n}.u.bam ]; then
     182    return
     183  fi
     184 
     185  ./stdwrap.sh ${JAVA} -jar ${FgBioJAR} AnnotateBamWithUmis \
     186    --fail-fast true -t RX \
     187    -i tmp/${n}.u.bam \
     188    -f fastq/${prefix}_UMI.fastq.gz \
     189    -o tmp/${n}.umi.bam \
     190    >> annotatebam.out
     191
     192}
     193
     194
Note: See TracChangeset for help on using the changeset viewer.