Hello Biostars Community,

I am a newbie to the bioinformatics world and need some help with a project I am working on! 

I need to use htsjdk to extract every tlen value from a BAM file and have a few questions.

 - How do a read the BAM file in the first place? I have found SamReader that might do the job like so : 
  SamReader samReader= SamReaderFactory.makeDefault().open(new File("mybam.bam"));
 - How do I find the position of individual chromosomes? I want to multithread the application, reading each chromosome in parallel. 
 - Once I get the position to start reading from, how do I read each line, then the tlen field? 

Sorry for all of the questions, I have been googling a lot and haven't found answers!

Any help is appreciated, thanks in advance! 
This may get you in the right direction:

    // Open bam file
    SamReader samReader= SamReaderFactory.
            makeDefault().
            validationStringency(ValidationStringency.SILENT).
            open(new File("aln.bam"));

    // Start iterating from start to end of chr7. 
    SAMRecordIterator iter = samReader.query("chr7", 0, 0, false);

    while(iter.hasNext()){
        // Iterate thorough each record and extract fragment size
        SAMRecord rec= iter.next();
        int tlen= rec.getInferredInsertSize();
        System.out.println(tlen);
    }

Get list of chromosomes/contig names from `SamReader` object:

    List<SAMSequenceRecord> refSeqs= samReader.getFileHeader().getSequenceDictionary().getSequences();
    for(SAMSequenceRecord ref : refSeqs){
        System.out.println(ref.getSequenceName());
    }

