| 
80
 | 
     1 #!/bin/bash
 | 
| 
87
 | 
     2 
 | 
| 
 | 
     3 #TOOLDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
 | 
| 
80
 | 
     4 
 | 
| 
 | 
     5 echo "Started FALCO calling"
 | 
| 
 | 
     6 
 | 
| 
 | 
     7 ## ----------
 | 
| 
 | 
     8 ## Variables setup ($1 contains the bash config file path)
 | 
| 
 | 
     9 ## ----------
 | 
| 
 | 
    10 source $1
 | 
| 
87
 | 
    11 TOOLDIR=$2
 | 
| 
80
 | 
    12 
 | 
| 
 | 
    13 ## ----------
 | 
| 
 | 
    14 ## make sure all is ok
 | 
| 
 | 
    15 ## ----------
 | 
| 
 | 
    16 if [ ! -f $REF_FILE".fai" ]
 | 
| 
 | 
    17 then
 | 
| 
 | 
    18 	echo "No FAI index (fai) found for reference fasta [$REF_FILE]"
 | 
| 
 | 
    19 	exit "No FAI index (fai) found for reference fasta [$REF_FILE]"
 | 
| 
 | 
    20 fi
 | 
| 
 | 
    21 
 | 
| 
 | 
    22 ## ----------
 | 
| 
 | 
    23 ## set params
 | 
| 
 | 
    24 ## ----------
 | 
| 
 | 
    25 if [[ $filter_file != 'None' && $filter_file != '' ]] # Galaxy default is "None" for some reason
 | 
| 
 | 
    26 then 
 | 
| 
 | 
    27 	FILTER_PARAM=" --filter "$filter_file
 | 
| 
 | 
    28 else
 | 
| 
 | 
    29 	FILTER_PARAM=""
 | 
| 
 | 
    30 fi
 | 
| 
 | 
    31 
 | 
| 
 | 
    32 if [[ $manifest_file != 'None' && $manifest_file != 'None' ]] # Galaxy default is "None" for some reason
 | 
| 
 | 
    33 then 
 | 
| 
 | 
    34 	MANIFEST_PARAM=" --manifest "$manifest_file
 | 
| 
 | 
    35 else
 | 
| 
 | 
    36 	MANIFEST_PARAM=""
 | 
| 
 | 
    37 fi
 | 
| 
 | 
    38 
 | 
| 
 | 
    39 ## name of file in galaxy not always set so will use a user-set job_name instead
 | 
| 
 | 
    40 #bam_base=`echo $bam_name | sed 's#.bam$##' - ` 
 | 
| 
 | 
    41 bam_base=$job_name
 | 
| 
 | 
    42 
 | 
| 
 | 
    43 ## ----------
 | 
| 
 | 
    44 ## Status / debug
 | 
| 
 | 
    45 ## ----------
 | 
| 
 | 
    46 DEBUG=1
 | 
| 
 | 
    47 if [ $DEBUG ]
 | 
| 
 | 
    48 then
 | 
| 
 | 
    49 	DBS="[INFO] "
 | 
| 
 | 
    50 	echo $DBS"FILTER:   "$filter_file
 | 
| 
 | 
    51 	echo $DBS"MANIFEST: "$manifest_file
 | 
| 
 | 
    52 	echo $DBS"REF FILE: "$REF_FILE
 | 
| 
 | 
    53 	echo $DBS"DB KEY:   "$DB_KEY
 | 
| 
 | 
    54 	echo $DBS"REF SRC:  "$REF_SOURCE
 | 
| 
 | 
    55 	echo $DBS"BAM FILE: "$bam_file
 | 
| 
 | 
    56 	echo $DBS"BAM NAME: "$bam_name
 | 
| 
 | 
    57 	echo $DBS"BAM BASE: "$bam_base
 | 
| 
 | 
    58 	echo $DBS"OUT PATH: "$out_path
 | 
| 
 | 
    59 fi
 | 
| 
 | 
    60 
 | 
| 
 | 
    61 ## ----------
 | 
| 
 | 
    62 ## create output files dir
 | 
| 
 | 
    63 ## ----------
 | 
| 
 | 
    64 mkdir $out_path
 | 
| 
 | 
    65 
 | 
| 
 | 
    66 ## ----------
 | 
| 
 | 
    67 ## running analysis
 | 
| 
 | 
    68 ## ----------
 | 
| 
 | 
    69 echo "[INFO] Starting variant calling"
 | 
| 
 | 
    70 ## NOTE: if $FILTER_PARAM is set it includes the param name (--filter)
 | 
| 
 | 
    71 ## NOTE: if $MANIFEST_PARAM is set it includes the param name (--manifest)
 | 
| 
 | 
    72 CALL_STRING="$TOOLDIR/falco/bin/falco --bam $bam_file --output $bam_base --ref $REF_FILE $FILTER_PARAM $MANIFEST_PARAM"
 | 
| 
 | 
    73 echo "[INFO] "$CALL_STRING
 | 
| 
 | 
    74 perl $CALL_STRING
 | 
| 
 | 
    75 echo "[INFO] done with variant calling"
 | 
| 
 | 
    76 
 | 
| 
 | 
    77 
 | 
| 
 | 
    78 ## ----------
 | 
| 
 | 
    79 ## create index html for main galaxy output
 | 
| 
 | 
    80 ## ----------
 | 
| 
 | 
    81 echo "<!DOCTYPE html>" >> $html_out
 | 
| 
 | 
    82 echo "<html>" >> $html_out
 | 
| 
 | 
    83 echo "<head>" >> $html_out
 | 
| 
 | 
    84 echo "<style>" >> $html_out
 | 
| 
 | 
    85 echo "    body{ padding: 0px 20px; }" >> $html_out
 | 
| 
 | 
    86 echo "    h1{ color: red; }" >> $html_out
 | 
| 
 | 
    87 echo "    table{ border: 1px solid black; padding: 5px }" >> $html_out
 | 
| 
 | 
    88 echo "</style>" >> $html_out
 | 
| 
 | 
    89 echo "</head>" >> $html_out
 | 
| 
 | 
    90 echo "<body>" >> $html_out
 | 
| 
 | 
    91 echo "	<h1>FALCO</h1>" >> $html_out
 | 
| 
 | 
    92 echo "	<p>This page is way to get output files that are not implemented in galaxy history, it is not intended to be a user-friendly way of displaying anything ;)</p>" >> $html_out
 | 
| 
 | 
    93 #echo "	<a href=\"index.html\">HTML</a>" >> $html_out
 | 
| 
 | 
    94 echo "	<table><tbody>" >> $html_out
 | 
| 
 | 
    95 for file in *.vcf *.txt *stderr *stdout
 | 
| 
 | 
    96 #for file in *
 | 
| 
 | 
    97 do
 | 
| 
 | 
    98 	lineCount=`wc -l $file | cut -f 1 -d " "`
 | 
| 
 | 
    99 	echo "	<tr><td><a href=\"$file\">$file</a> has $lineCount lines</td></tr>" >> $html_out
 | 
| 
 | 
   100 	echo "  <tr><td> --> " `head -1 $file` "</td></tr>" >> $html_out
 | 
| 
 | 
   101 done
 | 
| 
 | 
   102 echo "	</tbody></table>" >> $html_out
 | 
| 
 | 
   103 echo "</body>" >> $html_out
 | 
| 
 | 
   104 echo "</html>" >> $html_out
 | 
| 
 | 
   105 
 | 
| 
 | 
   106 ## ----------
 | 
| 
 | 
   107 ## creating galaxy history outputs
 | 
| 
 | 
   108 ## ----------
 | 
| 
 | 
   109 #cp 'index.html' $html_out # this is the overview of samples html
 | 
| 
 | 
   110 #cp $bam_base'.html' $out_path/'out.html' # this is the sample html
 | 
| 
 | 
   111 cp $bam_base'.falco.vcf' $vcf_out
 | 
| 
 | 
   112 cp $bam_base'.qc.ann.qual.txt' $qc_ann_qual_out
 | 
| 
 | 
   113 cp $bam_base'.qc2.ann.txt' $qc2_ann_txt_out
 | 
| 
 | 
   114 cp $bam_base'.qc.targets.txt' $qc_targets_txt_out
 | 
| 
 | 
   115 
 | 
| 
 | 
   116 ## ----------
 | 
| 
 | 
   117 ## copy files to keep to output path
 | 
| 
 | 
   118 ## ----------
 | 
| 
 | 
   119 #cp -r ./$bam_base/*png $out_path/$bam_base/
 | 
| 
 | 
   120 #cp -r ./* $out_path
 | 
| 
 | 
   121 cp *.vcf $out_path; cp *.txt $out_path; cp *_std* $out_path
 | 
| 
 | 
   122 
 | 
| 
 | 
   123 ## ----------
 | 
| 
 | 
   124 echo "END falco sh"
 | 
| 
 | 
   125 exit 0
 |