This repository was archived by the owner on Aug 22, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 48
supported to run ROSE2 in python3 environment #67
Open
gauravj49
wants to merge
3
commits into
BradnerLab:master
Choose a base branch
from
gauravj49:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -40,7 +40,7 @@ | |
|
|
||
| import os | ||
| import subprocess | ||
| from string import join | ||
| # from string import join | ||
|
|
||
| from collections import defaultdict | ||
|
|
||
|
|
@@ -189,14 +189,14 @@ def mapEnhancerToGene(annotFile,enhancerFile,transcribedFile='',uniqueGenes=True | |
| if noFormatTable: | ||
|
|
||
| newEnhancerLine = list(line) | ||
| newEnhancerLine.append(join(utils.uniquify([startDict[x]['name'] for x in overlappingGenes]),',')) | ||
| newEnhancerLine.append(join(utils.uniquify([startDict[x]['name'] for x in proximalGenes]),',')) | ||
| newEnhancerLine.append(','.join(utils.uniquify([startDict[x]['name'] for x in overlappingGenes]))) | ||
| newEnhancerLine.append(','.join(utils.uniquify([startDict[x]['name'] for x in proximalGenes]))) | ||
| newEnhancerLine.append(closestGene) | ||
|
|
||
| else: | ||
| newEnhancerLine = line[0:9] | ||
| newEnhancerLine.append(join(utils.uniquify([startDict[x]['name'] for x in overlappingGenes]),',')) | ||
| newEnhancerLine.append(join(utils.uniquify([startDict[x]['name'] for x in proximalGenes]),',')) | ||
| newEnhancerLine.append(','.join(utils.uniquify([startDict[x]['name'] for x in overlappingGenes]))) | ||
| newEnhancerLine.append(','.join(utils.uniquify([startDict[x]['name'] for x in proximalGenes]))) | ||
| newEnhancerLine.append(closestGene) | ||
| newEnhancerLine += line[-2:] | ||
|
|
||
|
|
@@ -238,9 +238,9 @@ def mapEnhancerToGene(annotFile,enhancerFile,transcribedFile='',uniqueGenes=True | |
| proxEnhancers = geneDict['overlapping'][refID]+geneDict['proximal'][refID] | ||
|
|
||
| superStatus = max(superDict[refID]) | ||
| enhancerRanks = join([str(x) for x in rankDict[refID]],',') | ||
| enhancerRanks = ','.join([str(x) for x in rankDict[refID]]) | ||
|
|
||
| newLine = [geneName,refID,join(proxEnhancers,','),enhancerRanks,superStatus] | ||
| newLine = [geneName,refID,','.join(proxEnhancers),enhancerRanks,superStatus] | ||
| geneToEnhancerTable.append(newLine) | ||
|
|
||
| #resort enhancerToGeneTable | ||
|
|
@@ -320,8 +320,7 @@ def mapEnhancerToGeneTop(rankByBamFile, controlBamFile, genome, annotFile, enhan | |
| # matter | ||
| tssCollection = utils.LocusCollection(tssLoci, 50) | ||
|
|
||
| geneDict = {'overlapping': defaultdict( | ||
| list), 'proximal': defaultdict(list)} | ||
| geneDict = {'overlapping': defaultdict(list), 'proximal': defaultdict(list)} | ||
|
|
||
| # dictionaries to hold ranks and superstatus of gene nearby enhancers | ||
| rankDict = defaultdict(list) | ||
|
|
@@ -347,16 +346,13 @@ def mapEnhancerToGeneTop(rankByBamFile, controlBamFile, genome, annotFile, enhan | |
| else: | ||
| # set up the output tables | ||
| # first by enhancer | ||
| enhancerToGeneTable = [ | ||
| header[0:9] + ['OVERLAP_GENES', 'PROXIMAL_GENES', 'CLOSEST_GENE'] + header[-2:]] | ||
| enhancerToGeneTable = [header[0:9] + ['OVERLAP_GENES', 'PROXIMAL_GENES', 'CLOSEST_GENE'] + header[-2:]] | ||
|
|
||
| # next by gene | ||
| geneToEnhancerTable = [ | ||
| ['GENE_NAME', 'REFSEQ_ID', 'PROXIMAL_ENHANCERS']] | ||
| geneToEnhancerTable = [['GENE_NAME', 'REFSEQ_ID', 'PROXIMAL_ENHANCERS']] | ||
|
|
||
| # next make the gene to enhancer table | ||
| geneToEnhancerTable = [ | ||
| ['GENE_NAME', 'REFSEQ_ID', 'PROXIMAL_ENHANCERS', 'ENHANCER_RANKS', 'IS_SUPER', 'ENHANCER_SIGNAL']] | ||
| geneToEnhancerTable = [['GENE_NAME', 'REFSEQ_ID', 'PROXIMAL_ENHANCERS', 'ENHANCER_RANKS', 'IS_SUPER', 'ENHANCER_SIGNAL']] | ||
|
|
||
| for line in enhancerTable: | ||
| if line[0][0] == '#' or line[0][0] == 'R': | ||
|
|
@@ -405,35 +401,38 @@ def mapEnhancerToGeneTop(rankByBamFile, controlBamFile, genome, annotFile, enhan | |
| distalGenes.remove(refID) | ||
|
|
||
| # Now find the closest gene | ||
| closestGene = '' | ||
| if len(allEnhancerGenes) == 0: | ||
| closestGene = '' | ||
| else: | ||
| # get enhancerCenter | ||
| enhancerCenter = (int(line[2]) + int(line[3])) / 2 | ||
|
|
||
| # get absolute distance to enhancer center | ||
| distList = [abs(enhancerCenter - startDict[geneID]['start'][0]) | ||
| for geneID in allEnhancerGenes] | ||
| # get the ID and convert to name | ||
| closestGene = startDict[ | ||
| allEnhancerGenes[distList.index(min(distList))]]['name'] | ||
| try: | ||
| # get absolute distance to enhancer center | ||
| distList = [abs(enhancerCenter - list(startDict[geneID]['start'])[0]) for geneID in allEnhancerGenes] | ||
|
|
||
| # get the ID and convert to name | ||
| closestGene = startDict[allEnhancerGenes[distList.index(min(distList))]]['name'] | ||
| except: | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do you want this to fail silently? Or give some meaningful message to the user? Or catch a specific kind of error that you expect? |
||
| pass | ||
|
|
||
| # NOW WRITE THE ROW FOR THE ENHANCER TABLE | ||
| if noFormatTable: | ||
|
|
||
| newEnhancerLine = list(line) | ||
| newEnhancerLine.append( | ||
| join(utils.uniquify([startDict[x]['name'] for x in overlappingGenes]), ',')) | ||
| ','.join(utils.uniquify([startDict[x]['name'] for x in overlappingGenes]))) | ||
| newEnhancerLine.append( | ||
| join(utils.uniquify([startDict[x]['name'] for x in proximalGenes]), ',')) | ||
| ','.join(utils.uniquify([startDict[x]['name'] for x in proximalGenes]))) | ||
| newEnhancerLine.append(closestGene) | ||
|
|
||
| else: | ||
| newEnhancerLine = line[0:9] | ||
| newEnhancerLine.append( | ||
| join(utils.uniquify([startDict[x]['name'] for x in overlappingGenes]), ',')) | ||
| ','.join(utils.uniquify([startDict[x]['name'] for x in overlappingGenes]))) | ||
| newEnhancerLine.append( | ||
| join(utils.uniquify([startDict[x]['name'] for x in proximalGenes]), ',')) | ||
| ','.join(utils.uniquify([startDict[x]['name'] for x in proximalGenes]))) | ||
| newEnhancerLine.append(closestGene) | ||
| newEnhancerLine += line[-2:] | ||
|
|
||
|
|
@@ -460,14 +459,15 @@ def mapEnhancerToGeneTop(rankByBamFile, controlBamFile, genome, annotFile, enhan | |
|
|
||
| #get the chromLists from the various bams here | ||
| cmd = 'samtools idxstats %s' % (rankByBamFile) | ||
| idxStats = subprocess.Popen(cmd,stdout=subprocess.PIPE,shell=True) | ||
| idxStats= idxStats.communicate() | ||
| bamChromList = [line.split('\t')[0] for line in idxStats[0].split('\n')[0:-2]] | ||
| idxStats = subprocess.Popen(cmd, stdout=subprocess.PIPE, shell=True, | ||
| universal_newlines=True).communicate()[0] | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Generally it's not good practice to use shell=True, but probably for a small scientific pipeline this would be okay. Here is an example of not using shell=True: https://github.com/HPC-buildtest/buildtest-framework/blob/devel/buildtest/utils/command.py#L55 |
||
|
|
||
| bamChromList = [bytes(line.split('\t')[0]) for line in idxStats[0].split('\n')[0:-2]] | ||
|
|
||
| if len(controlBamFile) > 0: | ||
| cmd = 'samtools idxstats %s' % (controlBamFile) | ||
| idxStats = subprocess.Popen(cmd,stdout=subprocess.PIPE,shell=True) | ||
| idxStats= idxStats.communicate() | ||
| idxStats = idxStats.communicate() | ||
| bamChromListControl = [line.split('\t')[0] for line in idxStats[0].split('\n')[0:-2]] | ||
| bamChromList = [chrom for chrom in bamChromList if bamChromListControl.count(chrom) != 0] | ||
|
|
||
|
|
@@ -572,13 +572,12 @@ def mapEnhancerToGeneTop(rankByBamFile, controlBamFile, genome, annotFile, enhan | |
| refID] + geneDict['proximal'][refID] | ||
|
|
||
| superStatus = max(superDict[refID]) | ||
| enhancerRanks = join([str(x) for x in rankDict[refID]], ',') | ||
| enhancerRanks = ','.join([str(x) for x in rankDict[refID]]) | ||
|
|
||
| enhancerSignal = signalDict[refID] | ||
| geneNameSigDict[geneName].append(enhancerSignal) | ||
|
|
||
| newLine = [geneName, refID, join( | ||
| proxEnhancers, ','), enhancerRanks, superStatus, enhancerSignal] | ||
| newLine = [geneName, refID, ','.join(proxEnhancers), enhancerRanks, superStatus, enhancerSignal] | ||
| geneToEnhancerTable.append(newLine) | ||
| #utils.unParseTable(geneToEnhancerTable,'/grail/projects/newRose/geneMapper/foo.txt','\t') | ||
| print('MAKING ENHANCER TO TOP GENE TABLE') | ||
|
|
@@ -711,7 +710,7 @@ def main(): | |
| if options.out: | ||
| outFolder = utils.formatFolder(options.out, True) | ||
| else: | ||
| outFolder = join(enhancerFile.split('/')[0:-1], '/') + '/' | ||
| outFolder = '/'.join(enhancerFile.split('/')[0:-1]) + '/' | ||
|
|
||
| # GETTING BAM INFO | ||
| rankByBamFile = options.rankby | ||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please delete code instead of commenting it out.