File: genwig.sh

package info (click to toggle)
trinityrnaseq 2.11.0%2Bdfsg-6
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 417,528 kB
  • sloc: perl: 48,420; cpp: 17,749; java: 12,695; python: 3,124; sh: 1,030; ansic: 983; makefile: 688; xml: 62
file content (80 lines) | stat: -rw-r--r-- 1,605 bytes parent folder | download | duplicates (3)
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
#!/bin/bash
sam2wig(){
    chrlen=$1
    chr=$2
    infi=$3
    nosingle=$4
    minins=$5
    maxins=$6
    threads=$7

    outfi="$infi.$chr.wig"
    tmp="$infi.$chr.sam"

    
    samtools view -@ $threads $infi $chr | \
    ./genwig2.py $chrlen $chr - $outfi $nosingle $minins $maxins
    echo "completed: $chr"
}
export -f sam2wig

while getopts ":b:m:n:o:p:q:" opt; do
    case $opt in
    b)
        if [ ! -f $OPTARG ]
            then
                echo "ERROR: Unable to find input bam $OPTARG" >&2
                exit 1
            else
                inbam="$OPTARG"
        fi
    ;;
    m)
        maxins=$OPTARG
    ;;
    n)
        minins=$OPTARG
    ;;
    o)
        if [ ! -d $OPTARG ];
            then
                echo "ERROR: Unable to find output directory $OPTARG" >&2
                exit 1
            else
                outdir="$OPTARG"
        fi
    ;;
    p)
        nproc=$OPTARG
    ;;
    q)
        nosingle=$OPTARG
    ;;
    \?)
        echo "ERROR: Unknown argument $opt" >&2
        exit 1
    ;;
    esac
done

#dump chromosome info from bam index
chrinfo="$inbam.chr"
#sort is required to preserve order between trinity and here
samtools idxstats $inbam | grep -v "^*" | cut -f1,2 | sort > $chrinfo

#generate wigs for segs/chrs
parallel -j $nproc --xapply \
sam2wig {1} {2} $inbam $nosingle $minins $maxins $nproc \
::: `cut -f2 $chrinfo` ::: `cut -f1 $chrinfo`

#cat to final wig and remove file
if [ -f "$inbam.wig" ]
then
    rm "$inbam.wig"
fi

while read chr len
do
    cat "$inbam.$chr.wig" >> "$inbam.wig"
    rm "$inbam.$chr.wig"
done < $chrinfo