コード例 #1
0
    def returnGeneDescLs(cls, gene_annotation, gene_id_ls=[]):
        """
		2009-6-22
			fix a bug. db_user and other variables are now accessible from config['app_conf'], not model.xxx
		"""
        DrawSNPRegion_ins = DrawSNPRegion(
            db_user=config["app_conf"]["db_user"],
            db_passwd=config["app_conf"]["db_passwd"],
            hostname=config["app_conf"]["hostname"],
            database=config["app_conf"]["dbname"],
            input_fname="/tmp/dumb",
            output_dir="/tmp",
            debug=0,
        )

        matrix_of_gene_descriptions = []
        for gene_id in gene_id_ls:
            gene_model = gene_annotation.gene_id2model.get(gene_id)
            if gene_model:
                if len(gene_model.gene_commentaries) == 0:
                    gene_commentaries = [gene_model]  # fake one here
                else:
                    gene_commentaries = gene_model.gene_commentaries
                for gene_commentary in gene_commentaries:
                    gene_desc_ls = DrawSNPRegion_ins.returnGeneDescLs(
                        DrawSNPRegion_ins.gene_desc_names, gene_model, gene_commentary
                    )
                    matrix_of_gene_descriptions.append(gene_desc_ls)
        return matrix_of_gene_descriptions
コード例 #2
0
 def dealWithGeneAnnotation():
     gene_annotation_picklef = "/Network/Data/250k/tmp-yh/at_gene_model_pickelf"
     DrawSNPRegion_ins = DrawSNPRegion(
         db_user=db_user,
         db_passwd=db_passwd,
         hostname=hostname,
         database=dbname,
         input_fname="/tmp/dumb",
         output_dir="/tmp",
         debug=0,
     )
     gene_annotation = DrawSNPRegion_ins.dealWithGeneAnnotation(
         gene_annotation_picklef, cls_with_db_args=DrawSNPRegion_ins
     )
     return gene_annotation
コード例 #3
0
	def getPlot(self):
		"""
		2010-1-22
			add argument call_method_id when calling DrawSNPRegion.drawRegionAroundThisSNP()
		2009-4-30
		"""
		chromosome = int(request.params.get('chromosome', 1))
		start = int(request.params.get('start', 1))
		stop = int(request.params.get('stop', 10))
		if start>stop:
			start, stop = stop, start
		snps_id = '%s_%s'%(chromosome, start)
		
		call_method_id = int(request.params.getone('call_method_id'))
		phenotype_method_id = int(request.params.getone('phenotype_method_id'))
		list_type_id = int(request.params.get('list_type_id', None))
		
		plot_key = (chromosome, start, stop, call_method_id, phenotype_method_id, list_type_id)
		
		if not hasattr(model, "plot_key2png_data"):
			model.plot_key2png_data = {}
		
		png_data = model.plot_key2png_data.get(plot_key)
		if png_data is not None:
			if hasattr(png_data, 'getvalue'):	# png_data is StringIO
				response.headers['Content-type'] = 'image/png'
				return png_data.getvalue()
			else:
				return png_data
		
		if not getattr(model, 'phenotype_id2analysis_method_id2gwr', None):
			model.phenotype_id2analysis_method_id2gwr = {}
		analysis_method_id2gwr = model.phenotype_id2analysis_method_id2gwr.get(phenotype_method_id)
		if not analysis_method_id2gwr:
			analysis_method_id2gwr = DrawSNPRegion.getSimilarGWResultsGivenResultsByGene(phenotype_method_id, call_method_id)
			model.phenotype_id2analysis_method_id2gwr[phenotype_method_id] = analysis_method_id2gwr
		
		if list_type_id>0:	#2009-2-22
			candidate_gene_set = GeneListRankTest.dealWithCandidateGeneList(list_type_id, return_set=True)
		else:
			candidate_gene_set = set()
		gene_annotation = model.gene_annotation
		
		snpData = hc.getSNPDataGivenCallMethodID(call_method_id)
		pheno_data = hc.getPhenotypeDataInSNPDataOrder(snpData)
	
		if h.ecotype_info is None:	#2009-3-6 not used right now
			h.ecotype_info = getEcotypeInfo(model.db)
		
		snp_info = getattr(model, 'snp_info', None)
		if snp_info is None:
			snp_info = DrawSNPRegion.getSNPInfo(model.db)
			model.snp_info = snp_info

		LD_info = None
		output_dir = '/tmp/'	#not used at all, place holder
		which_LD_statistic = 1
		this_snp = SNPPassingData(chromosome=chromosome, position=start, stop=stop, snps_id='%s_%s'%(chromosome, start))
		
		DrawSNPRegion.construct_chr_pos2index_forSNPData(snpData)	#prerequisite

		after_plot_data = DrawSNPRegion.drawRegionAroundThisSNP(phenotype_method_id, this_snp, candidate_gene_set, \
													gene_annotation, snp_info, \
								analysis_method_id2gwr, LD_info, output_dir, which_LD_statistic, \
								min_distance=20000, list_type_id=list_type_id,
								label_gene=True, \
								draw_LD_relative_to_center_SNP=False,\
								commit=True, snpData=snpData, phenData=pheno_data, \
								ecotype_info=h.ecotype_info, snpData_before_impute=None,\
								snp_matrix_data_type=1, call_method_id=call_method_id)
		
		if getattr(after_plot_data, 'png_data', None):
			response.headers['Content-type'] = 'image/png'
			model.plot_key2png_data[plot_key] = after_plot_data.png_data
			return after_plot_data.png_data.getvalue()
		else:
			model.plot_key2png_data[plot_key] = "No Plot"
			return model.plot_key2png_data[plot_key]
コード例 #4
0
#!/usr/bin/env python
"""
2008-10-01
        example to call DrawSNPRegion as an API
"""
import sys, os, math
sys.path.insert(0, os.path.expanduser('~/lib/python'))
sys.path.insert(0, os.path.join(os.path.expanduser('~/script')))
from variation.src.DrawSNPRegion import DrawSNPRegion

instance = DrawSNPRegion(db_user='******', db_passwd='', hostname='papaya.usc.edu', database='stock_250k', input_fname='/tmp/dumb', output_dir='/tmp', debug=0)
gene_annotation_picklef = '/Network/Data/250k/tmp-yh/at_gene_model_pickelf'
LD_info_picklef = '/Network/Data/250k/tmp-yh/call_method_17_LD_m0.2_n0.1_m40000'
#LD_info_picklef = None
LD_fname = '/Network/Data/250k/tmp-yh/call_method_17_LD_m0.2.tsv'	#optional
phenotype_method_id = 1
chromosome, start, stop  = 2, 9588685-40000, 9588685+40000
output_fname = '/tmp/SNP_2_9588685'
center_snp_position = 9588685
instance.drawSNPRegion(gene_annotation_picklef, LD_info_picklef, phenotype_method_id, chromosome, start, stop, \
		output_fname, center_snp_position=center_snp_position, LD_fname=LD_fname,\
                which_LD_statistic=2, call_method_id=17, min_MAF=0.1)