Unconfigured Ad

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts
  • CodeHippo
    Junior Member
    • Mar 2014
    • 4

    Getting Reference Name with Samtools/Picard

    Greetings,

    I am currently working in Picard, the java version of SAMtools. I am using the queryContained() method to count the number of reads in a BAM file by specified regions. This method requires an int start, int end, and String Name. I assume that the String Name value is the name of the reference sequence(s) in the BAM file. I tested this on a Human Chr20 BAM file from NCBI and found that I only got an output if I used "20" as my string name.

    Now here's my question: How can I make Picard check the BAM file for me and print out what the name of the reference sequence(s) is? I've tried incorporating the getReferenceName() method, but when I use it on the Chr20 BAM file, I always get "*" as an output. Here is a rough example of the logic I've tried so far:

    SAMFileReader reader = new SAMFileReader(bamFile, index);
    SAMFileHeader Bob = reader.getFileHeader();
    SAMRecord Jimmy = new SAMRecord(Bob);
    String Earl = Jimmy.getReferenceName();
    System.out.println(Earl);


    Any help will be greatly appreciated
  • lindenb
    Senior Member
    • Apr 2010
    • 143

    #2
    use sequence dictionary to get the list of reference sequences:


    Code:
    for(SAMSequenceRecord ssr:Bob.getSequenceDictionary().getSequences())
    {
    System.out.println(ssr.getSequenceName() );
    }

    Comment

    • CodeHippo
      Junior Member
      • Mar 2014
      • 4

      #3
      Thank you! That was exactly what I was looking for!

      Comment

      Latest Articles

      Collapse

      ad_right_rmr

      Collapse

      News

      Collapse

      Topics Statistics Last Post
      Started by SEQadmin2, Yesterday, 10:09 AM
      0 responses
      10 views
      0 reactions
      Last Post SEQadmin2  
      Started by SEQadmin2, 06-04-2026, 08:59 AM
      0 responses
      19 views
      0 reactions
      Last Post SEQadmin2  
      Started by SEQadmin2, 06-02-2026, 12:03 PM
      0 responses
      26 views
      0 reactions
      Last Post SEQadmin2  
      Started by SEQadmin2, 06-02-2026, 11:40 AM
      0 responses
      21 views
      0 reactions
      Last Post SEQadmin2  
      Working...