Mercurial > repos > devteam > intersect
diff gops_intersect.py @ 3:4e321cae9da1 draft
planemo upload commit 33927a87ba2eee9bf0ecdd376a66241b17b3d734
author | devteam |
---|---|
date | Tue, 13 Oct 2015 12:50:41 -0400 |
parents | d4d33e26deef |
children | 60925436ca5f |
line wrap: on
line diff
--- a/gops_intersect.py Mon Apr 14 09:19:55 2014 -0400 +++ b/gops_intersect.py Tue Oct 13 12:50:41 2015 -0400 @@ -11,34 +11,34 @@ -G, --gff1: input 1 is GFF format, meaning start and end coordinates are 1-based, closed interval -H, --gff2: input 2 is GFF format, meaning start and end coordinates are 1-based, closed interval """ -import sys, traceback, fileinput -from warnings import warn -from bx.intervals import * -from bx.intervals.io import * -from bx.intervals.operations.intersect import * +import fileinput +import sys +from bx.intervals.io import GenomicInterval, NiceReaderWrapper +from bx.intervals.operations.intersect import intersect from bx.cookbook import doc_optparse -from galaxy.tools.util.galaxyops import * +from bx.tabular.io import ParseError +from galaxy.tools.util.galaxyops import fail, parse_cols_arg, skipped from utils.gff_util import GFFFeature, GFFReaderWrapper, convert_bed_coords_to_gff assert sys.version_info[:2] >= ( 2, 4 ) + def main(): mincols = 1 - upstream_pad = 0 - downstream_pad = 0 options, args = doc_optparse.parse( __doc__ ) try: chr_col_1, start_col_1, end_col_1, strand_col_1 = parse_cols_arg( options.cols1 ) - chr_col_2, start_col_2, end_col_2, strand_col_2 = parse_cols_arg( options.cols2 ) - if options.mincols: mincols = int( options.mincols ) + chr_col_2, start_col_2, end_col_2, strand_col_2 = parse_cols_arg( options.cols2 ) + if options.mincols: + mincols = int( options.mincols ) pieces = bool( options.pieces ) in1_gff_format = bool( options.gff1 ) in2_gff_format = bool( options.gff2 ) in_fname, in2_fname, out_fname = args except: doc_optparse.exception() - + # Set readers to handle either GFF or default format. if in1_gff_format: in1_reader_wrapper = GFFReaderWrapper @@ -48,29 +48,29 @@ in2_reader_wrapper = GFFReaderWrapper else: in2_reader_wrapper = NiceReaderWrapper - + g1 = in1_reader_wrapper( fileinput.FileInput( in_fname ), - chrom_col=chr_col_1, - start_col=start_col_1, - end_col=end_col_1, - strand_col=strand_col_1, - fix_strand=True ) + chrom_col=chr_col_1, + start_col=start_col_1, + end_col=end_col_1, + strand_col=strand_col_1, + fix_strand=True ) if in1_gff_format: # Intersect requires coordinates in BED format. - g1.convert_to_bed_coord=True + g1.convert_to_bed_coord = True g2 = in2_reader_wrapper( fileinput.FileInput( in2_fname ), - chrom_col=chr_col_2, - start_col=start_col_2, - end_col=end_col_2, - strand_col=strand_col_2, - fix_strand=True ) + chrom_col=chr_col_2, + start_col=start_col_2, + end_col=end_col_2, + strand_col=strand_col_2, + fix_strand=True ) if in2_gff_format: # Intersect requires coordinates in BED format. - g2.convert_to_bed_coord=True - + g2.convert_to_bed_coord = True + out_file = open( out_fname, "w" ) try: - for feature in intersect( [g1,g2], pieces=pieces, mincols=mincols ): + for feature in intersect( [g1, g2], pieces=pieces, mincols=mincols ): if isinstance( feature, GFFFeature ): # Convert back to GFF coordinates since reader converted automatically. convert_bed_coords_to_gff( feature )