예제 #1
0
def chipcount(bamfile,
              bwfile,
              maxinsert=180,
              mininsert=130,
              paired=False,
              extend=150):
    """
    :param bamfile:
    :param chromosome:
    :param start:
    :param end:
    :param paired:
    :return:
    """

    samfile = openBam.openBam(bamfile)

    readscount = dict()

    if paired:

        pass

    else:

        pass

    return readscount
예제 #2
0
def dhcutcount(bamfile, chromosome, start, end, library='Duke'):
    """

    :param bamfile: bamfile
    :param chromosome:
    :param start:
    :param end:
    :param library: Duke or Washington

        Duke: |=====>
                        <=====|

        Washington: |===========|

        Out put cutting site '|'

    :return: dictionary of cutting site count
    """

    samfile = openBam.openBam(bamfile)

    readscount = dict()

    if library == 'Duke':

        for aligned_read in samfile.fetch(reference=str(chromosome),
                                          start=start,
                                          end=end):

            if aligned_read.is_reverse:

                site = aligned_read.aend

            else:

                site = aligned_read.pos

            site = site + 1

            if site in readscount:

                readscount[site] = readscount[site] + 1

            else:

                readscount[site] = 1

    elif library == 'Washington':

        pass

    else:

        pass

    return readscount
예제 #3
0
def chipcoverage(bamfile, chromosome, start, end, maxinsert=180, mininsert=130, paired=False, extend=150):
    """
    :param bamfile:
    :param chromosome:
    :param start:
    :param end:
    :param paired:
    :return:
    """

    samfile = openBam.openBam(bamfile)

    readscount = dict()

    if paired:

        for aligened_read in samfile.fetch(reference=str(chromosome), start=start, end=end):

            if aligened_read.is_proper_pair:

                if not aligened_read.is_reverse:

                    if mininsert <= aligened_read.isize <= maxinsert:

                        pair_start = aligened_read.pos

                        for i in range(pair_start, pair_start + aligened_read.isize):

                            if start <= i <= end:

                                if i in readscount:

                                    readscount[i] += 1

                                else:

                                    readscount[i] = 1

    else:

        for alignend_read in samfile.fetch(reference=str(chromosome), start=start, end=end):

            for i in range(alignend_read.pos, alignend_read.pos + extend):

                if start <= i <= end:

                    if i in readscount:

                        readscount[i] += 1

                    else:

                        readscount[i] = 1

    return readscount
예제 #4
0
def coveragecount(bamfile, chromosome, start, end, maxinsert=80, mininsert=1, paired=False):
    """

    :param bamfile:
    :param chromosome:
    :param start:
    :param end:
    :param paired:
    :return: dictionary of mhs middle site count
    """

    samfile = openBam.openBam(bamfile)

    readscount = dict()

    if paired:

        for aligened_read in samfile.fetch(reference=str(chromosome), start=start, end=end):

            if aligened_read.is_proper_pair:

                if not aligened_read.is_reverse:

                    if mininsert <= aligened_read.isize <= maxinsert:

                        pair_start = aligened_read.pos

                        for site in range(pair_start, pair_start + aligened_read.isize):

                            if site in readscount:

                                readscount[site] += 1

                            else:

                                readscount[site] = 1


    else:

        for alignend_read in samfile.fetch(reference=str(chromosome), start=start, end=end):

            if mininsert <= alignend_read.alen <= maxinsert:

                for site in range(alignend_read.pos, alignend_read.pos + alignend_read.alen):

                    if site in readscount:

                        readscount[site] = readscount[site] + 1

                    else:

                        readscount[site] = 1

    return readscount
예제 #5
0
def dhcutcount(bamfile, chromosome, start, end, library='Duke'):
    """

    :param bamfile: bamfile
    :param chromosome:
    :param start:
    :param end:
    :param library: Duke or Washington

        Duke: |=====>
                        <=====|

        Washington: |===========|

        Out put cutting site '|'

    :return: dictionary of cutting site count
    """

    samfile = openBam.openBam(bamfile)

    readscount = dict()

    if library == 'Duke':

        for aligned_read in samfile.fetch(reference=str(chromosome), start=start, end=end):

            if aligned_read.is_reverse:

                site = aligned_read.aend

            else:

                site = aligned_read.pos

            site = site + 1

            if site in readscount:

                readscount[site] = readscount[site] + 1

            else:

                readscount[site] = 1

    elif library == 'Washington':

        pass

    else:

        pass

    return readscount
예제 #6
0
def chipcount(bamfile, bwfile, maxinsert=180, mininsert=130, paired=False, extend=150):
    """
    :param bamfile:
    :param chromosome:
    :param start:
    :param end:
    :param paired:
    :return:
    """

    samfile = openBam.openBam(bamfile)

    readscount = dict()

    if paired:

        pass

    else:

        pass

    return readscount
예제 #7
0
def mhsmidcount(bamfile, chromosome, start, end, maxinsert=80, mininsert=1, paired=False):
    """

    :param bamfile:
    :param chromosome:
    :param start:
    :param end:
    :param paired:
    :return: dictionary of mhs middle site count
    """

    samfile = openBam.openBam(bamfile)

    readscount = dict()

    if paired:

        for aligened_read in samfile.fetch(reference=str(chromosome), start=start, end=end):

            if aligened_read.is_proper_pair:

                if not aligened_read.is_reverse:

                    if mininsert <= aligened_read.isize <= maxinsert:

                        pair_start = aligened_read.pos

                        if aligened_read.isize % 2 == 0:

                            middle1 = pair_start + aligened_read.isize / 2

                            middle2 = pair_start + aligened_read.isize / 2 - 1

                        else:

                            middle1 = pair_start + int(aligened_read.isize / 2)

                            middle2 = pair_start + int(aligened_read.isize / 2)

                        middleint1 = int(middle1)

                        middleint2 = int(middle2)

                        if start <= middleint1 <= end:

                            if middleint1 in readscount:

                                readscount[middleint1] = readscount[middleint1] + 1

                            else:

                                readscount[middleint1] = 1

                        if start <= middleint2 <= end:

                            if middleint2 in readscount:

                                readscount[middleint2] = readscount[middleint2] + 1

                            else:

                                readscount[middleint2] = 1

    else:

        for alignend_read in samfile.fetch(reference=str(chromosome), start=start, end=end):

            if mininsert <= alignend_read.alen <= maxinsert:

                if alignend_read.alen % 2 == 0:

                    middle1 = alignend_read.pos + alignend_read.alen / 2

                    middle2 = alignend_read.pos + alignend_read.alen / 2 + 1

                else:

                    middle1 = alignend_read.pos + int(alignend_read.alen / 2)

                    middle2 = alignend_read.pos + int(alignend_read.alen / 2)

                middleint1 = int(middle1)

                middleint2 = int(middle2)

                if (start <= middleint1 <= end):

                    if middleint1 in readscount:

                        readscount[middleint1] = readscount[middleint1] + 1

                    else:

                        readscount[middleint1] = 1

                if (start <= middleint2 <= end):

                    if middleint2 in readscount:

                        readscount[middleint2] = readscount[middleint2] + 1

                    else:

                        readscount[middleint2] = 1

    return readscount
예제 #8
0
def chipcoverage(bamfile,
                 chromosome,
                 start,
                 end,
                 maxinsert=180,
                 mininsert=130,
                 paired=False,
                 extend=150):
    """
    :param bamfile:
    :param chromosome:
    :param start:
    :param end:
    :param paired:
    :return:
    """

    samfile = openBam.openBam(bamfile)

    readscount = dict()

    if paired:

        for aligened_read in samfile.fetch(reference=str(chromosome),
                                           start=start,
                                           end=end):

            if aligened_read.is_proper_pair:

                if not aligened_read.is_reverse:

                    if mininsert <= aligened_read.isize <= maxinsert:

                        pair_start = aligened_read.pos

                        for i in range(pair_start,
                                       pair_start + aligened_read.isize):

                            if start <= i <= end:

                                if i in readscount:

                                    readscount[i] += 1

                                else:

                                    readscount[i] = 1

    else:

        for alignend_read in samfile.fetch(reference=str(chromosome),
                                           start=start,
                                           end=end):

            for i in range(alignend_read.pos, alignend_read.pos + extend):

                if start <= i <= end:

                    if i in readscount:

                        readscount[i] += 1

                    else:

                        readscount[i] = 1

    return readscount
예제 #9
0
    def __init__(self, bamfile):
        self.bamfile = bamfile

        self.samfile = openBam.openBam(self.bamfile)

        self.chrlen = self.getchrlen()
예제 #10
0
    def __init__(self, bamfile):
        self.bamfile = bamfile

        self.samfile = openBam.openBam(self.bamfile)

        self.chrlen = self.getchrlen()
예제 #11
0
def mhsmidcount(bamfile,
                chromosome,
                start,
                end,
                maxinsert=80,
                mininsert=1,
                paired=False):
    """

    :param bamfile:
    :param chromosome:
    :param start:
    :param end:
    :param paired:
    :return: dictionary of mhs middle site count
    """

    samfile = openBam.openBam(bamfile)

    readscount = dict()

    if paired:

        for aligened_read in samfile.fetch(reference=str(chromosome),
                                           start=start,
                                           end=end):

            if aligened_read.is_proper_pair:

                if not aligened_read.is_reverse:

                    if mininsert <= aligened_read.isize <= maxinsert:

                        pair_start = aligened_read.pos

                        if aligened_read.isize % 2 == 0:

                            middle1 = pair_start + aligened_read.isize / 2

                            middle2 = pair_start + aligened_read.isize / 2 - 1

                        else:

                            middle1 = pair_start + int(aligened_read.isize / 2)

                            middle2 = pair_start + int(aligened_read.isize / 2)

                        middleint1 = int(middle1)

                        middleint2 = int(middle2)

                        if start <= middleint1 <= end:

                            if middleint1 in readscount:

                                readscount[
                                    middleint1] = readscount[middleint1] + 1

                            else:

                                readscount[middleint1] = 1

                        if start <= middleint2 <= end:

                            if middleint2 in readscount:

                                readscount[
                                    middleint2] = readscount[middleint2] + 1

                            else:

                                readscount[middleint2] = 1

    else:

        for alignend_read in samfile.fetch(reference=str(chromosome),
                                           start=start,
                                           end=end):

            if mininsert <= alignend_read.alen <= maxinsert:

                if alignend_read.alen % 2 == 0:

                    middle1 = alignend_read.pos + alignend_read.alen / 2

                    middle2 = alignend_read.pos + alignend_read.alen / 2 + 1

                else:

                    middle1 = alignend_read.pos + int(alignend_read.alen / 2)

                    middle2 = alignend_read.pos + int(alignend_read.alen / 2)

                middleint1 = int(middle1)

                middleint2 = int(middle2)

                if (start <= middleint1 <= end):

                    if middleint1 in readscount:

                        readscount[middleint1] = readscount[middleint1] + 1

                    else:

                        readscount[middleint1] = 1

                if (start <= middleint2 <= end):

                    if middleint2 in readscount:

                        readscount[middleint2] = readscount[middleint2] + 1

                    else:

                        readscount[middleint2] = 1

    return readscount
예제 #12
0
def coveragecount(bamfile,
                  chromosome,
                  start,
                  end,
                  maxinsert=80,
                  mininsert=1,
                  paired=False):
    """

    :param bamfile:
    :param chromosome:
    :param start:
    :param end:
    :param paired:
    :return: dictionary of mhs middle site count
    """

    samfile = openBam.openBam(bamfile)

    readscount = dict()

    if paired:

        for aligened_read in samfile.fetch(reference=str(chromosome),
                                           start=start,
                                           end=end):

            if aligened_read.is_proper_pair:

                if not aligened_read.is_reverse:

                    if mininsert <= aligened_read.isize <= maxinsert:

                        pair_start = aligened_read.pos

                        for site in range(pair_start,
                                          pair_start + aligened_read.isize):

                            if site in readscount:

                                readscount[site] += 1

                            else:

                                readscount[site] = 1

    else:

        for alignend_read in samfile.fetch(reference=str(chromosome),
                                           start=start,
                                           end=end):

            if mininsert <= alignend_read.alen <= maxinsert:

                for site in range(alignend_read.pos,
                                  alignend_read.pos + alignend_read.alen):

                    if site in readscount:

                        readscount[site] = readscount[site] + 1

                    else:

                        readscount[site] = 1

    return readscount