code: def get_read_type(self, bam_file, n=10):
          
          from collections import Counter
          try:
              p = subprocess.Popen([self.tools.samtools, 'view', bam_file],
                                   stdout=subprocess.PIPE)
              # Count paired alignments
              paired = 0
              read_length = Counter()
              while n > 0:
                  line = p.stdout.next().split("\t")
                  flag = int(line[1])
                  read_length[len(line[9])] += 1
                  if 1 & flag:  # check decimal flag contains 1 (paired)
                      paired += 1
                  n -= 1
              p.kill()
          except IOError("Cannot read provided bam file.") as e:
              raise e
          # Get most abundant read read_length
          read_length = sorted(read_length)[-1]
          # If at least half is paired, return True
          if paired > (n / 2.):
              return "PE", read_length
          else:
              return "SE", read_length
docs: Gets the read type (single, paired) and length of bam file.
          :param str bam_file: Bam file to determine read attributes.
          :param int n: Number of lines to read from bam file.
          :return str, int: tuple of read type and read length