-
Notifications
You must be signed in to change notification settings - Fork 1
/
unpac
93 lines (79 loc) · 1.83 KB
/
unpac
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
#! /usr/bin/env bash
info() {
cat <<EOF
Converts PacBio bam files into fasta or fastq format using bam2fastx
provided by PacBio https://github.com/PacificBiosciences/bam2fastx
MUST have bam2fastx installed (simple via conda)
[usage]: unpac -f <fastq/a> -o <outfile.name> -d <working.directory>
[example]: unpac -f fasta -o pangolin_1 -d ./pangolin_pbio
-f <fastX> | fasta or fastq file output
-o <outfile> | output filename prefix
-d <directory> | path to working directory
EOF
}
usage() {
cat <<EOF
[usage]: unpac -f fastq/a -o <outfile.name> -d <working.directory>
[example]: unpac -f fasta -o armadillo -d ./
EOF
}
if [[ -z "$1" ]]; then
info
exit 1
fi
fastq(){
echo "output file will be named $OUTFILE.fq.gz"
bam2fastq -o $OUTFILE $SUBREADS
if [ $SCRAPS == "y" ] ; then
bam2fastq -o $OUTFILE $SCRAPFILES
fi
}
export -f fastq
fasta(){
echo "output file will be named $OUTFILE.fa.gz"
bam2fasta -o $OUTFILE $SUBREADS
if [ $SCRAPS == 'y' ] ; then
bam2fasta -o $OUTFILE $SCRAPFILES
fi
}
export -f fasta
while getopts ":f:o:d:" opt; do
case $opt in
f)
FASTX=$OPTARG
if [ "$FASTX" != 'fastq' ] && [ "$FASTX" != 'fasta' ] ; then
echo -e "\n\t :::Please specify either fasta or fastq:::"
usage
exit 1
fi
;;
o)
OUTFILE=$OPTARG
;;
d)
WORKDIR=$OPTARG
;;
\?)
echo "Invalid option: -$OPTARG" >&2
usage
exit 1
;;
:)
echo "-$OPTARG requires an argument." >&2
usage
exit 1
;;
esac
done
SUBREADS=$(find $WORKDIR -name "*.subreads.bam")
echo "Do you want to process scraps.bam files too (y/n)? "
read -r SCRAPS
if [ $SCRAPS == "y" ] ; then
SCRAPFILES=$(find $WORKDIR -name "*.scraps.bam")
fi
if [ $FASTX == "fastq" ] ; then
fastq
else
fasta
fi
exit 1