<p>I&#39;m tying to extract a specific region of a bam-file into a fasta-file (ultimately). All of the methods I&#39;ve tried so far give me all reads that OVERLAP the desired region, I&#39;m trying to find a way to trim those to only the desired region.</p>

<p>I&#39;ve tried:</p>

<p>samtools view</p>

<p><code>samtools view compiled.sorted.bam ConB:2185-2195</code></p>

<p>intersectBed</p>

<p><code>intersectBed -b test.bed -abam compiled.sorted.bam -ubam &gt; out.bam</code></p>

<p>but these will give the entire read that overlaps my desired region, I&#39;m trying to get something that will trim everything to sam/bam file where the &#39;reads&#39; are 10 nucleotides long. Am I just missing a flag somewhere to limit the returned region?</p>

I wrote [SAM4WebLogo](https://github.com/lindenb/jvarkit/wiki/SAM4WebLogo) for https://www.biostars.org/p/73021/ and I think it could do what you need

    $ java -jar dist/sam4weblogo.jar -r seq1:80-110  sorted.bam  2> /dev/null | head -n 50
    >B7_593:4:106:316:452/1
    TGTTG--------------------------
    >B7_593:4:106:316:452a/1
    TGTTG--------------------------
    >B7_593:4:106:316:452b/1
    TGTTG--------------------------
    >B7_589:8:113:968:19/2
    TGGGG--------------------------
    >B7_589:8:113:968:19a/2
    TGGGG--------------------------
    >B7_589:8:113:968:19b/2
    TGGGG--------------------------
    >EAS54_65:3:321:311:983/1
    TGTGGG-------------------------
    >EAS54_65:3:321:311:983a/1
    TGTGGG-------------------------
    >EAS54_65:3:321:311:983b/1
    TGTGGG-------------------------
    >B7_591:6:155:12:674/2
    TGTGGGGG-----------------------
    >B7_591:6:155:12:674a/2
    TGTGGGGG-----------------------
    >B7_591:6:155:12:674b/2
    TGTGGGGG-----------------------
    >EAS219_FC30151:7:51:1429:1043/2
    TGTGGGGGGCGCCG-----------------
    >EAS219_FC30151:7:51:1429:1043a/2
    TGTGGGGGGCGCCG-----------------
    >EAS219_FC30151:7:51:1429:1043b/2
    TGTGGGGGGCGCCG-----------------
    >B7_591:5:42:540:501/1
    TGTGGGGGCCGCAGTG---------------
    >EAS192_3:5:223:142:410/1
    TGGGGGGGGCGCAGT----------------
    >B7_591:5:42:540:501a/1
    TGTGGGGGCCGCAGTG---------------
    >EAS192_3:5:223:142:410a/1
    TGGGGGGGGCGCAGT----------------
    >B7_591:5:42:540:501b/1
    TGTGGGGGCCGCAGTG---------------
    >EAS192_3:5:223:142:410b/1
    TGGGGGGGGCGCAGT----------------