Mercurial > repos > mzytnicki > s_mart
changeset 141:ff6607328942 draft
Uploaded
author | mzytnicki |
---|---|
date | Fri, 10 Jan 2014 09:04:03 -0500 |
parents | a7825a22f239 |
children | 23ace8a3e22c |
files | SMART/Java/Python/CompareOverlappingAdapt.py SMART/Java/Python/CompareOverlappingSmallQuery.py SMART/Java/Python/CompareOverlappingSmallRef.py |
diffstat | 3 files changed, 131 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/SMART/Java/Python/CompareOverlappingAdapt.py Fri Jan 10 09:04:03 2014 -0500 @@ -0,0 +1,115 @@ +#! /usr/bin/env python +# +# Copyright INRA-URGI 2009-2011 +# +# This software is governed by the CeCILL license under French law and +# abiding by the rules of distribution of free software. You can use, +# modify and/ or redistribute the software under the terms of the CeCILL +# license as circulated by CEA, CNRS and INRIA at the following URL +# "http://www.cecill.info". +# +# As a counterpart to the access to the source code and rights to copy, +# modify and redistribute granted by the license, users are provided only +# with a limited warranty and the software's author, the holder of the +# economic rights, and the successive licensors have only limited +# liability. +# +# In this respect, the user's attention is drawn to the risks associated +# with loading, using, modifying and/or developing or reproducing the +# software by the user in light of its specific status of free software, +# that may mean that it is complicated to manipulate, and that also +# therefore means that it is reserved for developers and experienced +# professionals having in-depth computer knowledge. Users are therefore +# encouraged to load and test the software's suitability as regards their +# requirements in conditions enabling the security of their systems and/or +# data to be ensured and, more generally, to use and operate it in the +# same conditions as regards security. +# +# The fact that you are presently reading this means that you have had +# knowledge of the CeCILL license and that you accept its terms. +# +from optparse import OptionParser +import os.path +from SMART.Java.Python.CompareOverlappingSmallQuery import CompareOverlappingSmallQuery +from SMART.Java.Python.CompareOverlappingSmallRef import CompareOverlappingSmallRef +from SMART.Java.Python.CompareOverlapping import CompareOverlapping + + +MAX_SIZE = 10000000 +REFERENCE = 0 +QUERY = 1 + + +class CompareOverlappingAdapt(object): + + def __init__(self, verbosity): + self.verbosity = verbosity + + def setReferenceFile(self, fileName): + self.refSize = os.path.getsize(fileName) + print "refsize:", self.refSize + + def setQueryFile(self, fileName): + self.querySize = os.path.getsize(fileName) + print "querysize:", self.querySize + + def run(self, options): + object = None + if self.refSize < MAX_SIZE: + if self.verbosity >= 100: + print "Using 'Compare Overlapping Small Reference'" + object = CompareOverlappingSmallQuery(options.verbosity) + elif self.querySize < MAX_SIZE: + if self.verbosity >= 100: + print "Using 'Compare Overlapping Small Query'" + object = CompareOverlappingSmallRef(options.verbosity) + if object != None: + object.setQueryFile(options.inputFileName1, options.format1) + object.setReferenceFile(options.inputFileName2, options.format2) + object.setOutputFile(options.outputFileName) + object.includeNotOverlapping(options.notOverlapping) + object.setDistance(options.distance) + object.setCollinear(options.collinear) + object.setAntisense(options.antisense) + object.setInvert(options.exclude) + object.setMinOverlap(options.minOverlap) + object.run() + return + if self.verbosity >= 100: + print "Using 'Compare Overlapping'" + object = CompareOverlapping(options.verbosity) + object.setInput(options.inputFileName1, options.format1, QUERY) + object.setInput(options.inputFileName2, options.format2, REFERENCE) + object.setOutput(options.outputFileName) + object.getAntisenseOnly(options.antisense) + object.getColinearOnly(options.collinear) + object.getInvert(options.exclude) + object.setMaxDistance(options.distance) + object.includeNotOverlapping(options.notOverlapping) + object.setMinOverlap(options.minOverlap) + object.run() + + +if __name__ == "__main__": + + description = "Compare Overlapping Adapt v1.0.1: Start the relevant CompareOverlappingX depending on the input data. [Category: Data Comparison]" + + parser = OptionParser(description = description) + parser.add_option("-i", "--input1", dest="inputFileName1", action="store", type="string", help="query input file [compulsory] [format: file in transcript format given by -f]") + parser.add_option("-f", "--format1", dest="format1", action="store", type="string", help="format of previous file [compulsory] [format: transcript file format]") + parser.add_option("-j", "--input2", dest="inputFileName2", action="store", type="string", help="reference input file [compulsory] [format: file in transcript format given by -g]") + parser.add_option("-g", "--format2", dest="format2", action="store", type="string", help="format of previous file [compulsory] [format: transcript file format]") + parser.add_option("-o", "--output", dest="outputFileName", action="store", type="string", help="output file [format: output file in GFF3 format]") + parser.add_option("-O", "--notOverlapping", dest="notOverlapping", action="store_true", default=False, help="also output not overlapping data [format: bool] [default: false]") + parser.add_option("-d", "--distance", dest="distance", action="store", default=0, type="int", help="accept some distance between query and reference [format: int]") + parser.add_option("-c", "--collinear", dest="collinear", action="store_true", default=False, help="provide collinear features [format: bool] [default: false]") + parser.add_option("-a", "--antisense", dest="antisense", action="store_true", default=False, help="provide antisense features [format: bool] [default: false]") + parser.add_option("-x", "--exclude", dest="exclude", action="store_true", default=False, help="invert the match [format: bool] [default: false]") + parser.add_option("-m", "--minOverlap", dest="minOverlap", action="store", default=False, type="int", help="min. # overlap between query and reference [format: bool] [default: false]") + parser.add_option("-v", "--verbosity", dest="verbosity", action="store", default=1, type="int", help="trace level [format: int]") + (options, args) = parser.parse_args() + + coa = CompareOverlappingAdapt(options.verbosity) + coa.setQueryFile(options.inputFileName1) + coa.setReferenceFile(options.inputFileName2) + coa.run(options)
--- a/SMART/Java/Python/CompareOverlappingSmallQuery.py Tue Nov 05 05:52:22 2013 -0500 +++ b/SMART/Java/Python/CompareOverlappingSmallQuery.py Fri Jan 10 09:04:03 2014 -0500 @@ -74,6 +74,7 @@ self.collinear = False self.pcOverlapQuery = False self.pcOverlapRef = False + self.minOverlap = False self.bins = {} self.overlaps = {} self.notOverlapping = False @@ -107,6 +108,9 @@ self.pcOverlapQuery = pcOverlapQuery self.pcOverlapRef = pcOverlapRef + def setMinOverlap(self, minOverlap): + self.minOverlap = minOverlap + def includeNotOverlapping(self, boolean): self.notOverlapping = boolean @@ -135,6 +139,8 @@ return False if self.antisense and queryTranscript.getDirection() == refTranscript.getDirection(): return False + if self.minOverlap and not queryTranscript.overlapWithExon(refTranscript, self.minOverlap): + return False querySize = queryTranscript.getSize() if self.pcOverlapQuery and not queryTranscript.overlapWithExon(refTranscript, int(querySize * self.pcOverlapQuery / 100.0)): return False @@ -223,6 +229,7 @@ parser.add_option("-a", "--antisense", dest="antisense", action="store_true", default=False, help="provide antisense features [format: bool] [default: false]") parser.add_option("-p", "--pcOverlapQuery", dest="pcOverlapQuery", action="store", default=False, type="int", help="min. % overlap of the query [format: bool] [default: false]") parser.add_option("-P", "--pcOverlapRef", dest="pcOverlapRef", action="store", default=False, type="int", help="min. % overlap of the reference [format: bool] [default: false]") + parser.add_option("-m", "--minOverlap", dest="minOverlap", action="store", default=False, type="int", help="min. # overlap between query and reference [format: bool] [default: false]") parser.add_option("-x", "--exclude", dest="exclude", action="store_true", default=False, help="invert the match [format: bool] [default: false]") parser.add_option("-v", "--verbosity", dest="verbosity", action="store", default=1, type="int", help="trace level [format: int]") (options, args) = parser.parse_args() @@ -236,5 +243,6 @@ cosq.setCollinear(options.collinear) cosq.setAntisense(options.antisense) cosq.setMinPercentOverlap(options.pcOverlapQuery, options.pcOverlapRef) + cosq.setMinOverlap(options.minOverlap) cosq.setInvert(options.exclude) cosq.run()
--- a/SMART/Java/Python/CompareOverlappingSmallRef.py Tue Nov 05 05:52:22 2013 -0500 +++ b/SMART/Java/Python/CompareOverlappingSmallRef.py Fri Jan 10 09:04:03 2014 -0500 @@ -74,6 +74,7 @@ self.distance = None self.pcOverlapQuery = False self.pcOverlapRef = False + self.minOverlap = False self.bins = {} self.notOverlapping = False @@ -106,6 +107,9 @@ self.pcOverlapQuery = pcOverlapQuery self.pcOverlapRef = pcOverlapRef + def setMinOverlap(self, minOverlap): + self.minOverlap = minOverlap + def includeNotOverlapping(self, boolean): self.notOverlapping = boolean @@ -139,6 +143,8 @@ return False if self.antisense and queryTranscript.getDirection() == refTranscript.getDirection(): return False + if self.minOverlap and not queryTranscript.overlapWithExon(refTranscript, self.minOverlap): + return False querySize = queryTranscript.getSize() if self.pcOverlapQuery and not queryTranscript.overlapWithExon(refTranscript, int(querySize * self.pcOverlapQuery / 100.0)): return False @@ -217,6 +223,7 @@ parser.add_option("-a", "--antisense", dest="antisense", action="store_true", default=False, help="provide antisense features [format: bool] [default: false]") parser.add_option("-p", "--pcOverlapQuery", dest="pcOverlapQuery", action="store", default=False, type="int", help="min. % overlap of the query [format: bool] [default: false]") parser.add_option("-P", "--pcOverlapRef", dest="pcOverlapRef", action="store", default=False, type="int", help="min. % overlap of the reference [format: bool] [default: false]") + parser.add_option("-m", "--minOverlap", dest="minOverlap", action="store", default=False, type="int", help="min. # overlap between query and reference [format: bool] [default: false]") parser.add_option("-x", "--exclude", dest="exclude", action="store_true", default=False, help="invert the match [format: bool] [default: false]") parser.add_option("-v", "--verbosity", dest="verbosity", action="store", default=1, type="int", help="trace level [format: int]") (options, args) = parser.parse_args() @@ -230,5 +237,6 @@ cosr.setAntisense(options.antisense) cosr.setInvert(options.exclude) cosr.setMinPercentOverlap(options.pcOverlapQuery, options.pcOverlapRef) + cosr.setMinOverlap(options.minOverlap) cosr.run()