---
# System prepended metadata

title: Scripts samtools

---

# Scripts samtools

### Script Samtools sort-by name

```
#!/bin/bash

#/data/projects/Pedu/treino/output/star_out
#/data/projects/Pedu/treino/output/star_out_pe


indir1=$1
indir2=$2

basedir1=`pwd`
for dir in `ls -d ${indir1}/*`; do
        if [ -d "${dir}" ]; then
                echo "Entrando no diretorio ${dir}"
                cd ${dir}
                samtools sort -@ 8 -n Aligned.out.sorted.bam -o Aligned.out.sorted.byname.bam
                cd ${basedir1}
        fi

done

basedir2=`pwd`
for dir in `ls -d ${indir2}/*`; do
        if [ -d "${dir}" ]; then
                echo "Entrando no diretorio ${dir}"
                cd ${dir}
                samtools sort -@ 8 -n Aligned.out.sorted.bam -o Aligned.out.sorted.byname.bam
                cd ${basedir2}
        fi

done
```

## Script SAM_nameSorted_to_uniq_count_stats

```
#!/bin/bash

#/usr/local/bioinfo/trinityrnaseq-Trinity-v2.6.6/util/misc/SAM_nameSorted_to_uniq_count_stats.pl`
#/data/projects/Pedu/treino/output/star_out
#/data/projects/Pedu/treino/output/star_out_pe
ndir1=$1
indir2=$2

basedir1=`pwd`
for dir in `ls -d ${indir1}/*`; do
        if [ -d "${dir}" ]; then
                echo "Entrando no diretorio ${dir}"
                cd ${dir}
                 /usr/local/bioinfo/trinityrnaseq-Trinity-v2.6.6/util/misc/SAM_nameSorted_to_uniq_count_stats.pl` Aligned.out.sorted.byname.bam
                > Stats.out.log
                2> Stats.err.log 
                cd ${basedir1}
        fi

done

basedir2=`pwd`
for dir in `ls -d ${indir2}/*`; do
        if [ -d "${dir}" ]; then
                echo "Entrando no diretorio ${dir}"
                cd ${dir}
                 /usr/local/bioinfo/trinityrnaseq-Trinity-v2.6.6/util/misc/SAM_nameSorted_to_uniq_count_stats.pl` Aligned.out.sorted.byname.bam
                > Stats.out.log
                2> Stats.err.log
                cd ${basedir2}
        fi

done
```
