Commits

Davide Cittaro committed 3493eb7

Chromosome size reading in bigWig is native

  • Participants
  • Parent commits 677d52f

Comments (0)

Files changed (1)

File lib/dspomics/ptpileup.py

         for (chrom, size) in csize.items():
           self.addChromosome(chrom, int(size))
     elif fmt == "bw":
-      for (chrom, size) in getChromosomeFromBigWig(fname):
+      for (chrom, size) in getChromosomeSizesFromBigWig(fname):
         self.addChromosome(chrom, size)
     
       giterator = subprocess.Popen(["bigWigToBedGraph", fname, "stdout"], shell = False, stdout = subprocess.PIPE).stdout 
         self._flush()
 
 
-def getChromosomeFromBigWig(bwname):
+def getChromosomeSizesFromBigWig(bwname):
   csize = {}
   bw = open(os.path.expanduser(bwname), "rb")
   
   
   (blockSize, keySize, valSize, itemCount, reserved) = struct.unpack(endianness + 'IIIQQ', fh.read(28))
   (isLeaf, reserved, count) = struct.unpack(endianness + 'BBH', fh.read(4))
-  for n in range(itemCount):
-    (key, chromId, chromSize) = struct.unpack(endianness + str(keySize) + 'sII', fh.read(keySize + 2 * 4))
-    # we have chrom and size
-    csize[key.replace('\x00', '')] = chromSize
-  return csize  
+  if isLeaf:
+    for n in range(count):
+      (key, chromId, chromSize) = struct.unpack(endianness + str(keySize) + 'sII', fh.read(keySize + 2 * 4))
+      # we have chrom and size
+      csize[key.replace('\x00', '')] = chromSize
+    return csize  
 #  (key, childOffset) = struct.unpack(endianness + str(keySize) + 'sQ', fh.read(keySize + 8))