Exemplo n.º 1
0
def process_args(args=None):
    args = parse_arguments().parse_args(args)
    if args.correctedFile.name.endswith('bam'):
        if not cfg.checkProgram(samtools, 'view',
                                'http://samtools.sourceforge.net/'):
            exit(1)
    if args.correctedFile.name.endswith('bw'):
        if not cfg.checkProgram(bedgraph_to_bigwig, '-h',
                                'http://hgdownload.cse.ucsc.edu/admin/exe/'):
            exit(1)

    return args
Exemplo n.º 2
0
def getChromSizes(bigwigFilesList):
    """
    Get chromosome sizes from bigWig file by shell calling bigWigInfo
    (UCSC tools).

    Test dataset with two samples covering 200 bp.
    >>> test = Tester()

    Chromosome name(s) and size(s).
    >>> getChromSizes([test.bwFile1, test.bwFile2])
    [('3R', 200)]
    """
    #The following lines are - with one exception ("bigWigInfo") -
    #identical with the bw-reading part of deeptools/countReadsPerBin.py (FK)


    # check that the path to USCS bedGraphToBigWig as set in the config
    # is installed and is executable.
    bigwig_info_cmd = cfg.config.get('external_tools', 'bigwig_info')

    if not cfg.checkProgram(bigwig_info_cmd, '-h',
                            'http://hgdownload.cse.ucsc.edu/admin/exe/'):
        exit()

    cCommon = []
    chromNamesAndSize = {}
    for bw in bigwigFilesList:
        inBlock = False
        for line in os.popen("{} -chroms {}".format(bigwig_info_cmd, bw)).readlines():
            if line[0:10] == "chromCount":
                inBlock = True
                continue
            if line[0:5] == "bases":
                break
            if inBlock:
                chromName, id, size = line.strip().split(" ")
                size = int(size)
                if chromName in chromNamesAndSize:
                    cCommon.append(chromName)
                    if chromNamesAndSize[chromName] != size:
                        print "\nWARNING\n" \
                            "Chromosome {} length reported in the " \
                            "bigwig files differ.\n{} for {}\n" \
                            "{} for {}.\n\nThe smallest " \
                            "length will be used".format(
                            chromName, chromNamesAndSize[chromName],
                            bw[0], size, bw[1])
                        chromNamesAndSize[chromName] = min(
                            chromNamesAndSize[chromName], size)
                else:
                    chromNamesAndSize[chromName] = size
    # get the list of common chromosome names and sizes
    chromSizes = sorted([(k, v) for k, v in chromNamesAndSize.iteritems() \
                         if k in cCommon])
    return chromSizes
Exemplo n.º 3
0
def checkBigWig(string):
    """
    Checks if the path to USCS bedGraphToBigWig as set in the config
    is installed and is executable.
    """
    if string == 'bigwig':
        bedgraph_to_bigwig = cfg.config.get('external_tools',
                                            'bedgraph_to_bigwig')
        if not cfg.checkProgram(bedgraph_to_bigwig, 'h',
                                'http://hgdownload.cse.ucsc.edu/admin/exe/'):
            msg = "The output is set by default to 'bedgraph'\n"
            sys.stderr.write(msg)
            return 'bedgraph'

    return string
Exemplo n.º 4
0
def checkBigWig(string):
    """
    Checks if the path to USCS bedGraphToBigWig as set in the config
    is installed and is executable.
    """
    if string == 'bigwig':
        bedgraph_to_bigwig = cfg.config.get('external_tools',
                                            'bedgraph_to_bigwig')
        if not cfg.checkProgram(bedgraph_to_bigwig, 'h',
                                'http://hgdownload.cse.ucsc.edu/admin/exe/'):
            msg = "The output is set by default to 'bedgraph'\n"
            sys.stderr.write(msg)
            return 'bedgraph'

    return string