diff --git a/annofeat.py b/annofeat.py index f383d55..cc1318d 100644 --- a/annofeat.py +++ b/annofeat.py @@ -18,19 +18,23 @@ parser.add_argument("reference", help="Reference filename", type=argparse.FileType('r')) parser.add_argument("output", help="Output filename", type=argparse.FileType('w')) # Optional -parser.add_argument("-m","--margin", help="Basepair margin to include", nargs=1, type=int) +parser.add_argument("-m","--margin", help="Margin to include in basepairs [use with -o]", nargs=1, type=int) parser.add_argument("-a","--all", help="List all features", action="store_true") -parser.add_argument("-t","--title", help="Column title", action="store") -parser.add_argument("-c","--closest", help="List closest features regardless of distance", action="store_true") +parser.add_argument("-t","--title", help="Column title [use with -o]", action="store") +parser.add_argument("-o","--overlap", help="Only examine overlapping region", action="store_true") parser.add_argument("-s","--sense", help="Order closest items by sense and antisense", action="store_true") +parser.add_argument("-f","--features", help="Features to include when look for closest feature", action="store") # Any commands entered without a flag args = parser.parse_args() # Setup variables: +features=['exon','transcript'] + all = 0 if args.all: all = 1 + features=[] margin = 0 if args.margin: @@ -40,22 +44,26 @@ if args.title: title = args.title -useclosest = 0 -if args.closest: - useclosest = 1 +useoverlap = 0 +if args.overlap: + useoverlap = 1 usesense = 0 if args.sense: usesense = 1 +if args.features: + features=args.features.split(',') + # Run the command print("Indexing reference file") trackobj = libAnnoShared.loadTrackFile(args.reference) -if useclosest: - libAnnoFeat.featureClosestAddColumn(args.query,trackobj,args.output,usesense, all) -else: - print("Processing annotations *This may take some time*") +print("Processing annotations *This may take some time if used with large unsorted files*") +if useoverlap: libAnnoFeat.featureOverlappingAddColumn(args.query,trackobj,args.output,margin,title,all) +else: + libAnnoFeat.featureClosestAddColumn(args.query,trackobj,args.output,usesense, all, features) + # Close files args.query.close() diff --git a/lib/libAnnoAtlas.py b/lib/libAnnoAtlas.py index c11ebb7..7f89083 100644 --- a/lib/libAnnoAtlas.py +++ b/lib/libAnnoAtlas.py @@ -8,6 +8,8 @@ EmptyChar = "." # Character to use for empty fields +# TODO: Additional error checking to return an error message if an out of range column number is used + # Creates a class for addressing Human Protein Atlas files # Usage example: #atlasobj = atlas(open('atlasfilename')) diff --git a/lib/libAnnoFeat.py b/lib/libAnnoFeat.py index afe024a..233be4e 100644 --- a/lib/libAnnoFeat.py +++ b/lib/libAnnoFeat.py @@ -244,7 +244,7 @@ def featureOverlappingAddColumn(annofileobj, reftrackobj, outfileobj, margin=0, # Simple usage example: #trackobj = libAnnoShared.loadTrackFile(open("RefFilename.gtf")) # Load the files into a track object #featureClosestAddColumn(open('queryfile.bed'), trackobj, open('output.tsv','w')) # Outputs a file with additional columns on nearby features -def featureClosestAddColumn(annofileobj, reftrackobj, outfileobj, senseorder=0, returnall=0): +def featureClosestAddColumn(annofileobj, reftrackobj, outfileobj, senseorder=0, returnall=0, features=[]): """Adds a column detailing the feature in a region""" type = libAnnoShared.detectFileType(annofileobj) annofileobj.seek(0) @@ -274,7 +274,7 @@ def featureClosestAddColumn(annofileobj, reftrackobj, outfileobj, senseorder=0, if annoObj.alignStart0: + lineout = linestore.pop(random.randrange(len(linestore))) + outputobj.write(lineout) +outputobj.close() + +# Display the status of the unsorted file +print("Unsorted file status:") +command = "python3 ../annosort.py sortedfiles/"+unsortedfile+" -s" +subprocess.call(command, shell=True) + +# Sort the unsorted file +print("Sorting file") +command = "python3 ../annosort.py sortedfiles/"+unsortedfile+" -o sortedfiles/"+sortedfile +subprocess.call(command, shell=True) + +# Display the status of the sorted file +print("Sorted file status:") +command = "python3 ../annosort.py sortedfiles/"+sortedfile+" -s" +subprocess.call(command, shell=True)