Question: How can I only took the mapped ones from STAR ?
0
gravatar for rekren
9 weeks ago by
rekren10
rekren10 wrote:

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
samunmapped rna-seq star genome • 146 views
ADD COMMENTlink modified 9 weeks ago by andrew.j.skelton733.3k • written 9 weeks ago by rekren10

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

ADD REPLYlink written 9 weeks ago by genomax29k

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 REPLYlink written 9 weeks ago by rekren10
1

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

ADD REPLYlink modified 9 weeks ago • written 9 weeks ago by genomax29k

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 REPLYlink written 9 weeks ago by rekren10

it was about my supervisor's satisfaction :)

Aha. No logical solution would suffice in that case.

ADD REPLYlink written 9 weeks ago by genomax29k
3
gravatar for andrew.j.skelton73
9 weeks ago by
Newcastle Upon Tyne
andrew.j.skelton733.3k wrote:

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 COMMENTlink written 9 weeks ago by andrew.j.skelton733.3k

Thanks a lot friend, it worked.

ADD REPLYlink written 9 weeks ago by rekren10
1

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

ADD REPLYlink written 9 weeks ago by genomax29k
3
gravatar for Macspider
9 weeks ago by
Macspider1.2k
Vienna - BOKU
Macspider1.2k wrote:

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 COMMENTlink written 9 weeks ago by Macspider1.2k
Please log in to add an answer.

Help
Access

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.
Powered by Biostar version 2.3.0
Traffic: 508 users visited in the last hour