Seqanswers Leaderboard Ad

Collapse

Announcement

Collapse
No announcement yet.
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • read strand

    Hi NGS users,
    is there a way (by using bioperl module of samtools) to extract the information about the strand of the reads using a bam alignment?
    Thanx a lot!
    ME

  • #2
    I don't know how to do it in perl, but I've done it in python using pysam. You can take a look at:
    franklin library for NGS sequencing analysis. Contribute to JoseBlanca/franklin development by creating an account on GitHub.


    The code that does the job is around lines 140 to 170 in the function _snvs_in_bam.

    Comment


    • #3
      Originally posted by m_elena_bioinfo View Post
      Hi NGS users,
      is there a way (by using bioperl module of samtools) to extract the information about the strand of the reads using a bam alignment?
      Thanx a lot!
      ME
      Yes, here is some sample code:

      Code:
      #!/usr/bin/perl
      
      use strict;
      use warnings;
      
      use Bio::DB::Sam
      
      # Instantiate a new Bio::DB::Sam object, passing it the BAM file and the reference FASTA.
      
      my $sam = Bio::DB::Sam ->new(-bam=>"myPath/myBamFile.bam",
                                   -fasta=>"myPath/myFastaFile.fa");
      
      
      # Create a collection of alignment objects.  The arguments for get_features_by_location are seq_id (e.g. chrom name), start and end (1 based).
      
      
      my @alignments = $sam->get_features_by_location(-seq_id=>'chr1',
                                                      -start=>500,
                                                      -end=>15000);
      
      
      # Iterate over the aligments, querying each one for the strand of the read.
      
      for my $a (@alignments) {
      	
      	my $strand=$a->strand;
      	
      	# Do something with strand info.
      	
      	# You can also get seq_id, start, end, cigar string and much more about each alignment.
      	
      }

      Comment


      • #4
        Thank you very much for the rapid answers! Both are very useful!

        @kmcarr:in module Bio:B::Sam i found two different thing:
        my $strand=$a->strand;
        my $strand-query=$a->query->strand;

        What is the different? The query strand (the second variable) is the strand of the read?

        Comment


        • #5
          Originally posted by m_elena_bioinfo View Post
          Thank you very much for the rapid answers! Both are very useful!

          @kmcarr:in module Bio:B::Sam i found two different thing:
          my $strand=$a->strand;
          my $strand-query=$a->query->strand;

          What is the different? The query strand (the second variable) is the strand of the read?
          By my reading of the APIs they are both giving you the same information, just from slightly different points of view. In the first case you are calling the strand method on a Bio:B::BAM::Alignment object, and in the second case you are calling the strand method within a Bio:B::BAM::Query object.

          In the first case strand reports whether the query sequence matches the forward (+1) or reverse (-1) strand of the reference. The second method reports whether or not the query sequence itself (+1) or the reverse complement of the query sequence (-1) matches the forward strand of the reference.

          Comment


          • #6
            Great Kmcarr, thanks for all the help you gave me.
            I tried to compare the two codes by extracting the strand of the reads in both methods. The results were the same!

            So I think that the only difference is the context and the module of bioperl that you use in your script!

            Comment

            Latest Articles

            Collapse

            • seqadmin
              Best Practices for Single-Cell Sequencing Analysis
              by seqadmin



              While isolating and preparing single cells for sequencing was historically the bottleneck, recent technological advancements have shifted the challenge to data analysis. This highlights the rapidly evolving nature of single-cell sequencing. The inherent complexity of single-cell analysis has intensified with the surge in data volume and the incorporation of diverse and more complex datasets. This article explores the challenges in analysis, examines common pitfalls, offers...
              06-06-2024, 07:15 AM
            • seqadmin
              Latest Developments in Precision Medicine
              by seqadmin



              Technological advances have led to drastic improvements in the field of precision medicine, enabling more personalized approaches to treatment. This article explores four leading groups that are overcoming many of the challenges of genomic profiling and precision medicine through their innovative platforms and technologies.

              Somatic Genomics
              “We have such a tremendous amount of genetic diversity that exists within each of us, and not just between us as individuals,”...
              05-24-2024, 01:16 PM

            ad_right_rmr

            Collapse

            News

            Collapse

            Topics Statistics Last Post
            Started by seqadmin, 06-07-2024, 06:58 AM
            0 responses
            176 views
            0 likes
            Last Post seqadmin  
            Started by seqadmin, 06-06-2024, 08:18 AM
            0 responses
            203 views
            0 likes
            Last Post seqadmin  
            Started by seqadmin, 06-06-2024, 08:04 AM
            0 responses
            177 views
            0 likes
            Last Post seqadmin  
            Started by seqadmin, 06-03-2024, 06:55 AM
            0 responses
            16 views
            0 likes
            Last Post seqadmin  
            Working...
            X