Пример #1
0
def main(args):
    fwig = gs.loadWig( args.forwardWig, smooth=False )
    rwig = gs.loadWig( args.reverseWig, smooth=False )
    mappedCount = getMappedCount(fwig, rwig)
    poses = loadPos( args.positionFile, args.chromCol, args.startCol, args.endCol, args.strandCol, args.offset, args.format )
    values = []
    #print "\n"
    #print fwig.keys()
    #print rwig.keys()
    for chrom in poses:
        #print "\n"
        #print chrom
        if chrom in fwig:
            chromFwig = gs.expandWig( fwig[ chrom ], 0, 1, False )
        if chrom in rwig:
            chromRwig = gs.expandWig( rwig[ chrom ], 0, 1, False)
        chromPos = poses[ chrom ]
        for p,strand in chromPos:
            keep = True
            tempFValues = np.zeros( 2 * args.width + 1 )
            tempRValues = np.zeros( 2 * args.width + 1 )
            if chrom in fwig:
                #print chromFwig.shape
                start = int(p - args.width - fwig[ chrom ][0,0])
                end = int(p + args.width - fwig[ chrom ][0,0])
                #print 'Forward'
                #print start, " " , end
                #print abs(min(0,start)), ' ', min( tempFValues.shape[0], tempFValues.shape[0] + chromFwig.shape[0] - end -1 )
                #print max(0, start) , ' ', min( chromFwig.shape[0], end + 1 )
                if end >= 0 and start < chromFwig.shape[0]:
                    tempFValues[abs(min(0,start)):min( tempFValues.shape[0], tempFValues.shape[0] + chromFwig.shape[0] - end -1) ] = chromFwig[ max(0, start) : min( chromFwig.shape[0], end + 1 ) ]

            if chrom in rwig:
                #print chromRwig.shape
                start = int(p - args.width - rwig[ chrom ][0,0])
                end = int(p + args.width - rwig[ chrom ][0,0])
                #print 'Reverse'
                #print start, " ", end
                #print abs(min(0,start)), ' ', min( tempRValues.shape[0], tempRValues.shape[0] + chromRwig.shape[0] - end -1)
                #print max(0, start) , ' ', min( chromRwig.shape[0], end + 1 )
                if end >= 0 and start < chromRwig.shape[0]:
                    tempRValues[abs(min(0,start)):min( tempRValues.shape[0], tempRValues.shape[0] + chromRwig.shape[0] - end -1 ) ] = chromRwig[ max(0, start) : min( chromRwig.shape[0], end + 1 ) ]
            thresh = mappedCount * args.thresh / 10**6
            if tempRValues.sum() < thresh or tempFValues.sum() < thresh:
                keep = False
            if keep:
                if strand == '-':
                    temp = tempFValues[::-1]
                    tempFValues = tempRValues[::-1]
                    tempRValues = temp
                values.append(10**6*np.array(np.ma.concatenate([tempFValues, tempRValues])) / mappedCount)


    values.sort(key=lambda k:(sum(k),))

    writeAll( values, args.out + ".txt" )
    values = np.array(values)
    plot( values[:,0:2*args.width+1], values[:,2*args.width+1:], args.width, args.out )
Пример #2
0
def main():
    parser = argparse.ArgumentParser(description="Pair the peaks on different strand.")
    parser.add_argument( "peak", help="The bed file contains all peaks." )
    parser.add_argument( 'forwardWig', help="The forward wig file." )
    parser.add_argument( 'reverseWig', help="The reverse wig file." )
    parser.add_argument( 'output', help="The output prefix. Will output two files, one containing all the singletons and the other with the pairs. The pair file will be in GFF format and singletons in BED format. Output files will be prefix_singletons.bed and prefix_pairs.gff" )
    parser.add_argument( '-d', '--downstream', type = int, default = 100, help = "Within how far downstream to look for a mate." )
    parser.add_argument( '-u', '--upstream', type = int, default = 0, help = "Within how far upstream to look for a mate." )

    args = parser.parse_args()

    fpeaks, rpeaks = loadPeaks( args.peak )
    fwig = gs.loadWig( args.forwardWig, smooth=False )
    rwig = gs.loadWig( args.reverseWig, smooth=False )

    pair( fpeaks, rpeaks, fwig, rwig, args.upstream, args.downstream, args.output)