Example #1
0
    def runTest(self):
        outdir = '/tmp/gMiner/'
        if not os.path.exists(outdir): os.mkdir(outdir)

        # Cross-correlation #
        files = run(
           track1          = track_collections['Scores'][1]['path_sql'],
           track1_name     = 'Scores 1',
           track1_chrs     = small_chr_file,
           track2          = track_collections['Scores'][2]['path_sql'],
           track2_name     = 'Scores 2',
           track2_chrs     = small_chr_file,
           operation_type  = 'plot',
           plot            = 'correlation',
           output_location = outdir,
        )

        # Scatter plot #
        files = run(
           track1          = track_collections['Scores'][1]['path_sql'],
           track1_name     = 'Scores 1',
           track1_chrs     = small_chr_file,
           track2          = track_collections['Scores'][2]['path_sql'],
           track2_name     = 'Scores 2',
           track2_chrs     = small_chr_file,
           track3          = track_collections['Validation'][1]['path_sql'],
           track3_name     = 'Features 1',
           track3_chrs     = small_chr_file,
           operation_type  = 'plot',
           plot            = 'scatter',
           output_location = outdir,
        )
Example #2
0
    def runTest(self):
        outdir = '/tmp/gMiner/'
        if not os.path.exists(outdir): os.mkdir(outdir)

        # Simple boxplot #
        files = run(
           track1          = track_collections['Yeast']['All genes']['path_sql'],
           track1_name     = 'All genes from SGD',
           track2          = track_collections['Yeast']['Ribi genes']['path_sql'],
           track2_name     = 'Ribosome genesis',
           track3          = track_collections['Yeast']['RP genes']['path_sql'],
           track3_name     = 'Ribosome proteins',
           operation_type  = 'desc_stat',
           characteristic  = 'length',
           output_location = outdir,
        )

        # Track selection #
        files = run(
           track1           = track_collections['Validation'][2]['path_sql'],
           track1_name      = 'Validation track two',
           operation_type   = 'desc_stat',
           characteristic   = 'base_coverage',
           selected_regions = track_collections['Validation'][3]['path_sql'],
           per_chromosome   = True,
           compare_parents  = True,
           output_location  = outdir,
        )
        # Result should be 120 / 150 or 80%

        # Field test via filter #
        files = run(
           track1           = track_collections['Yeast']['All genes']['path_sql'],
           track1_name      = 'S. cer refseq genes',
           track2           = track_collections['Yeast']['RP genes']['path_sql'],
           track2_name      = 'RP genes',
           operation_type   = 'desc_stat',
           characteristic   = 'number_of_features',
           selected_regions = track_collections['Yeast']['Ribi genes']['path_sql'],
           per_chromosome   = True,
           compare_parents  = False,
           output_location  = outdir,
        )

        # Permission test #
        if os.path.exists('/scratch/genomic/tracks/locked.sql'):
            files = run(
               track1           = '/scratch/genomic/tracks/locked.sql',
               track1_name      = 'Permission test',
               selected_regions = '/scratch/genomic/tracks/locked.sql',
               operation_type   = 'desc_stat',
               characteristic   = 'number_of_features',
               output_location  = outdir,
            )
Example #3
0
def generate(result_path='/tmp/gMiner/'):
    if not os.path.isdir(result_path):
        raise Exception("The result location specified is not a directory")
    max_count = 2*2*2*2*4
    max_count -= max_count/4
    max_count *= len(collections)
    count = 1
    print gm_terminal_colors['bldylw'] + "    Writing graphs in: " + result_path + gm_terminal_colors['end']
    for col_name, col in collections.items():
        for b_many in [True, False]:
            for b_sel in [True, False]:
                for b_comp in [True, False]:
                    for b_chr in [True, False]:
                        for chara in chara_dict.keys():
                            # Preparation #
                            if not b_sel and b_comp: continue
                            name = col_name + '_'
                            name = name + name_dict[b_comp][b_chr][b_many]
                            name = name + chara_dict[chara]
                            if not b_sel: name += '_NoSel'
                            print gm_terminal_colors['txtylw'] + "Graph " + str(count) + " out of " + str(max_count) + \
                            "   " + gm_terminal_colors['txtpur'] + name + gm_terminal_colors['end']
                            count += 1
                            # Making the request #
                            request = {}
                            request['gm_encoding'] = 'image/png'
                            request['operation_type'] = 'desc_stat'
                            request['characteristic'] = chara
                            request['output_location'] = result_path
                            request['output_name'] = name
                            if b_many:
                                request['track1'] = col['track_set']['many'][1]['path_sql']
                                request['track1_name'] = col['track_name_fn'](col['track_set']['many'][1]['name'])
                                request['track2'] = col['track_set']['many'][2]['path_sql']
                                request['track2_name'] = col['track_name_fn'](col['track_set']['many'][2]['name'])
                                request['track3'] = col['track_set']['many'][3]['path_sql']
                                request['track3_name'] = col['track_name_fn'](col['track_set']['many'][3]['name'])
                            else:
                                request['track1'] = col['track_set']['single']['path_sql']
                                request['track1_name'] = col['track_name_fn'](col['track_set']['single']['name'])
                            if b_sel:
                                request['selected_regions'] = col['request_selection_string']
                            if b_chr:
                                request['per_chromosome'] = 'True'
                            if b_comp:
                                request['compare_parents'] = 'True'
                            # Executing the request #
                            run(**request)
Example #4
0
 def runTest(self):
     path = track_collections['Validation'][1]['path']
     files = run(
        track1           = path,
        track1_name      = 'Validation track one',
        operation_type   = 'genomic_manip',
        manipulation     = 'merge',
        output_location  = tempfile.gettempdir(),
     )
     os.remove(files[0])
Example #5
0
 def runTest(self):
     sql_path = track_collections['Validation'][2]['path_sql']
     bed_path = track_collections['Validation'][2]['path']
     files = run(
        track1           = bed_path,
        track1_name      = 'Validation track two',
        track1_chrs      = yeast_chr_file,
        operation_type   = 'genomic_manip',
        manipulation     = 'bool_not',
        output_location  = tempfile.gettempdir(),
     )
     with load(sql_path, chrmeta=yeast_chr_file, readonly=True) as sql:
         with load(files[0]) as bed:
             self.assertEqual(sql.chrmeta, bed.chrmeta)
     os.remove(files[0])
Example #6
0
def main(argv = None):
    if argv is None:
        argv = sys.argv[1:]
    try:
        if len(argv) != 1:
            raise Usage("run_gminer.py takes exactly 1 argument.")
        pickle_file = argv[0]
        with open(pickle_file,'r') as f:
            job = pickle.load(f)
        job['job_output'] = gMiner.run(**job)
        with open(pickle_file,'w') as f:
            pickle.dump(job,f)
        sys.exit(0)
    except Usage, err:
        print >>sys.stderr, err.msg
        print >>sys.stderr, usage
        sys.exit(2)
Example #7
0
def post_process(**kwargs):
    try:
        # Get a job from the list #
        global jobs
        job = jobs.pop(0)
        # Load the form #
        request = json.loads(job['data'])
        # Get the output location #
        request['output_location'] = job.pop('output_location')
        # Format the request #
        if request.has_key('compare_parents' ): request['compare_parents' ] = bool(request['compare_parents'  ])
        if request.has_key('per_chromosome'  ): request['per_chromosome'  ] = bool(request['per_chromosome'   ])
        if request.has_key('filter'):
            request['selected_regions'] = request['filter'][0]['path']
            request.pop('filter')
        if request.has_key('ntracks'):
            request.update(dict([('track' + str(i+1), v['path'])                         for i,v in enumerate(request['ntracks'])]))
            request.update(dict([('track' + str(i+1) + '_name', v.get('name', 'Unamed')) for i,v in enumerate(request['ntracks'])]))
            request.pop('ntracks')
        # Unicode filtering #
        request = dict([(k.encode('ascii'),v) for k,v in request.items()])
        # Run the request #
        files = gMiner.run(**request)
        # Format the output #
        result = {'files': [dict([('path',p),('type',p.split('.')[-1])]) for p in files]}
        # Report success #
        print '\033[1;33m[' + time.asctime() + ']\033[0m \033[42m' + files[0] + '\033[0m'
    except Exception as err:
        traceback.print_exc()
        print '\033[1;33m[' + time.asctime() + ']\033[0m \033[41m' + str(err) + '\033[0m'
        with warnings.catch_warnings():
            warnings.simplefilter("ignore")
            result = {'type':'error', 'html':cgitb.html(sys.exc_info()), 'msg': str(err)}
    finally:
        result     = locals().get('result', '')
        connection = httplib2.Http()
        body       = urllib.urlencode({'id':'job', 'action':'gfeatresponse', 'job_id':job.get('job_id', -1), 'data':json.dumps(result)})
        headers    = {'content-type': 'application/x-www-form-urlencoded'}
        address    = job['callback_url']
        response, content = connection.request(address, "POST", body=body, headers=headers)
Example #8
0
File: 3.py Project: hjanime/gMiner
import gMiner
files = gMiner.run(
    track1             = '/scratch/genomic/tracks/ribosome_proteins.sql',
    track1_name        = 'RP genes (SGD)',
    track2             = '/scratch/genomic/tracks/ribosome_genesis.sql',
    track2_name        = 'Ribi genes (SGD)',
    operation_type     = 'desc_stat',
    characteristic     = 'base_coverage',
    selected_regions   = 'chr2:0:300000;chr5:0:200000',
    compare_parents    = 'False',
    per_chromosome     = 'True',
    wanted_chromosomes = 'chr1;chr2;chr5;chr6;chr7;chr8;chr9;chr10;chr11;chr12;' + \
                         'chr13;chr14;chr15;chr16;chr17;chr18;chr19;chr20;chr21;' + \
                         'chr22;chrX;chrY',
    output_location    = '/tmp/',
)
Example #9
0
# Modules #
import sys, tempfile

# gMiner #
import gMiner
from gMiner.gm_constants import *

# Parser #
def parse_args(args):
    option = ''
    for arg in args:
        if arg.startswith("--"): option = arg[2:]
        else:
            if not option:
                print "Bad options"
                sys.exit()
            else:
                yield (option, arg)

# Make the request #
request = dict([(x[0], x[1]) for x in parse_args(sys.argv[1:])])

# Run it #
print gMiner.run(**request)
Example #10
0
File: 1.py Project: hjanime/gMiner
import gMiner
files = gMiner.run(
    track1          = '/scratch/genomic/tracks/all_yeast_genes.sql',
    track1_name     = 'S. cer. genes (SGD)',
    operation_type  = 'desc_stat',
    characteristic  = 'number_of_features',
    per_chromosome  = 'True',
    compare_parents = 'False',
    output_location = '/tmp/',
)
Example #11
0
def post_process(**kwargs):
    try:
        # Get a job from the list #
        global jobs
        job = jobs.pop(0)
        # Load the form #
        request = json.loads(job['data'])
        # Get the output location #
        request['output_location'] = job.pop('output_location')
        # Format the request #
        if request.has_key('compare_parents'):
            request['compare_parents'] = bool(request['compare_parents'])
        if request.has_key('per_chromosome'):
            request['per_chromosome'] = bool(request['per_chromosome'])
        if request.has_key('filter'):
            request['selected_regions'] = request['filter'][0]['path']
            request.pop('filter')
        if request.has_key('ntracks'):
            request.update(
                dict([('track' + str(i + 1), v['path'])
                      for i, v in enumerate(request['ntracks'])]))
            request.update(
                dict([('track' + str(i + 1) + '_name', v.get('name', 'Unamed'))
                      for i, v in enumerate(request['ntracks'])]))
            request.pop('ntracks')
        # Unicode filtering #
        request = dict([(k.encode('ascii'), v) for k, v in request.items()])
        # Run the request #
        files = gMiner.run(**request)
        # Format the output #
        result = {
            'files':
            [dict([('path', p), ('type', p.split('.')[-1])]) for p in files]
        }
        # Report success #
        print '\033[1;33m[' + time.asctime(
        ) + ']\033[0m \033[42m' + files[0] + '\033[0m'
    except Exception as err:
        traceback.print_exc()
        print '\033[1;33m[' + time.asctime() + ']\033[0m \033[41m' + str(
            err) + '\033[0m'
        with warnings.catch_warnings():
            warnings.simplefilter("ignore")
            result = {
                'type': 'error',
                'html': cgitb.html(sys.exc_info()),
                'msg': str(err)
            }
    finally:
        result = locals().get('result', '')
        connection = httplib2.Http()
        body = urllib.urlencode({
            'id': 'job',
            'action': 'gfeatresponse',
            'job_id': job.get('job_id', -1),
            'data': json.dumps(result)
        })
        headers = {'content-type': 'application/x-www-form-urlencoded'}
        address = job['callback_url']
        response, content = connection.request(address,
                                               "POST",
                                               body=body,
                                               headers=headers)
Example #12
0
def run_request(case, t):
    files = gMiner.run(**t['kwargs'])
    with track.load(files[0], chrmeta=yeast_chr_file) as x:
        data = list(x.read('chr1'))
    os.remove(files[0])
    case.assertEqual(data, t['expected'])
Example #13
0
File: 4.py Project: hjanime/gMiner
import gMiner
files = gMiner.run(
    track1          : '/scratch/genomic/tracks/refseq_ucsc.sql',
    track1_name     : 'hg19 refSeq genome-wide from UCSC',
    track2          : '/scratch/genomic/tracks/hiv_bushman.sql',
    track2_name     : 'hg19 HIV integration sites from liftOver',
    operation_type  : 'genomic_manip',
    manipulation    : 'overlap_track',
    output_location : '/tmp/gMiner/',
)
Example #14
0
File: 2.py Project: hjanime/gMiner
import gMiner
files = gMiner.run(
    track1          = '/scratch/genomic/tracks/refseq_ucsc.sql',
    track1_name     = 'hg19 refSeq genome-wide from UCSC',
    track2          = '/scratch/genomic/tracks/hiv_bushman.sql',
    track2_name     = 'hg19 HIV integration sites from liftOver',
    operation_type  = 'genomic_manip',
    manipulation    = 'overlap_track',
    output_location = '/tmp/',
)