diff --git a/Bed3Record.py b/Bed3Record.py old mode 100755 new mode 100644 index 679e788..fefad58 --- a/Bed3Record.py +++ b/Bed3Record.py @@ -3,11 +3,8 @@ # License (GPL) version 3, as described at www.opensource.org. # Copyright (C)2016 William H. Majoros (martiandna@gmail.com). #========================================================================= -from __future__ import (absolute_import, division, print_function, - unicode_literals, generators, nested_scopes, with_statement) -from builtins import (bytes, dict, int, list, object, range, str, ascii, - chr, hex, input, next, oct, open, pow, round, super, filter, map, zip) -from Interval import Interval +from .Interval import Interval + #========================================================================= # Attributes: @@ -21,7 +18,7 @@ # end=record.getEnd() # line=record.toString() # Class Methods: -# +# #========================================================================= class Bed3Record: """Bed3Record represents a record in a BED3 file""" diff --git a/Bed6Record.py b/Bed6Record.py old mode 100755 new mode 100644 index b1ddbca..cdf2c74 --- a/Bed6Record.py +++ b/Bed6Record.py @@ -3,11 +3,8 @@ # License (GPL) version 3, as described at www.opensource.org. # Copyright (C)2016 William H. Majoros (martiandna@gmail.com). #========================================================================= -from __future__ import (absolute_import, division, print_function, - unicode_literals, generators, nested_scopes, with_statement) -from builtins import (bytes, dict, int, list, object, range, str, ascii, - chr, hex, input, next, oct, open, pow, round, super, filter, map, zip) -from Bed3Record import Bed3Record +from .Bed3Record import Bed3Record + #========================================================================= # Inherited Attributes: @@ -23,7 +20,7 @@ # bool=isBed6() # str=toString() # Class Methods: -# +# #========================================================================= class Bed6Record(Bed3Record): """Bed6Record represents a record in a BED6 file""" diff --git a/BedGene.py b/BedGene.py old mode 100755 new mode 100644 index 5973d66..1bafdb8 --- a/BedGene.py +++ b/BedGene.py @@ -3,11 +3,8 @@ # License (GPL) version 3, as described at www.opensource.org. # Copyright (C)2016 William H. Majoros (martiandna@gmail.com). #========================================================================= -from __future__ import (absolute_import, division, print_function, - unicode_literals, generators, nested_scopes, with_statement) -from builtins import (bytes, dict, int, list, object, range, str, ascii, - chr, hex, input, next, oct, open, pow, round, super, filter, map, zip) -from Interval import Interval +from .Interval import Interval + #========================================================================= # Attributes: diff --git a/BedGeneReader.py b/BedGeneReader.py old mode 100755 new mode 100644 index a309b84..b1b2465 --- a/BedGeneReader.py +++ b/BedGeneReader.py @@ -3,16 +3,13 @@ # License (GPL) version 3, as described at www.opensource.org. # Copyright (C)2016 William H. Majoros (martiandna@gmail.com). #========================================================================= -from __future__ import (absolute_import, division, print_function, - unicode_literals, generators, nested_scopes, with_statement) -from builtins import (bytes, dict, int, list, object, range, str, ascii, - chr, hex, input, next, oct, open, pow, round, super, filter, map, zip) -from BedReader import BedReader -from BedGene import BedGene +from .BedGene import BedGene +from .BedReader import BedReader + #========================================================================= # Attributes: -# +# # Instance Methods: # reader=BedGeneReader() # genes=reader.read(CDS_filename,UTR_filename=None) @@ -68,7 +65,7 @@ def addUTR(self,filename,genes): raise Exception("BED file has too few fields") id=record.name gene=hash.get(id,None) - if(not gene): + if(not gene): gene=BedGene(id,record.chr,record.strand) genes.append(gene) hash[id]=gene diff --git a/BedReader.py b/BedReader.py old mode 100755 new mode 100644 index a68cabf..ed8551a --- a/BedReader.py +++ b/BedReader.py @@ -3,14 +3,12 @@ # License (GPL) version 3, as described at www.opensource.org. # Copyright (C)2016 William H. Majoros (martiandna@gmail.com). #========================================================================= -from __future__ import (absolute_import, division, print_function, - unicode_literals, generators, nested_scopes, with_statement) -from builtins import (bytes, dict, int, list, object, range, str, ascii, - chr, hex, input, next, oct, open, pow, round, super, filter, map, zip) -from Bed3Record import Bed3Record -from Bed6Record import Bed6Record import re +from .Bed3Record import Bed3Record +from .Bed6Record import Bed6Record + + #========================================================================= # Attributes: # fh : file handle @@ -21,7 +19,7 @@ # list=BedReader.readAll(filename) # hash=BedReader.hashBySubstrate(filename) # chr -> list of records # Class Methods: -# +# #========================================================================= class BedReader: """BedReader reads bed3 and/or bed6 files""" diff --git a/CigarOp.py b/CigarOp.py index 4054e39..4d715e1 100755 --- a/CigarOp.py +++ b/CigarOp.py @@ -3,12 +3,6 @@ # License (GPL) version 3, as described at www.opensource.org. # 2018 William H. Majoros (bmajoros@alumni.duke.edu) #========================================================================= -from __future__ import (absolute_import, division, print_function, - unicode_literals, generators, nested_scopes, with_statement) -from builtins import (bytes, dict, int, list, object, range, str, ascii, - chr, hex, input, next, oct, open, pow, round, super, filter, map, zip) -from Interval import Interval - ADVANCE_QUERY=set(["M","I","S","H","=","X"]) ADVANCE_REF=set(["M","D","N","=","X"]) @@ -51,7 +45,7 @@ def getQueryInterval(self): def getRefInterval(self): return self.interval2 - def getOp(self): + def getOp(self): return self.op def getLength(self): diff --git a/CigarString.py b/CigarString.py index df39868..4e4d89c 100755 --- a/CigarString.py +++ b/CigarString.py @@ -3,14 +3,12 @@ # License (GPL) version 3, as described at www.opensource.org. # 2018 William H. Majoros (bmajoros@alumni.duke.edu) #========================================================================= -from __future__ import (absolute_import, division, print_function, - unicode_literals, generators, nested_scopes, with_statement) -from builtins import (bytes, dict, int, list, object, range, str, ascii, - chr, hex, input, next, oct, open, pow, round, super, filter, map, zip) -from Rex import Rex +from .Rex import Rex + rex=Rex() -from CigarOp import CigarOp -from Interval import Interval +from .CigarOp import CigarOp +from .Interval import Interval + #========================================================================= # Attributes: @@ -25,7 +23,7 @@ # ops=cigar.matchesByLength() # sorted by decreasing length # op=cigar.longestMatch() # returns a CigarOp object (or None) # L=cigar.longestMatchLen() # returns integer -# (numMatches,numMismatches)=cigar.longestMatchStats(seq1,seq2) +# (numMatches,numMismatches)=cigar.longestMatchStats(seq1,seq2) # # ^ Returns none if no match; must call computeIntervals() first! # L=cigar.totalAlignmentLength() # cigar.setOps(ops) @@ -77,7 +75,7 @@ def length(self): def __getitem__(self,i): return self.ops[i] - + def completeMatch(self): ops=self.ops return len(ops)==1 and ops[0].op in ("M","=","X") diff --git a/Codon.py b/Codon.py index 0402750..6a72ca8 100755 --- a/Codon.py +++ b/Codon.py @@ -3,10 +3,6 @@ # License (GPL) version 3, as described at www.opensource.org. # Copyright (C)2016 William H. Majoros (martiandna@gmail.com). #========================================================================= -from __future__ import (absolute_import, division, print_function, - unicode_literals, generators, nested_scopes, with_statement) -from builtins import (bytes, dict, int, list, object, range, str, ascii, - chr, hex, input, next, oct, open, pow, round, super, filter, map, zip) ###################################################################### # bmajoros@duke.edu 10/15/2016 @@ -42,4 +38,4 @@ def __init__(self,exon,triplet,relative,absolute,isInterrupted): self.absoluteCoord=absolute self.isInterrupted=isInterrupted - + diff --git a/CodonIterator.py b/CodonIterator.py old mode 100755 new mode 100644 index 151dca7..16b8e90 --- a/CodonIterator.py +++ b/CodonIterator.py @@ -3,13 +3,7 @@ # License (GPL) version 3, as described at www.opensource.org. # Copyright (C)2016 William H. Majoros (martiandna@gmail.com). #========================================================================= -from __future__ import (absolute_import, division, print_function, - unicode_literals, generators, nested_scopes, with_statement) -from builtins import (bytes, dict, int, list, object, range, str, ascii, - chr, hex, input, next, oct, open, pow, round, super, filter, map, zip) -from Codon import Codon -from Exon import Exon -from Translation import Translation +from .Codon import Codon ###################################################################### # bmajoros@duke.edu 10/15/2016 diff --git a/ConfigFile.py b/ConfigFile.py index 9fc2882..358d5de 100755 --- a/ConfigFile.py +++ b/ConfigFile.py @@ -3,10 +3,6 @@ # This is OPEN SOURxCE SOFTWARE governed by the Gnu General Public # License (GPL) version 3, as described at www.opensource.org. #==================================================================== -from __future__ import (absolute_import, division, print_function, - unicode_literals, generators, nested_scopes, with_statement) -from builtins import (bytes, dict, int, list, object, range, str, ascii, - chr, hex, input, next, oct, open, pow, round, super, filter, map, zip) import re ###################################################################### @@ -49,4 +45,4 @@ def load(self,filename): key=match.group(1) value=match.group(2) hash[key]=value - + diff --git a/DataFrame.py b/DataFrame.py index ba670c3..002150b 100755 --- a/DataFrame.py +++ b/DataFrame.py @@ -3,13 +3,9 @@ # License (GPL) version 3, as described at www.opensource.org. # 2018 William H. Majoros (bmajoros@alumni.duke.edu) #========================================================================= -from __future__ import (absolute_import, division, print_function, - unicode_literals, generators, nested_scopes, with_statement) -from builtins import (bytes, dict, int, list, object, range, str, ascii, - chr, hex, input, next, oct, open, pow, round, super, filter, map, zip) -import sys -from DataFrameRow import DataFrameRow -from Rex import Rex +from .DataFrameRow import DataFrameRow +from .Rex import Rex + rex=Rex() #========================================================================= @@ -120,7 +116,7 @@ def subsetColumns(self,colIndices): def subsetRows(self,rowIndices): newDF=DataFrame() newDF.header=self.header - for i in rowIndices: + for i in rowIndices: newDF.addRow(self[i].clone()) return newDF diff --git a/DataFrameRow.py b/DataFrameRow.py index 2c720e1..0176bf2 100755 --- a/DataFrameRow.py +++ b/DataFrameRow.py @@ -3,11 +3,6 @@ # License (GPL) version 3, as described at www.opensource.org. # 2018 William H. Majoros (bmajoros@alumni.duke.edu) #========================================================================= -from __future__ import (absolute_import, division, print_function, - unicode_literals, generators, nested_scopes, with_statement) -from builtins import (bytes, dict, int, list, object, range, str, ascii, - chr, hex, input, next, oct, open, pow, round, super, filter, map, zip) -import sys #========================================================================= # Attributes: @@ -81,7 +76,7 @@ def getLabel(self): def rename(self,x): self.label=x - + def toInt(self): self.values=[int(x) for x in self.values] diff --git a/EssexNode.py b/EssexNode.py index 6b85530..b784236 100755 --- a/EssexNode.py +++ b/EssexNode.py @@ -3,10 +3,6 @@ # License (GPL) version 3, as described at www.opensource.org. # Copyright (C)2016 William H. Majoros (martiandna@gmail.com). #========================================================================= -from __future__ import (absolute_import, division, print_function, - unicode_literals, generators, nested_scopes, with_statement) -from builtins import (bytes, dict, int, list, object, range, str, ascii, - chr, hex, input, next, oct, open, pow, round, super, filter, map, zip) import copy import re @@ -212,7 +208,7 @@ def countDescendentOrDatum(self,tag): else: # not a node if(child==tag): count+=1 return count - + def hasDescendentOrDatum(self,tag): if(self.tag==tag): return True children=self.elements diff --git a/EssexParser.py b/EssexParser.py index 6241448..398ac55 100755 --- a/EssexParser.py +++ b/EssexParser.py @@ -3,14 +3,10 @@ # License (GPL) version 3, as described at www.opensource.org. # Copyright (C)2016 William H. Majoros (martiandna@gmail.com). #========================================================================= -from __future__ import (absolute_import, division, print_function, - unicode_literals, generators, nested_scopes, with_statement) -from builtins import (bytes, dict, int, list, object, range, str, ascii, - chr, hex, input, next, oct, open, pow, round, super, filter, map, zip) import os -from EssexNode import EssexNode -from EssexScanner import EssexScanner -from EssexToken import EssexToken + +from .EssexNode import EssexNode +from .EssexScanner import EssexScanner ###################################################################### # diff --git a/EssexScanner.py b/EssexScanner.py index 713b9f7..a053a0a 100755 --- a/EssexScanner.py +++ b/EssexScanner.py @@ -3,13 +3,10 @@ # License (GPL) version 3, as described at www.opensource.org. # Copyright (C)2016 William H. Majoros (martiandna@gmail.com). #========================================================================= -from __future__ import (absolute_import, division, print_function, - unicode_literals, generators, nested_scopes, with_statement) -from builtins import (bytes, dict, int, list, object, range, str, ascii, - chr, hex, input, next, oct, open, pow, round, super, filter, map, zip) -from EssexToken import EssexToken import re +from .EssexToken import EssexToken + ###################################################################### # # A token scanner for the EssexParser. @@ -100,4 +97,4 @@ def skipWhitespace(self): if(not re.search("\s",c)): self.unGetChar(c) return - + diff --git a/EssexToken.py b/EssexToken.py index c05ca15..f20c2fd 100755 --- a/EssexToken.py +++ b/EssexToken.py @@ -3,10 +3,6 @@ # License (GPL) version 3, as described at www.opensource.org. # Copyright (C)2016 William H. Majoros (martiandna@gmail.com). #========================================================================= -from __future__ import (absolute_import, division, print_function, - unicode_literals, generators, nested_scopes, with_statement) -from builtins import (bytes, dict, int, list, object, range, str, ascii, - chr, hex, input, next, oct, open, pow, round, super, filter, map, zip) ###################################################################### # Represents a token in a Essex file --- either a parenthesis or a diff --git a/Exon.py b/Exon.py index 1583f68..d9bd27e 100755 --- a/Exon.py +++ b/Exon.py @@ -3,11 +3,7 @@ # License (GPL) version 3, as described at www.opensource.org. # Copyright (C)2016 William H. Majoros (martiandna@gmail.com). #========================================================================= -from __future__ import (absolute_import, division, print_function, - unicode_literals, generators, nested_scopes, with_statement) -from builtins import (bytes, dict, int, list, object, range, str, ascii, - chr, hex, input, next, oct, open, pow, round, super, filter, map, zip) -from Interval import Interval +from .Interval import Interval ###################################################################### # diff --git a/FastaReader.py b/FastaReader.py old mode 100755 new mode 100644 index 1472ac6..f0ad15c --- a/FastaReader.py +++ b/FastaReader.py @@ -3,12 +3,9 @@ # License (GPL) version 3, as described at www.opensource.org. # Copyright (C)2016 William H. Majoros (martiandna@gmail.com). #========================================================================= -from __future__ import (absolute_import, division, print_function, - unicode_literals, generators, nested_scopes, with_statement) -from builtins import (bytes, dict, int, list, object, range, str, ascii, - chr, hex, input, next, oct, open, pow, round, super, filter, map, zip) import re + #========================================================================= # Attributes: # fh : file handle @@ -146,7 +143,7 @@ def readAllAndKeepDefs(cls,filename): hash[id]=[defline,seq] reader.close() return hash - + @classmethod def parseDefline(cls,defline): match=re.search("^\s*>\s*(\S+)(.*)",defline) diff --git a/FastaWriter.py b/FastaWriter.py old mode 100755 new mode 100644 index 7fb8e32..5057d5d --- a/FastaWriter.py +++ b/FastaWriter.py @@ -3,12 +3,9 @@ # License (GPL) version 3, as described at www.opensource.org. # Copyright (C)2016 William H. Majoros (martiandna@gmail.com). #========================================================================= -from __future__ import (absolute_import, division, print_function, - unicode_literals, generators, nested_scopes, with_statement) -from builtins import (bytes, dict, int, list, object, range, str, ascii, - chr, hex, input, next, oct, open, pow, round, super, filter, map, zip) -import re import os +import re + #========================================================================= # Attributes: @@ -29,7 +26,7 @@ def __init__(self,width=60): def writeFasta(self,defline,seq,filename): with open(filename,"w") as fh: self.addToFasta(defline,seq,fh) - + def addToFasta(self,defline,seq,fh): defline=defline.rstrip() if(not re.search("^\s*>",defline)): defline=">"+defline diff --git a/Fastb.py b/Fastb.py old mode 100755 new mode 100644 index 94ef8f0..970d1d4 --- a/Fastb.py +++ b/Fastb.py @@ -3,12 +3,9 @@ # License (GPL) version 3, as described at www.opensource.org. # Copyright (C)2016 William H. Majoros (martiandna@gmail.com). #========================================================================= -from __future__ import (absolute_import, division, print_function, - unicode_literals, generators, nested_scopes, with_statement) -from builtins import (bytes, dict, int, list, object, range, str, ascii, - chr, hex, input, next, oct, open, pow, round, super, filter, map, zip) import re -from FastbTrack import FastbTrack + +from .FastbTrack import FastbTrack ###################################################################### # diff --git a/FastbTrack.py b/FastbTrack.py old mode 100755 new mode 100644 index 6917147..49da857 --- a/FastbTrack.py +++ b/FastbTrack.py @@ -3,12 +3,8 @@ # License (GPL) version 3, as described at www.opensource.org. # Copyright (C)2016 William H. Majoros (martiandna@gmail.com). #========================================================================= -from __future__ import (absolute_import, division, print_function, - unicode_literals, generators, nested_scopes, with_statement) -from builtins import (bytes, dict, int, list, object, range, str, ascii, - chr, hex, input, next, oct, open, pow, round, super, filter, map, zip) -from FastaWriter import FastaWriter -from Interval import Interval +from .FastaWriter import FastaWriter +from .Interval import Interval ###################################################################### # @@ -43,7 +39,7 @@ # array=track.getZeroRegions() # returns array of Interval # array=track.getRegionsAbove(cutoff) # returns array of Interval # bool=track.anyZeroValues() # only for continuous tracks -# array=track.getContiguousRegions() # returns an array of Interval with +# array=track.getContiguousRegions() # returns an array of Interval with # "value" attribute added # newTrack=track.slice(begin,end) # [begin,end) => end not inclusive # meanValue=track.getMean(interval=None) # only for continuous data @@ -199,7 +195,7 @@ def getMean(self,interval=None): L=len(data) begin=0 end=L - if(interval is not None): + if(interval is not None): begin=interval.begin end=interval.end L=end-begin @@ -213,7 +209,7 @@ def getMax(self,interval=None): L=len(data) begin=0 end=L - if(interval is not None): + if(interval is not None): begin=interval.begin end=interval.end L=end-begin diff --git a/FastqReader.py b/FastqReader.py old mode 100755 new mode 100644 index 4237830..b846002 --- a/FastqReader.py +++ b/FastqReader.py @@ -3,14 +3,13 @@ # License (GPL) version 3, as described at www.opensource.org. # 2018 William H. Majoros (bmajoros@allumni.duke.edu) #========================================================================= -from __future__ import (absolute_import, division, print_function, - unicode_literals, generators, nested_scopes, with_statement) -from builtins import (bytes, dict, int, list, object, range, str, ascii, - chr, hex, input, next, oct, open, pow, round, super, filter, map, zip) -from Rex import Rex -rex=Rex() import gzip +from .Rex import Rex + +rex=Rex() + + #========================================================================= # Attributes: # fh : file handle @@ -49,6 +48,6 @@ def nextSequence(self): qualSeq=fh.readline().rstrip() qual=[ord(x)-33 for x in qualSeq] return (ID,seq,qual,qualSeq,pair) - + diff --git a/Fisher2x2.py b/Fisher2x2.py old mode 100755 new mode 100644 index 2714466..8d9b8d2 --- a/Fisher2x2.py +++ b/Fisher2x2.py @@ -3,11 +3,8 @@ # License (GPL) version 3, as described at www.opensource.org. # Copyright (C)2016 William H. Majoros (martiandna@gmail.com). #========================================================================= -from __future__ import (absolute_import, division, print_function, - unicode_literals, generators, nested_scopes, with_statement) -from builtins import (bytes, dict, int, list, object, range, str, ascii, - chr, hex, input, next, oct, open, pow, round, super, filter, map, zip) -from Pipe import Pipe +from .Pipe import Pipe + #========================================================================= # Attributes: @@ -19,7 +16,7 @@ # P=fisher.getPvalue() # (exp00,exp01,exp10,exp11)=fisher.getExpectedCounts() # Class Methods: -# +# #========================================================================= class Fisher2x2: """Fisher2x2 performs Fisher's exact test for 2x2 contingency tables""" @@ -49,6 +46,6 @@ def getExpectedCounts(self): exp10=int(round(pBottom*leftSum,0)) exp11=int(round(pBottom*rightSum,0)) return (exp00,exp01,exp10,exp11) - + diff --git a/GFF3Parser.py b/GFF3Parser.py old mode 100755 new mode 100644 index d929d4a..a27babd --- a/GFF3Parser.py +++ b/GFF3Parser.py @@ -3,19 +3,17 @@ # License (GPL) version 3, as described at www.opensource.org. # Copyright (C)2016 William H. Majoros (martiandna@gmail.com). #========================================================================= -from __future__ import (absolute_import, division, print_function, - unicode_literals, generators, nested_scopes, with_statement) -from builtins import (bytes, dict, int, list, object, range, str, ascii, - chr, hex, input, next, oct, open, pow, round, super, filter, map, zip) -from Rex import Rex -from Gene import Gene -from Transcript import Transcript -from Exon import Exon import re +from .Exon import Exon +from .Gene import Gene +from .Rex import Rex +from .Transcript import Transcript + + #========================================================================= # Attributes: -# +# # Instance Methods: # reader=GFF3Parser() =TESTED # transcriptArray=reader.loadGFF(filename) =TESTED @@ -58,7 +56,7 @@ def hashGenesBySubstrate(self,filename): if(array is None): array=hash[substrate]=[] array.append(gene) return hash - + def hashBySubstrate(self,filename): transcripts=self.loadGFF(filename) hash={} @@ -68,7 +66,7 @@ def hashBySubstrate(self,filename): if(array is None): array=hash[substrate]=[] array.append(transcript) return hash - + def loadGFF(self,filename): genes=self.loadGenes(filename) transcripts=[] @@ -78,7 +76,7 @@ def loadGFF(self,filename): transcript=gene.getIthTranscript(i) transcripts.append(transcript) return transcripts - + def makeGene(self,root): gene=Gene() root["object"]=gene @@ -144,7 +142,7 @@ def makeExon(self,root): for key in extra: exon.extraFields+=key+"="+extra[key]+";" return exon - + def labelStructure(self,root): obj=None t=root["type"] @@ -155,7 +153,7 @@ def labelStructure(self,root): elif(t=="exon" or t=="CDS"): obj=self.makeExon(root) return obj - + def loadGenes(self,filename): roots=self.loadStructure(filename) genes=[] @@ -172,14 +170,14 @@ def loadStructure(self,filename): roots=self.findRoots(records) #for root in roots: self.printStructure(root) return roots - + def printStructure(self,rec,depth=0): print("\t"*depth+rec["type"]+" "+rec["extra"]["ID"]) children=rec.get("children",None) if(not children): return for child in children: self.printStructure(child,depth+1) - + def findRoots(self,records): roots=[] for record in records: @@ -191,7 +189,7 @@ def addChild(self,parent,child): if(parent.get("children",None) is None): parent["children"]=[] parent["children"].append(child) child["parent"]=parent - + def connectParentsChildren(self,records,idHash): for record in records: parent=record["extra"].get("Parent",None) @@ -208,7 +206,7 @@ def hashRecordsByID(self,records,hash): extraHash=record["extra"] ID=extraHash.get("ID",None) if(ID is not None): hash[ID]=record - + def loadRecords(self,filename): fh=open(filename,"rt") records=[] @@ -248,7 +246,7 @@ def parseRecord(self,fields): return rec - + # ========================================================================= def test_parser1(filename): parser=GFF3Parser() @@ -306,7 +304,7 @@ def test_parser3(filename): transcripts=hashTable[substrate] for transcript in transcripts: print(transcript.getID()) - + def test_parser4(filename): reader=GFF3Parser() hashTable=reader.hashGenesBySubstrate(filename) @@ -334,5 +332,5 @@ def test_parser7(filename): genes=reader.loadGenes(filename) for gene in genes: print(gene.toGff()) - + #test_parser7("/Users/bmajoros/python/test/data/subset.gff3") diff --git a/Gene.py b/Gene.py index 95aad44..286c2f6 100755 --- a/Gene.py +++ b/Gene.py @@ -3,12 +3,6 @@ # License (GPL) version 3, as described at www.opensource.org. # Copyright (C)2016 William H. Majoros (martiandna@gmail.com). #========================================================================= -from __future__ import (absolute_import, division, print_function, - unicode_literals, generators, nested_scopes, with_statement) -from builtins import (bytes, dict, int, list, object, range, str, ascii, - chr, hex, input, next, oct, open, pow, round, super, filter, map, zip) -# The above imports should allow this program to run in both Python 2 and -# Python 3. You might need to update your version of module "future". ###################################################################### # Attributes: @@ -31,7 +25,7 @@ # substrate=gene.getSubstrate() # gff=gene.toGff() # exons=gene.getMergedExons() -# +# ###################################################################### class Gene: @@ -153,4 +147,4 @@ def __hash__(self): def __eq__(self,other): return self.ID==other.ID - + diff --git a/GffTranscriptReader.py b/GffTranscriptReader.py index 9a016de..22e8ce8 100755 --- a/GffTranscriptReader.py +++ b/GffTranscriptReader.py @@ -3,19 +3,14 @@ # License (GPL) version 3, as described at www.opensource.org. # Copyright (C)2016 William H. Majoros (martiandna@gmail.com). #========================================================================= -from __future__ import (absolute_import, division, print_function, - unicode_literals, generators, nested_scopes, with_statement) -from builtins import (bytes, dict, int, list, object, range, str, ascii, - chr, hex, input, next, oct, open, pow, round, super, filter, map, zip) -# The above imports should allow this program to run in both Python 2 and -# Python 3. You might need to update your version of module "future". -from Exon import Exon -from Transcript import Transcript -from Gene import Gene -from Integer import Integer -from Rex import Rex import re +from .Exon import Exon +from .Gene import Gene +from .Integer import Integer +from .Rex import Rex +from .Transcript import Transcript + ###################################################################### # Returns a list of Transcripts. For each transcript, the Exons # will be sorted according to order of translation, so that @@ -151,7 +146,7 @@ def adjustStartCodons_fw(self,transcript,totalIntronSize): prevExon=exons[i-1] intronSize=exon.begin-prevExon.end totalIntronSize+=intronSize - if(transcript.startCodon is not None and + if(transcript.startCodon is not None and self.exonContainsPoint(exon,transcript.startCodon)): break return startCodon @@ -179,7 +174,7 @@ def adjustStartCodons_bw(self,transcript,totalIntronSize): if(transcript.startCodon is not None and self.exonContainsPoint(exon,transcript.startCodon)): break return startCodon - + def adjustStartCodons(self,transcripts): for transcript in transcripts: transcript.sortExons() @@ -234,7 +229,7 @@ def loadGFF_transcript(self,fields,line,transcriptBeginEnd,GFF, transcript.setGene(gene) gene.addTranscript(transcript) transcript.extraFields=transcriptExtraFields - + def loadGFF_UTR(self,fields,line,transcriptBeginEnd,GFF, transcripts,readOrder,genes): exonBegin=int(fields[3])-1 @@ -253,8 +248,8 @@ def loadGFF_UTR(self,fields,line,transcriptBeginEnd,GFF, elif(rex.find('gene_id[:=]?\s*"?([^\s\;"]+)"?',line)): geneId=rex[1] if(transcriptId is None): transcriptId=geneId if(geneId is None): geneId=transcriptId - if(transcriptId is None): - raise Exception(line+" : no transcript ID found") + if(transcriptId is None): + raise Exception(line+" : no transcript ID found") if(rex.find("(\S+);$",transcriptId)): transcriptId=rex[1] if(rex.find("(\S+);$",geneId)): geneId=rex[1] extra="" @@ -283,7 +278,7 @@ def loadGFF_UTR(self,fields,line,transcriptBeginEnd,GFF, transcript.setGene(gene) exon=Exon(exonBegin,exonEnd,transcript) exon.extraFields=extra - if(transcript.rawExons is not None): + if(transcript.rawExons is not None): exon.frame=frame exon.score=exonScore exon.type=fields[2] @@ -346,7 +341,7 @@ def loadGFF_exon(self,fields,line,transcriptBeginEnd,GFF, if(transcript.rawExons is None): transcript.rawExons=[] transcript.rawExons.append(exon) gene.addTranscript(transcript) - + def loadGFF_CDS(self,fields,line,transcriptBeginEnd,GFF, transcripts,readOrder,genes): exonBegin=int(fields[3])-1 @@ -365,8 +360,8 @@ def loadGFF_CDS(self,fields,line,transcriptBeginEnd,GFF, elif(rex.find('gene_id[:=]?\s*"?([^\s\;"]+)"?',line)): geneId=rex[1] if(transcriptId is None): transcriptId=geneId if(geneId is None): geneId=transcriptId - if(transcriptId is None): - raise Exception(line+" : no transcript ID found") + if(transcriptId is None): + raise Exception(line+" : no transcript ID found") if(rex.find('(\S+);$',transcriptId)): transcriptId=rex[1] if(rex.find('(\S+);$',geneId)): geneId=rex[1] extra="" diff --git a/Integer.py b/Integer.py index 10037ef..8f255fd 100755 --- a/Integer.py +++ b/Integer.py @@ -3,15 +3,9 @@ # License (GPL) version 3, as described at www.opensource.org. # Copyright (C)2016 William H. Majoros (martiandna@gmail.com). #========================================================================= -from __future__ import (absolute_import, division, print_function, - unicode_literals, generators, nested_scopes, with_statement) -from builtins import (bytes, dict, int, list, object, range, str, ascii, - chr, hex, input, next, oct, open, pow, round, super, filter, map, zip) -# The above imports should allow this program to run in both Python 2 and -# Python 3. You might need to update your version of module "future". class Integer(object): - """Integer is a first-class mutable object, so it can be passed + """Integer is a first-class mutable object, so it can be passed by reference, allowing functions to modify its value. """ def __init__(self,x=0): @@ -81,7 +75,7 @@ def __iand__(self,x): # &= def __ixor__(self,x): # ^= self.value ^= int(x) return self - def __ior__(self,x): # |= + def __ior__(self,x): # |= self.value |= int(x) return self def __neg__(self): # - @@ -128,7 +122,7 @@ def __repr__(self): #=========================== TESTING CODE ========================= def testInteger_func(x): x+=2 - + def testInteger(): x=Integer(1) y=Integer(3) @@ -146,6 +140,6 @@ def testInteger(): y=3 print(x,"%",y,"=",x%y) print((x+4-y*2)/x) - + #testInteger() diff --git a/Interval.py b/Interval.py index b16c497..87bf082 100755 --- a/Interval.py +++ b/Interval.py @@ -3,12 +3,10 @@ # License (GPL) version 3, as described at www.opensource.org. # Copyright (C)2016 William H. Majoros (martiandna@gmail.com). #========================================================================= -from __future__ import (absolute_import, division, print_function, - unicode_literals, generators, nested_scopes, with_statement) -from builtins import (bytes, dict, int, list, object, range, str, ascii, - chr, hex, input, next, oct, open, pow, round, super, filter, map, zip) import sys -from Rex import Rex + +from .Rex import Rex + rex=Rex() #========================================================================= diff --git a/MatrixMarket.py b/MatrixMarket.py index d5bf8ea..91e0889 100755 --- a/MatrixMarket.py +++ b/MatrixMarket.py @@ -4,16 +4,10 @@ # License (GPL) version 3, as described at www.opensource.org. # Author: William H. Majoros (bmajoros@alumni.duke.edu) #========================================================================= -from __future__ import (absolute_import, division, print_function, - unicode_literals, generators, nested_scopes, with_statement) -from builtins import (bytes, dict, int, list, object, range, str, ascii, - chr, hex, input, next, oct, open, pow, round, super, filter, map, zip) -# The above imports should allow this program to run in both Python 2 and -# Python 3. You might need to update your version of module "future". -import sys -import ProgramName import gzip -from Rex import Rex + +from .Rex import Rex + rex=Rex() #========================================================================= diff --git a/NgramIterator.py b/NgramIterator.py index 3a3ea92..6925302 100755 --- a/NgramIterator.py +++ b/NgramIterator.py @@ -4,12 +4,6 @@ # License (GPL) version 3, as described at www.opensource.org. # Copyright (C)2017 William H. Majoros (martiandna@gmail.com). #========================================================================= -from __future__ import (absolute_import, division, print_function, - unicode_literals, generators, nested_scopes, with_statement) -from builtins import (bytes, dict, int, list, object, range, str, ascii, - chr, hex, input, next, oct, open, pow, round, super, filter, map, zip) -# The above imports should allow this program to run in both Python 2 and -# Python 3. You might need to update your version of module "future". ###################################################################### # diff --git a/Pipe.py b/Pipe.py old mode 100755 new mode 100644 index 0db01b2..3cffb6a --- a/Pipe.py +++ b/Pipe.py @@ -3,13 +3,10 @@ # License (GPL) version 3, as described at www.opensource.org. # Copyright (C)2016 William H. Majoros (martiandna@gmail.com). #========================================================================= -from __future__ import (absolute_import, division, print_function, - unicode_literals, generators, nested_scopes, with_statement) -from builtins import (bytes, dict, int, list, object, range, str, ascii, - chr, hex, input, next, oct, open, pow, round, super, filter, map, zip) import subprocess import sys + #========================================================================= # Attributes: # iter diff --git a/ProgramName.py b/ProgramName.py old mode 100755 new mode 100644 index 5eaeb0b..1d18ab8 --- a/ProgramName.py +++ b/ProgramName.py @@ -1,5 +1,6 @@ -import sys import os +import sys + def get(): return os.path.basename(sys.argv[0]) diff --git a/Rex.py b/Rex.py old mode 100755 new mode 100644 index f72ccc0..90620e0 --- a/Rex.py +++ b/Rex.py @@ -3,12 +3,9 @@ # License (GPL) version 3, as described at www.opensource.org. # Copyright (C)2016 William H. Majoros (martiandna@gmail.com). #========================================================================= -from __future__ import (absolute_import, division, print_function, - unicode_literals, generators, nested_scopes, with_statement) -from builtins import (bytes, dict, int, list, object, range, str, ascii, - chr, hex, input, next, oct, open, pow, round, super, filter, map, zip) import re + #========================================================================= # Attributes: # match : returned from re.search() diff --git a/SamMDtagParser.py b/SamMDtagParser.py old mode 100755 new mode 100644 index 8d76815..3eec7bc --- a/SamMDtagParser.py +++ b/SamMDtagParser.py @@ -3,14 +3,10 @@ # License (GPL) version 3, as described at www.opensource.org. # Copyright (C)2016 William H. Majoros (martiandna@gmail.com). #========================================================================= -from __future__ import (absolute_import, division, print_function, - unicode_literals, generators, nested_scopes, with_statement) -from builtins import (bytes, dict, int, list, object, range, str, ascii, - chr, hex, input, next, oct, open, pow, round, super, filter, map, zip) #========================================================================= # Attributes: -# +# # Instance Methods: # SamMDtagParser() # Class Methods: diff --git a/SamReader.py b/SamReader.py old mode 100755 new mode 100644 index 1d47d81..472e9cf --- a/SamReader.py +++ b/SamReader.py @@ -3,15 +3,13 @@ # License (GPL) version 3, as described at www.opensource.org. # 2018 William H. Majoros (bmajoros@allumni.duke.edu) #========================================================================= -from __future__ import (absolute_import, division, print_function, - unicode_literals, generators, nested_scopes, with_statement) -from builtins import (bytes, dict, int, list, object, range, str, ascii, - chr, hex, input, next, oct, open, pow, round, super, filter, map, zip) -from Rex import Rex -rex=Rex() import gzip -from SamRecord import SamRecord -from CigarString import CigarString + +from .CigarString import CigarString +from .Rex import Rex +from .SamRecord import SamRecord + +rex=Rex() #========================================================================= # Attributes: @@ -61,5 +59,5 @@ def nextSeqAndText(self): rec=SamRecord(ID,refName,refPos,CIGAR,seq,flags,tags) return (rec,line) -# M03884:303:000000000-C4RM6:1:1101:1776:15706 99 chrX:31786371-31797409 6687 44 150M = 6813 271 ATACTATTGCTGCGGTAATAACTGTAACTGCAGTTACTATTTAGTGATTTGTATGTAGATGTAGATGTAGTCTATGTCAGACACTATGCTGAGCATTTTATGGTTGCTATGTACTGATACATACAGAAACAAGAGGTACGTTCTTTTACA BBBBFFFFFFFGGGGGEFGGFGHFHFFFHHHFFHHHFHFHHHGFHEDGGHFHBGFHGBDHFHFFFHHHHFHHHHHGHGFFBGGGHFHFFHHFFFFHHHHGHGFHHGFHGHHHGFHFFHHFHHFFGFFFFGGEHFFEHHFGHHHGHHHHFB AS:i:300 XN:i:0 +# M03884:303:000000000-C4RM6:1:1101:1776:15706 99 chrX:31786371-31797409 6687 44 150M = 6813 271 ATACTATTGCTGCGGTAATAACTGTAACTGCAGTTACTATTTAGTGATTTGTATGTAGATGTAGATGTAGTCTATGTCAGACACTATGCTGAGCATTTTATGGTTGCTATGTACTGATACATACAGAAACAAGAGGTACGTTCTTTTACA BBBBFFFFFFFGGGGGEFGGFGHFHFFFHHHFFHHHFHFHHHGFHEDGGHFHBGFHGBDHFHFFFHHHHFHHHHHGHGFFBGGGHFHFFHHFFFFHHHHGHGFHHGFHGHHHGFHFFHHFHHFFGFFFFGGEHFFEHHFGHHHGHHHHFB AS:i:300 XN:i:0 diff --git a/SamRecord.py b/SamRecord.py old mode 100755 new mode 100644 index 61988a8..ef9ba74 --- a/SamRecord.py +++ b/SamRecord.py @@ -3,13 +3,10 @@ # License (GPL) version 3, as described at www.opensource.org. # 2018 William H. Majoros (bmajoros@allumni.duke.edu) #========================================================================= -from __future__ import (absolute_import, division, print_function, - unicode_literals, generators, nested_scopes, with_statement) -from builtins import (bytes, dict, int, list, object, range, str, ascii, - chr, hex, input, next, oct, open, pow, round, super, filter, map, zip) -from Rex import Rex +from .Rex import Rex +from .SamMDtagParser import SamMDtagParser + rex=Rex() -from SamMDtagParser import SamMDtagParser #========================================================================= # Attributes: @@ -97,7 +94,7 @@ def getRefName(self): def getRefPos(self): return self.refPos - + def getCigar(self): return self.CIGAR @@ -157,5 +154,5 @@ def flag_supplAlignment(self): # > 0x400 PCR or optical duplicate # 0x800 supplementary alignment -# M03884:303:000000000-C4RM6:1:1101:1776:15706 99 chrX:31786371-31797409 6687 44 150M = 6813 271 ATACTATTGCTGCGGTAATAACTGTAACTGCAGTTACTATTTAGTGATTTGTATGTAGATGTAGATGTAGTCTATGTCAGACACTATGCTGAGCATTTTATGGTTGCTATGTACTGATACATACAGAAACAAGAGGTACGTTCTTTTACA BBBBFFFFFFFGGGGGEFGGFGHFHFFFHHHFFHHHFHFHHHGFHEDGGHFHBGFHGBDHFHFFFHHHHFHHHHHGHGFFBGGGHFHFFHHFFFFHHHHGHGFHHGFHGHHHGFHFFHHFHHFFGFFFFGGEHFFEHHFGHHHGHHHHFB AS:i:300 XN:i:0 +# M03884:303:000000000-C4RM6:1:1101:1776:15706 99 chrX:31786371-31797409 6687 44 150M = 6813 271 ATACTATTGCTGCGGTAATAACTGTAACTGCAGTTACTATTTAGTGATTTGTATGTAGATGTAGATGTAGTCTATGTCAGACACTATGCTGAGCATTTTATGGTTGCTATGTACTGATACATACAGAAACAAGAGGTACGTTCTTTTACA BBBBFFFFFFFGGGGGEFGGFGHFHFFFHHHFFHHHFHFHHHGFHEDGGHFHBGFHGBDHFHFFFHHHHFHHHHHGHGFFBGGGHFHFFHHFFFFHHHHGHGFHHGFHGHHHGFHFFHHFHHFFGFFFFGGEHFFEHHFGHHHGHHHHFB AS:i:300 XN:i:0 diff --git a/Shuffler.py b/Shuffler.py old mode 100755 new mode 100644 index 366a86a..bf9514d --- a/Shuffler.py +++ b/Shuffler.py @@ -3,15 +3,12 @@ # License (GPL) version 3, as described at www.opensource.org. # Copyright (C)2016 William H. Majoros (martiandna@gmail.com). #========================================================================= -from __future__ import (absolute_import, division, print_function, - unicode_literals, generators, nested_scopes, with_statement) -from builtins import (bytes, dict, int, list, object, range, str, ascii, - chr, hex, input, next, oct, open, pow, round, super, filter, map, zip) import random + #========================================================================= # Attributes: -# +# # Instance Methods: # shuffler=Shuffler() # Class Methods: diff --git a/SlurmWriter.py b/SlurmWriter.py old mode 100755 new mode 100644 index 55d0987..c71c694 --- a/SlurmWriter.py +++ b/SlurmWriter.py @@ -3,12 +3,9 @@ # License (GPL) version 3, as described at www.opensource.org. # Copyright (C)2016 William H. Majoros (martiandna@gmail.com). #========================================================================= -from __future__ import (absolute_import, division, print_function, - unicode_literals, generators, nested_scopes, with_statement) -from builtins import (bytes, dict, int, list, object, range, str, ascii, - chr, hex, input, next, oct, open, pow, round, super, filter, map, zip) import os + #========================================================================= # Attributes: # commands : array of string @@ -46,7 +43,7 @@ def mem(self,value): def threads(self,value): self.threadsValue=value - + def setQueue(self,value): self.queue=value diff --git a/SmithWaterman.py b/SmithWaterman.py index ce08904..64bee1d 100755 --- a/SmithWaterman.py +++ b/SmithWaterman.py @@ -4,23 +4,20 @@ # License (GPL) version 3, as described at www.opensource.org. # Author: William H. Majoros (bmajoros@alumni.duke.edu) #========================================================================= -from __future__ import (absolute_import, division, print_function, - unicode_literals, generators, nested_scopes, with_statement) -from builtins import (bytes, dict, int, list, object, range, str, ascii, - chr, hex, input, next, oct, open, pow, round, super, filter, map, zip) # The above imports should allow this program to run in both Python 2 and # Python 3. You might need to update your version of module "future". import os -from Pipe import Pipe -from Rex import Rex -rex=Rex() -import TempFilename -from CigarString import CigarString -from FastaWriter import FastaWriter +from . import TempFilename +from .CigarString import CigarString +from .FastaWriter import FastaWriter +from .Pipe import Pipe +from .Rex import Rex + +rex=Rex() #========================================================================= # Attributes: -# +# # Instance Methods: # aligner=SmithWaterman(alignerDir,matrixFile,openPenalty,extrendPenalty) # cigarString=aligner.align(seq1,seq2) diff --git a/Stan.py b/Stan.py index 57105e5..c9b9ba6 100755 --- a/Stan.py +++ b/Stan.py @@ -4,17 +4,11 @@ # License (GPL) version 3, as described at www.opensource.org. # Copyright (C)2016 William H. Majoros (martiandna@gmail.com). #========================================================================= -from __future__ import (absolute_import, division, print_function, - unicode_literals, generators, nested_scopes, with_statement) -from builtins import (bytes, dict, int, list, object, range, str, ascii, - chr, hex, input, next, oct, open, pow, round, super, filter, map, zip) -# The above imports should allow this program to run in both Python 2 and -# Python 3. You might need to update your version of module "future". import os ###################################################################### # Attributes: -# +# # Methods: # stan=Stan(model) # stan.run(numWarmup,numSamples,inputFile,outputFile,stderrFile, @@ -111,4 +105,4 @@ def getVarCmd(self,numSamples,inputFile,outputFile,stderrFile,initFile=None): init+\ " output file="+outputFile+" refresh=0 > "+stderrFile return cmd - + diff --git a/StanParser.py b/StanParser.py index 317f55e..971f394 100755 --- a/StanParser.py +++ b/StanParser.py @@ -4,19 +4,14 @@ # License (GPL) version 3, as described at www.opensource.org. # Copyright (C)2016 William H. Majoros (martiandna@gmail.com). #========================================================================= -from __future__ import (absolute_import, division, print_function, - unicode_literals, generators, nested_scopes, with_statement) -from builtins import (bytes, dict, int, list, object, range, str, ascii, - chr, hex, input, next, oct, open, pow, round, super, filter, map, zip) -# The above imports should allow this program to run in both Python 2 and -# Python 3. You might need to update your version of module "future". -from SummaryStats import SummaryStats -from Rex import Rex +from .Rex import Rex +from .SummaryStats import SummaryStats + rex=Rex() ###################################################################### # Attributes: -# +# # Methods: # parser=StanParser(filename) # samples=parser.getSamples() @@ -80,7 +75,7 @@ def parseFile(self,IN): if(line[0]=="#"): continue fields=line.rstrip().split(",") if(len(fields)<1): continue - if(fields[0]=="lp__"): + if(fields[0]=="lp__"): firstIndex=self.getFirstVariableIndex(fields) self.parseVarNames(fields,firstIndex) else: self.parseSample(fields,firstIndex) diff --git a/Strand.py b/Strand.py old mode 100755 new mode 100644 index 2f501a5..8a833cd --- a/Strand.py +++ b/Strand.py @@ -3,12 +3,9 @@ # License (GPL) version 3, as described at www.opensource.org. # Copyright (C)2016 William H. Majoros (martiandna@gmail.com). #========================================================================= -from __future__ import (absolute_import, division, print_function, - unicode_literals, generators, nested_scopes, with_statement) -from builtins import (bytes, dict, int, list, object, range, str, ascii, - chr, hex, input, next, oct, open, pow, round, super, filter, map, zip) from enum import Enum + #========================================================================= # Attributes: # FORWARD : int @@ -21,7 +18,7 @@ class Strand(Enum): FORWARD=1 REVERSE=0 - + @classmethod def toString(cls,strand): return "+" if strand==strand.FORWARD else "-" diff --git a/SumLogProbs.py b/SumLogProbs.py index a9c65b6..9395cda 100755 --- a/SumLogProbs.py +++ b/SumLogProbs.py @@ -4,15 +4,8 @@ # License (GPL) version 3, as described at www.opensource.org. # Copyright (C)2016 William H. Majoros (martiandna@gmail.com). #========================================================================= -from __future__ import (absolute_import, division, print_function, - unicode_literals, generators, nested_scopes, with_statement) -from builtins import (bytes, dict, int, list, object, range, str, ascii, - chr, hex, input, next, oct, open, pow, round, super, filter, map, zip) -# The above imports should allow this program to run in both Python 2 and -# Python 3. You might need to update your version of module "future". import math - NEGATIVE_INFINITY=float("-inf") @@ -32,7 +25,7 @@ def sumLogProbs(x): n=len(x) if(n==1): return x[0] if(n==0): return NEGATIVE_INFINITY - + # Pull out the largest value largestValue=x[0] for v in x: diff --git a/SummaryStats.py b/SummaryStats.py index 51340e3..dd7145e 100755 --- a/SummaryStats.py +++ b/SummaryStats.py @@ -3,15 +3,11 @@ # This is OPEN SOURxCE SOFTWARE governed by the Gnu General Public # License (GPL) version 3, as described at www.opensource.org. #==================================================================== -from __future__ import (absolute_import, division, print_function, - unicode_literals, generators, nested_scopes, with_statement) -from builtins import (bytes, dict, int, list, object, range, str, ascii, - chr, hex, input, next, oct, open, pow, round, super, filter, map, zip) import math ###################################################################### # Attributes: -# +# # Methods: # [mean,SD,min,max]=SummaryStats.summaryStats(array) # [mean,SD,min,max]=SummaryStats.roundedSummaryStats(array) diff --git a/TempFilename.py b/TempFilename.py index 4050e1e..1e59e7d 100755 --- a/TempFilename.py +++ b/TempFilename.py @@ -3,12 +3,9 @@ # License (GPL) version 3, as described at www.opensource.org. # Copyright (C)2016 William H. Majoros (martiandna@gmail.com). #========================================================================= -from __future__ import (absolute_import, division, print_function, - unicode_literals, generators, nested_scopes, with_statement) -from builtins import (bytes, dict, int, list, object, range, str, ascii, - chr, hex, input, next, oct, open, pow, round, super, filter, map, zip) -import tempfile import os +import tempfile + def generate(suffix=""): [fh,filename]=tempfile.mkstemp(suffix) diff --git a/Transcript.py b/Transcript.py index c66e11d..757670a 100755 --- a/Transcript.py +++ b/Transcript.py @@ -3,18 +3,15 @@ # License (GPL) version 3, as described at www.opensource.org. # Copyright (C)2016 William H. Majoros (martiandna@gmail.com). #========================================================================= -from __future__ import (absolute_import, division, print_function, - unicode_literals, generators, nested_scopes, with_statement) -from builtins import (bytes, dict, int, list, object, range, str, ascii, - chr, hex, input, next, oct, open, pow, round, super, filter, map, zip) -from Exon import Exon -from Translation import Translation -from CodonIterator import CodonIterator -from EssexNode import EssexNode -from Interval import Interval import copy import re +from .CodonIterator import CodonIterator +from .EssexNode import EssexNode +from .Exon import Exon +from .Interval import Interval +from .Translation import Translation + ###################################################################### # bmajoros@duke.com 10/15/2016 # @@ -23,7 +20,7 @@ # source : name of entity that predicted or curated this transcript # startCodon : index into (spliced) transcript sequence of ATG, # regardless of strand -# startCodonAbsolute : absolute coordinates of start codon, +# startCodonAbsolute : absolute coordinates of start codon, # relative to genomic axis # score : float # strand : + or - @@ -185,7 +182,7 @@ def __init__(self,id,strand=None): end=int(exon.getIthElem(1)) exon=Exon(begin,end,self) UTR.append(exon) - + def equals(self,other): if(self.getSource()!=other.getSource()): return False if(self.getStrand()!=other.getStrand()): return False @@ -562,7 +559,7 @@ def trimUTR(self,axisSequenceRef): exon.type="initial-exon" if numExons>1 else "single-exon" self.startCodon=0 break - + # Find in-frame stop codon codonIterator=CodonIterator(self,axisSequenceRef,stopCodons) stopCodonFound=False @@ -595,7 +592,7 @@ def trimUTR(self,axisSequenceRef): self.deleteExon(j) j-=1 stopCodonFound=True - break + break if(not stopCodonFound): ### sometimes the GFF coords don't include the stop codon... numExons=self.numExons() @@ -618,7 +615,7 @@ def trimUTR(self,axisSequenceRef): self.transcriptId,self.strand, "strand , unable to trim UTR") self.recomputeBoundaries() - + def getScore(self): return self.score #exons=self.exons @@ -640,7 +637,7 @@ def getIntrons(self): if(lastExonEnd>exon.getBegin()): exit("XXX "+str(lastExonEnd)+" "+str(exon.getBegin())+" "+strand) introns.append(Interval(lastExonEnd,exon.getBegin())) else: - if(lastExonEnd0): rawExons.append(exon.copy()) - for utr in UTR: + for utr in UTR: if(utr.getLength()>0): rawExons.append(utr.copy()) # Sort into chromosome order (temporarily): rawExons.sort(key=lambda exon: exon.begin) diff --git a/Translation.py b/Translation.py index 0e25df3..6745fd0 100755 --- a/Translation.py +++ b/Translation.py @@ -3,11 +3,7 @@ # This is OPEN SOURxCE SOFTWARE governed by the Gnu General Public # License (GPL) version 3, as described at www.opensource.org. #==================================================================== -from __future__ import (absolute_import, division, print_function, - unicode_literals, generators, nested_scopes, with_statement) -from builtins import (bytes, dict, int, list, object, range, str, ascii, - chr, hex, input, next, oct, open, pow, round, super, filter, map, zip) -from NgramIterator import NgramIterator +from .NgramIterator import NgramIterator ###################################################################### # Attributes: @@ -30,7 +26,7 @@ class Translation: codon={} complementMap={} - + @classmethod def translate(cls,transcript): translation="" @@ -84,7 +80,7 @@ def getFourfoldDegenerateCodons(cls): if(len(acids)>1): continue for codon in codons: degenerate.add(codon) return degenerate - + @classmethod def initCodonMap(cls): @@ -184,7 +180,7 @@ def initCodonMap(cls): cls.codon["AGG"]='R' cls.codon["AGA"]='R' cls.codon["AGY"]='R' - + Translation.initCodonMap() Translation.initComplementMap(); diff --git a/__init__.py b/__init__.py old mode 100755 new mode 100644 index 139597f..4a0dfa6 --- a/__init__.py +++ b/__init__.py @@ -1,2 +1,45 @@ - - +from . import ProgramName, SumLogProbs, TempFilename +from .Bed3Record import Bed3Record +from .Bed6Record import Bed6Record +from .BedGene import BedGene +from .BedGeneReader import BedGeneReader +from .BedReader import BedReader +from .CigarOp import CigarOp +from .CigarString import CigarString +from .Codon import Codon +from .CodonIterator import CodonIterator +from .ConfigFile import ConfigFile +from .DataFrame import DataFrame +from .DataFrameRow import DataFrameRow +from .EssexNode import EssexNode +from .EssexParser import EssexParser +from .EssexScanner import EssexScanner +from .EssexToken import EssexToken +from .Exon import Exon +from .FastaReader import FastaReader +from .FastaWriter import FastaWriter +from .Fastb import Fastb +from .FastbTrack import FastbTrack +from .FastqReader import FastqReader +from .Fisher2x2 import Fisher2x2 +from .Gene import Gene +from .GFF3Parser import GFF3Parser +from .GffTranscriptReader import GffTranscriptReader +from .Integer import Integer +from .Interval import Interval +from .MatrixMarket import MatrixMarket +from .NgramIterator import NgramIterator +from .Pipe import Pipe +from .Rex import Rex +from .SamMDtagParser import SamMDtagParser +from .SamReader import SamReader +from .SamRecord import SamRecord +from .Shuffler import Shuffler +from .SlurmWriter import SlurmWriter +from .SmithWaterman import SmithWaterman +from .Stan import Stan +from .StanParser import StanParser +from .Strand import Strand +from .SummaryStats import SummaryStats +from .Transcript import Transcript +from .Translation import Translation diff --git a/essex-pretty-print.py b/essex-pretty-print.py index f54265a..f6ca8b7 100755 --- a/essex-pretty-print.py +++ b/essex-pretty-print.py @@ -4,16 +4,12 @@ # License (GPL) version 3, as described at www.opensource.org. # Author: William H. Majoros (bmajoros@alumni.duke.edu) #========================================================================= -from __future__ import (absolute_import, division, print_function, - unicode_literals, generators, nested_scopes, with_statement) -from builtins import (bytes, dict, int, list, object, range, str, ascii, - chr, hex, input, next, oct, open, pow, round, super, filter, map, zip) -# The above imports should allow this program to run in both Python 2 and -# Python 3. You might need to update your version of module "future". import sys -import ProgramName + from EssexParser import EssexParser +from . import ProgramName + #========================================================================= # main() #========================================================================= diff --git a/extract-gaa.py b/extract-gaa.py index 7759f6a..9dc5a5b 100755 --- a/extract-gaa.py +++ b/extract-gaa.py @@ -1,7 +1,6 @@ #!/usr/bin/env python -import sys -import os import gzip +import sys if(len(sys.argv)!=4): print(sys.argv[0]+" ") diff --git a/fastb-lengths.py b/fastb-lengths.py index 5ab6969..90bec4e 100755 --- a/fastb-lengths.py +++ b/fastb-lengths.py @@ -4,14 +4,11 @@ # License (GPL) version 3, as described at www.opensource.org. # Copyright (C)2016 William H. Majoros (martiandna@gmail.com). #========================================================================= -from __future__ import (absolute_import, division, print_function, - unicode_literals, generators, nested_scopes, with_statement) -from builtins import (bytes, dict, int, list, object, range, str, ascii, - chr, hex, input, next, oct, open, pow, round, super, filter, map, zip) -from Fastb import Fastb -import ProgramName import sys +from . import ProgramName +from .Fastb import Fastb + if(len(sys.argv)!=2): sys.exit(ProgramName.get()+" in.fastb") filename=sys.argv[1] diff --git a/get-SNP-IDs.py b/get-SNP-IDs.py index fe076f8..9d24b17 100755 --- a/get-SNP-IDs.py +++ b/get-SNP-IDs.py @@ -1,8 +1,6 @@ #!/usr/bin/env python -import sys -import os import re -import basic +import sys name=sys.argv[0]; if(len(sys.argv)!=2): diff --git a/hello-world.py b/hello-world.py index 4ca15c1..ffba7da 100755 --- a/hello-world.py +++ b/hello-world.py @@ -1,15 +1,12 @@ #!/usr/bin/env python -from __future__ import (absolute_import, division, print_function, - unicode_literals, generators, nested_scopes, with_statement) -from builtins import (bytes, dict, int, list, object, range, str, ascii, chr, - hex, input, next, oct, open, pow, round, super, filter, map, zip) -import ProgramName -import sys import os -from Interval import Interval -from ConfigFile import ConfigFile -from SummaryStats import SummaryStats import random +import sys + +from . import ProgramName +from .ConfigFile import ConfigFile +from .Interval import Interval +from .SummaryStats import SummaryStats # Process command line name=ProgramName.get(); @@ -50,7 +47,8 @@ def main(): #print(filename,fh) #os.close(fh) -import TempFilename +from . import TempFilename + filename=TempFilename.generate() fh=open(filename,'w') print(fh) diff --git a/make-bam-slurms.py b/make-bam-slurms.py index d93ed25..4d1d927 100755 --- a/make-bam-slurms.py +++ b/make-bam-slurms.py @@ -1,8 +1,6 @@ #!/usr/bin/env python -import sys -import os -import basic import glob +import os import re # Global variables @@ -22,7 +20,7 @@ # Process each sam file jobID=1 for samfile in samFiles: - match=re.search("([^/]+)\.sam",samfile); + match=re.search("([^/]+)\.sam",samfile); bamfile=samDir+"/"+match.group(1)+".bam" bamStem=samDir+"/"+match.group(1) slurmFile=slurmDir+"/"+str(jobID)+".slurm" diff --git a/make-fastqc-slurms.py b/make-fastqc-slurms.py index 561e4d6..4780ff5 100755 --- a/make-fastqc-slurms.py +++ b/make-fastqc-slurms.py @@ -1,8 +1,6 @@ #!/usr/bin/env python -import sys -import os -import basic import glob +import os import re # Global variables diff --git a/make-star-slurms.py b/make-star-slurms.py index 8b375bd..6326241 100755 --- a/make-star-slurms.py +++ b/make-star-slurms.py @@ -1,9 +1,8 @@ #!/usr/bin/env python -import sys -import os -import basic import glob +import os import re +import sys # Global variables jobName="STAR" @@ -48,7 +47,7 @@ # Process each file files=glob.glob(sample+"/*.fastq.gz") for file in files: - match=re.search("([^/]+)\s*$",file); + match=re.search("([^/]+)\s*$",file); if(match is None): sys.exit("can't parse filename") fileNoPath=match.group(1) match=re.search("(\S+_R)([12])(_\S+.fastq.gz)",fileNoPath); diff --git a/new-python-class.py b/new-python-class.py index 7bc488c..5639529 100755 --- a/new-python-class.py +++ b/new-python-class.py @@ -4,13 +4,10 @@ # License (GPL) version 3, as described at www.opensource.org. # Copyright (C)2016 William H. Majoros (martiandna@gmail.com). #========================================================================= -from __future__ import (absolute_import, division, print_function, - unicode_literals, generators, nested_scopes, with_statement) -from builtins import (bytes, dict, int, list, object, range, str, ascii, - chr, hex, input, next, oct, open, pow, round, super, filter, map, zip) import os import sys -import ProgramName + +from . import ProgramName # Process command line name=ProgramName.get(); diff --git a/parse-stan.py b/parse-stan.py index be450a6..f048562 100755 --- a/parse-stan.py +++ b/parse-stan.py @@ -4,15 +4,10 @@ # License (GPL) version 3, as described at www.opensource.org. # Author: William H. Majoros (bmajoros@alumni.duke.edu) #========================================================================= -from __future__ import (absolute_import, division, print_function, - unicode_literals, generators, nested_scopes, with_statement) -from builtins import (bytes, dict, int, list, object, range, str, ascii, - chr, hex, input, next, oct, open, pow, round, super, filter, map, zip) -# The above imports should allow this program to run in both Python 2 and -# Python 3. You might need to update your version of module "future". import sys -import ProgramName -from StanParser import StanParser + +from . import ProgramName +from .StanParser import StanParser #========================================================================= # main() @@ -35,6 +30,6 @@ line=[] for sample in samplesByVar: line.append(str(sample[i])) print("\t".join(line)) - + diff --git a/parse-vcf.py b/parse-vcf.py index 1c556ca..3c429f2 100755 --- a/parse-vcf.py +++ b/parse-vcf.py @@ -4,15 +4,8 @@ # License (GPL) version 3, as described at www.opensource.org. # Author: William H. Majoros (bmajoros@alumni.duke.edu) #========================================================================= -from __future__ import (absolute_import, division, print_function, - unicode_literals, generators, nested_scopes, with_statement) -from builtins import (bytes, dict, int, list, object, range, str, ascii, - chr, hex, input, next, oct, open, pow, round, super, filter, map, zip) -# The above imports should allow this program to run in both Python 2 and -# Python 3. You might need to update your version of module "future". -import sys -import os import gzip +import sys if(len(sys.argv)!=3): print(sys.argv[0]+" ") diff --git a/popstar-step1.py b/popstar-step1.py index d61954f..211748a 100755 --- a/popstar-step1.py +++ b/popstar-step1.py @@ -1,10 +1,7 @@ #!/usr/bin/env python -import sys -import os import distutils -from distutils.spawn import find_executable -import subprocess -import basic +import os +import sys name=sys.argv[0]; diff --git a/popstar-step2.py b/popstar-step2.py index 85f895b..e2c8d69 100755 --- a/popstar-step2.py +++ b/popstar-step2.py @@ -1,10 +1,6 @@ #!/usr/bin/env python -import sys import os -import distutils -from distutils.spawn import find_executable -import subprocess -import basic +import sys name=sys.argv[0]; diff --git a/random-dna.py b/random-dna.py index 2efc564..96970db 100755 --- a/random-dna.py +++ b/random-dna.py @@ -4,14 +4,11 @@ # License (GPL) version 3, as described at www.opensource.org. # Copyright (C)2016 William H. Majoros (martiandna@gmail.com). #========================================================================= -from __future__ import (absolute_import, division, print_function, - unicode_literals, generators, nested_scopes, with_statement) -from builtins import (bytes, dict, int, list, object, range, str, ascii, - chr, hex, input, next, oct, open, pow, round, super, filter, map, zip) import random -import ProgramName import sys -from FastaWriter import FastaWriter + +from . import ProgramName +from .FastaWriter import FastaWriter if(len(sys.argv)!=3): exit(ProgramName.get()+" ") diff --git a/rank-variants.py b/rank-variants.py index 6e764f3..a25d015 100755 --- a/rank-variants.py +++ b/rank-variants.py @@ -1,7 +1,6 @@ #!/usr/bin/env python -import sys -import os import operator +import sys if(len(sys.argv)!=2): print sys.argv[0]+" " diff --git a/reverse.py b/reverse.py index faf9454..4194f84 100755 --- a/reverse.py +++ b/reverse.py @@ -4,14 +4,11 @@ # License (GPL) version 3, as described at www.opensource.org. # Author: William H. Majoros (bmajoros@alumni.duke.edu) #========================================================================= -from __future__ import (absolute_import, division, print_function, - unicode_literals, generators, nested_scopes, with_statement) -from builtins import (bytes, dict, int, list, object, range, str, ascii, - chr, hex, input, next, oct, open, pow, round, super, filter, map, zip) # The above imports should allow this program to run in both Python 2 and # Python 3. You might need to update your version of module "future". import sys -import ProgramName + +from . import ProgramName #========================================================================= # main() diff --git a/sort-matrixmarket.py b/sort-matrixmarket.py index d1a948f..15c05d4 100755 --- a/sort-matrixmarket.py +++ b/sort-matrixmarket.py @@ -4,17 +4,11 @@ # License (GPL) version 3, as described at www.opensource.org. # Author: William H. Majoros (bmajoros@alumni.duke.edu) #========================================================================= -from __future__ import (absolute_import, division, print_function, - unicode_literals, generators, nested_scopes, with_statement) -from builtins import (bytes, dict, int, list, object, range, str, ascii, - chr, hex, input, next, oct, open, pow, round, super, filter, map, zip) -# The above imports should allow this program to run in both Python 2 and -# Python 3. You might need to update your version of module "future". -import sys -import ProgramName import gzip -from Pipe import Pipe -import TempFilename +import sys + +from . import ProgramName, TempFilename +from .Pipe import Pipe HEADERFILE=TempFilename.generate(".header") SORTEDFILE=TempFilename.generate(".sorted") @@ -31,10 +25,10 @@ with gzip.open(infile,"rt") as IN: for line in IN: if(len(line)==0): raise Exception("unexpected empty line") - if(line[0]=="%"): + if(line[0]=="%"): numHeader+=1 print(line,file=OUT,end="") - else: + else: print(line,file=OUT,end="") break IN.close(); OUT.close() diff --git a/summarize-stan.py b/summarize-stan.py index b915631..5769a7c 100755 --- a/summarize-stan.py +++ b/summarize-stan.py @@ -4,15 +4,10 @@ # License (GPL) version 3, as described at www.opensource.org. # Author: William H. Majoros (bmajoros@alumni.duke.edu) #========================================================================= -from __future__ import (absolute_import, division, print_function, - unicode_literals, generators, nested_scopes, with_statement) -from builtins import (bytes, dict, int, list, object, range, str, ascii, - chr, hex, input, next, oct, open, pow, round, super, filter, map, zip) -# The above imports should allow this program to run in both Python 2 and -# Python 3. You might need to update your version of module "future". import sys -import ProgramName -from StanParser import StanParser + +from . import ProgramName +from .StanParser import StanParser #========================================================================= # main() diff --git a/template.py b/template.py index 7f4b235..aefaa8f 100755 --- a/template.py +++ b/template.py @@ -2,14 +2,9 @@ #========================================================================= # Copyright (C)William H. Majoros (bmajoros@alumni.duke.edu) #========================================================================= -from __future__ import (absolute_import, division, print_function, - unicode_literals, generators, nested_scopes, with_statement) -from builtins import (bytes, dict, int, list, object, range, str, ascii, - chr, hex, input, next, oct, open, pow, round, super, filter, map, zip) -# The above imports should allow this program to run in both Python 2 and -# Python 3. You might need to update your version of module "future". import sys -import ProgramName + +from . import ProgramName #========================================================================= # main() diff --git a/test-bed.py b/test-bed.py index a9b0d1e..4890022 100755 --- a/test-bed.py +++ b/test-bed.py @@ -4,11 +4,7 @@ # License (GPL) version 3, as described at www.opensource.org. # Copyright (C)2016 William H. Majoros (martiandna@gmail.com). #========================================================================= -from __future__ import (absolute_import, division, print_function, - unicode_literals, generators, nested_scopes, with_statement) -from builtins import (bytes, dict, int, list, object, range, str, ascii, - chr, hex, input, next, oct, open, pow, round, super, filter, map, zip) -from BedReader import BedReader +from .BedReader import BedReader BASE="/Users/bmajoros/python/test/data" filename=BASE+"/DEGs_downreg.FDR_0.1.TSS.protein_coding.bed" diff --git a/test-essex.py b/test-essex.py index da66f7c..8b17443 100755 --- a/test-essex.py +++ b/test-essex.py @@ -4,13 +4,10 @@ # License (GPL) version 3, as described at www.opensource.org. # Copyright (C)2016 William H. Majoros (martiandna@gmail.com). #========================================================================= -from __future__ import (absolute_import, division, print_function, - unicode_literals, generators, nested_scopes, with_statement) -from builtins import (bytes, dict, int, list, object, range, str, ascii, - chr, hex, input, next, oct, open, pow, round, super, filter, map, zip) -from EssexParser import EssexParser import sys +from .EssexParser import EssexParser + BASE="/Users/bmajoros/python/test/data" filename=BASE+"/HG00096-1-subset.essex" parser=EssexParser(filename) diff --git a/test-fasta-reader.py b/test-fasta-reader.py index a47d9cb..098b9ea 100755 --- a/test-fasta-reader.py +++ b/test-fasta-reader.py @@ -4,13 +4,9 @@ # License (GPL) version 3, as described at www.opensource.org. # Copyright (C)2016 William H. Majoros (martiandna@gmail.com). #========================================================================= -from __future__ import (absolute_import, division, print_function, - unicode_literals, generators, nested_scopes, with_statement) -from builtins import (bytes, dict, int, list, object, range, str, ascii, - chr, hex, input, next, oct, open, pow, round, super, filter, map, zip) -from FastaReader import FastaReader -from FastaWriter import FastaWriter -from Translation import Translation +from .FastaReader import FastaReader +from .FastaWriter import FastaWriter +from .Translation import Translation #filename="/home/bmajoros/1000G/assembly/combined/HG00096/1.fasta" diff --git a/test-fastb.py b/test-fastb.py index 751f1b2..3d87b20 100755 --- a/test-fastb.py +++ b/test-fastb.py @@ -4,13 +4,10 @@ # License (GPL) version 3, as described at www.opensource.org. # Copyright (C)2016 William H. Majoros (martiandna@gmail.com). #========================================================================= -from __future__ import (absolute_import, division, print_function, - unicode_literals, generators, nested_scopes, with_statement) -from builtins import (bytes, dict, int, list, object, range, str, ascii, - chr, hex, input, next, oct, open, pow, round, super, filter, map, zip) -from Fastb import Fastb import copy +from .Fastb import Fastb + BASE="/Users/bmajoros/python/test/data" #filename=BASE+"/iter0_peak1858.standardized_across_all_timepoints.t05.fastb" filename=BASE+"/test.fastb" diff --git a/test-pipe.py b/test-pipe.py index 0935786..fbd1ea4 100755 --- a/test-pipe.py +++ b/test-pipe.py @@ -4,13 +4,8 @@ # License (GPL) version 3, as described at www.opensource.org. # Copyright (C)2016 William H. Majoros (martiandna@gmail.com). #========================================================================= -from __future__ import (absolute_import, division, print_function, - unicode_literals, generators, nested_scopes, with_statement) -from builtins import (bytes, dict, int, list, object, range, str, ascii, - chr, hex, input, next, oct, open, pow, round, super, filter, map, zip) -# The above imports should allow this program to run in both Python 2 and -# Python 3. You might need to update your version of module "future". -from Pipe import Pipe +from .Pipe import Pipe + #import subprocess #import sys diff --git a/test-transcript-reader.py b/test-transcript-reader.py index d53b91a..4e5f0a2 100755 --- a/test-transcript-reader.py +++ b/test-transcript-reader.py @@ -4,13 +4,7 @@ # License (GPL) version 3, as described at www.opensource.org. # Copyright (C)2016 William H. Majoros (martiandna@gmail.com). #========================================================================= -from __future__ import (absolute_import, division, print_function, - unicode_literals, generators, nested_scopes, with_statement) -from builtins import (bytes, dict, int, list, object, range, str, ascii, - chr, hex, input, next, oct, open, pow, round, super, filter, map, zip) -# The above imports should allow this program to run in both Python 2 and -# Python 3. You might need to update your version of module "future". -from GffTranscriptReader import GffTranscriptReader +from .GffTranscriptReader import GffTranscriptReader #filename="/home/bmajoros/1000G/assembly/local-genes.gff" #filename="/home/bmajoros/1000G/assembly/tmp.gff" @@ -35,7 +29,7 @@ #print(transcript.getID()) #gff=transcript.toGff() #print(gff) - + #genes=reader.loadGenes(filename) #for gene in genes: # print("gene",gene.getID())