How can I only took the mapped ones from STAR ?
2
2
Entering edit mode
7.6 years ago
rekren ▴ 40

Hello,

I wanted to obtain only the "mapped" reads as an output of the STAR. I forgot to delete "--outSAMunmapped Within " and all of my mapped output files also contain all unmapped reads,too. Data size is huge and re-mapping properly wiil take so much time...

How can I fix the BAM files which were supposed to be mapped reads but also include unmapped reads in it ?

#!/bin/bash
mkdir /mnt/data/Toxo_scan/GBR_Male/ToxoMap
while read -r line
do
mkdir ToxoMap/$line
echo $line" -> Running STAR - Toxo now"
STAR  --runThreadN 12 --alignIntronMax 1 --outSAMunmapped Within --outSAMtype BAM SortedByCoordinate --genomeDir "/mnt/data/Toxo_scan/toxo_genome" --readFilesIn "/mnt/data/Toxo_scan/GBR_Male/sickle/"$line"_1_clean.fastq" "/mnt/data/Toxo_scan/GBR_Male/sickle/"$line"_2_clean.fastq" --outFileNamePrefix "/mnt/data/Toxo_scan/GBR_Male/ToxoMap/"$line"_" --outReadsUnmapped Fastx
done
RNA-Seq STAR genome SAMunmapped • 6.5k views
ADD COMMENT
0
Entering edit mode

Is the presence of unmapped reads causing issues? If you were going to do counts etc those reads will be ignored.

ADD REPLY
0
Entering edit mode

They were causing the issues because, I was supposed to process only the mapped reads in the workflow. For my case, presence of the unmapped reads in the mapped reads is like having false positive results into the true positive results...

ADD REPLY
1
Entering edit mode

Out of curiosity what was the downstream workflow component that was causing a problem? Most programs should understand reads that are unmapped easily.

ADD REPLY
0
Entering edit mode

The issue was not related with downstream workflow components, it was about my supervisor's satisfaction :) When I came with millions of undesired "unmapped" reads as a result of "mapped" reads, I was in the position of not doing the task well. That's all :)

ADD REPLY
0
Entering edit mode

it was about my supervisor's satisfaction :)

Aha. No logical solution would suffice in that case.

ADD REPLY
6
Entering edit mode
7.6 years ago

To get your mapped reads:

samtools view -b -F 4 alignment.bam > mapped.bam

To get your unmapped reads:

samtools view -b -f 4 alignment.bam > unmapped.bam

The -f filters based on bitwise samflags. Flag 4 (or 0x0004) is for unmapped reads. -F does the inverse.

ADD COMMENT
0
Entering edit mode

Thanks a lot friend, it worked.

ADD REPLY
1
Entering edit mode

Go ahead and accept the answer (green checkmark) to provide closure to the thread. You can accept more than one answer.

ADD REPLY
3
Entering edit mode
7.6 years ago

This is what you're looking for:

samtools view -f 0x2 foo.bam > foo.filtered.bam

It will keep only the proper pairs in your alignment (if paired end). Proper pairs: correct orientation and within insert size.

ADD COMMENT

Login before adding your answer.

Traffic: 1844 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6