Question: Is there an R function that transforms a decimal SAM FLAG into a list of strings?
1
gravatar for cristian
9 months ago by
cristian90
cristian90 wrote:

Hi,

Does anybody know of an R function that takes a decimal number as input, the FLAG number from a SAM file, and outputs a list of text stating whether the read has multiple alignments, is properly aligned, is mapped, etc.?

It should not be too hard to code, but if it is already present in some Bioconductor package, I would rather use that.

Thanks.

Best, C.

alignment format sam bam R flag • 383 views
ADD COMMENTlink modified 4 weeks ago by mathieu.lajoie10 • written 9 months ago by cristian90
2
gravatar for cpad0112
9 months ago by
cpad01126.4k
cpad01126.4k wrote:

https://rdrr.io/github/jefferys/SamSeq/

> library(SamSeq)
> samFlags(1024)
SUPPLEMENTARY_ALIGNMENT          DUPLICATE_READ    READ_FAILS_VENDOR_QC   NOT_PRIMARY_ALIGNMENT 
                  FALSE                    TRUE                   FALSE                   FALSE 
         SECOND_OF_PAIR           FIRST_OF_PAIR     MATE_REVERSE_STRAND     READ_REVERSE_STRAND 
                  FALSE                   FALSE                   FALSE                   FALSE 
          MATE_UNMAPPED           READ_UNMAPPED             PROPER_PAIR             READ_PAIRED 
                  FALSE                   FALSE                   FALSE                   FALSE 

> samFlags(228)[samFlags(228)==1]
     SECOND_OF_PAIR       FIRST_OF_PAIR MATE_REVERSE_STRAND       READ_UNMAPPED 
               TRUE                TRUE                TRUE                TRUE 
> samFlags(2056)[samFlags(2056)==1]
SUPPLEMENTARY_ALIGNMENT           MATE_UNMAPPED 
                   TRUE                    TRUE 
> samFlags(128)[samFlags(128)==1]
SECOND_OF_PAIR 
          TRUE

Reverse flag search:

> samFlags("SUPPLEMENTARY_ALIGNMENT")
[1] 2048
> samFlags(c("SUPPLEMENTARY_ALIGNMENT","MATE_UNMAPPED"))
[1] 2056
ADD COMMENTlink modified 9 months ago • written 9 months ago by cpad01126.4k
1
gravatar for mathieu.lajoie
4 weeks ago by
Canada
mathieu.lajoie10 wrote:

library(Rsamtools)

bamFlagAsBitMatrix( as.integer (1024))

FLAG_BITNAMES[ as.logical( bamFlagAsBitMatrix( as.integer(1024)))]

ADD COMMENTlink written 4 weeks ago by mathieu.lajoie10

Tip of the day: to save typing, declare integer type with the L suffix as in 1024L, instead of as.integer(1024).

ADD REPLYlink written 4 weeks ago by Charles Plessy2.5k
0
gravatar for VHahaut
9 months ago by
VHahaut1.1k
Belgium
VHahaut1.1k wrote:

https://www.rdocumentation.org/packages/Rsamtools/versions/1.24.0/topics/ScanBamParam

This doesn't answer 100% your question but ScanBamParam() / ScanBamFlag can parse a SAM file and extract reads with certain features (isProperPair, isPaired, ...)

ADD COMMENTlink modified 9 months ago • written 9 months ago by VHahaut1.1k
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: 974 users visited in the last hour