/usr/bin/bam2starch_sge is in bedops 2.4.26+dfsg-1.
This file is owned by root:root, with mode 0o755.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 | #!/usr/bin/tcsh -ef
# bam2starch_sge
# -----------------------------------------------------------------------
# Copyright (C) 2011-2016 Shane Neph and Alex Reynolds
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
####################################################
# cluster variables:
# change to match your environment
# may also require changes to 2 'qsub' calls below
####################################################
set shell = "-S /usr/bin/tcsh"
set queue = "-q all.q"
set misc_opts = "-V -cwd -w e -r yes -now no"
set soundoff = "-j n -e /dev/null -o /dev/null"
set sge_opts = "$queue $shell $misc_opts $soundoff"
############################
# some input error checking
############################
set help = "\nUsage: bam2starch_sge [--help] [--clean] <input-indexed-bam-file> [output-starch-file]\n\n"
set help = "$help Pass in the name of an indexed BAM file to create a Starch archive using the cluster.\n\n"
set help = "$help (stdin isn't supported through this wrapper script, but Starch supports it natively.)\n\n"
set help = "$help Add --clean to remove <input-indexed-bam-file> after starching it up.\n\n"
set help = "$help You can pass in the name of the output Starch archive to be created.\n"
set help = "$help Otherwise, the output will have the same name as the input file, with an additional\n"
set help = "$help '.starch' ending. If the input file ends with '.bam', that will be stripped off.\n"
if ( $#argv == 0 ) then
printf "$help"
exit -1
endif
@ inputset = 0
@ clean = 0
foreach argc (`seq 1 $#argv`)
if ( "$argv[$argc]" == "--help" ) then
printf "$help"
exit 0
else if ( "$argv[$argc]" == "--clean" ) then
@ clean = 1
else if ( $argc == $#argv ) then
if ( $inputset > 0 ) then
set output = "$argv[$argc]"
else
set originput = "$argv[$argc]"
set output = $originput:t.starch
endif
@ inputset = 1
else if ( $inputset > 0 ) then
printf "$help"
printf "Multiple input files cannot be specified\n"
exit -1
else
set originput = "$argv[$argc]"
set output = $originput:t.starch
@ inputset = 1
endif
end
if ( $inputset == 0 ) then
printf "No input file specified\n"
exit -1
else if ( ! -s $originput ) then
printf "Unable to find BAM file: %s\n" $originput
exit -1
else if ( "$output" == "$originput:t.starch" && "$originput:e" == "bam" ) then
set output = "$originput:t:r.starch"
endif
set origininputindex = "$originput.bai"
if ( ! -s $origininputindex ) then
printf "Unable to find associated BAI file (is the BAM file indexed?): %s\n" $origininputindex
exit -1
endif
###############################################################
# new working directory to keep file pileups local to this job
###############################################################
set nm = b2scs.`uname -a | cut -f2 -d' '`.$$
if ( -d $nm ) then
rm -rf $nm
endif
mkdir -p $nm
set here = `pwd`
cd $nm
if ( -s ../$originput ) then
set input = ../$originput
else
# $originput includes absolute path
set input = $originput
endif
# $output:h gives back $output if there is no directory information
if ( -d ../$output:h || "$output:h" == "$output" ) then
set output = $here/$output
else if ( `echo $output | awk '{ print substr($0, 1, 1); }'` == "/" ) then
# $output includes absolute path
else
# $output includes non-absolute path
set output = $here/$output
endif
#####################################################
# extract information by chromosome and bam2starch it
#####################################################
set files = ()
set jids = ()
@ cntr = 0
foreach chrom (`samtools idxstats $input | awk '$1!~"^*"'`)
qsub $sge_opts -N $nm.$cntr > /dev/stderr << __EXTRACTION__
samtools view -b $input $chrom | bam2starch - > $here/$nm/$cntr
__EXTRACTION__
set jids = ($jids $nm.$cntr)
set files = ($files $here/$nm/$cntr)
@ cntr++
end
if ( $cntr == 0 ) then
printf "Program problem: no files were submitted to the cluster?\n"
exit -1
endif
##################################################
# create final starch archive and clean things up
##################################################
qsub $sge_opts -N $nm.union -hold_jid `echo $jids | tr ' ' ','` > /dev/stderr << __CATTED__
starchcat $files > $output
cd $here
rm -rf $nm
if ( $clean > 0 ) then
rm -f $originput
endif
__CATTED__
exit 0
|