misc/featuresFromSnps.py
def find_overlapping_features(snp_groups, gff_db, gene_info, feature_type, outfile):
    """For each SNP group, search the gff3 (gene) file for any features that 
    overlap the range. Find the feature in the info file, and calculate the 
    distance from the actual SNP"""
    with open(outfile, 'w') as output:
        output.write("SNP_GROUP\tCHR\tSNP_POS\tNUM_SNPs\tGENE_ID\t" + 
                "GENE_Start\tGENE_End\tGeneINFO\n")
        for key, value in snp_groups.items():
            chromosome, position, minimum, maximum, snp_count = value
            region = "Chr{0:02d}:{1}-{2}".format(int(chromosome.lower().replace("chr","")), 
                    minimum, 
                    maximum) 
            features = []
            for line in gff_db.region(region, featuretype=feature_type):
                # sys.stderr.write(str(line) + "\n")
                gene_id = ".".join(line.id.split('.')[0:2])
                gene_start = line.start
                gene_end = line.end
                for feature in gene_info[gene_id]:
                    if feature not in features:
                        output.write("{}\t{}\t{}\t{}\t{}\t{}\t{}\t{}\n".format(key, 
                            chromosome, 
                            position, 
                            snp_count, 
                            gene_id, 
                            gene_start,
                            gene_end,
                            ",".join(feature.split()[3:])
                            )
                            )
                    features.append(feature)
For each SNP group, search the gff3 (gene) file for any features that 
    overlap the range. Find the feature in the info file, and calculate the 
    distance from the actual SNP
For each SNP group, search the gff3 (gene) file for any features that
overlap the range. Find the feature in the info file, and calculate the
distance from the actual SNP
For each SNP group search the gff3 ( gene ) file for any features that overlap the range . Find the feature in the info file and calculate the distance from the actual SNP
def find_overlapping_features(snp_groups, gff_db, gene_info, feature_type, outfile):
    with open(outfile, 'w') as output:
        output.write("SNP_GROUP\tCHR\tSNP_POS\tNUM_SNPs\tGENE_ID\t" + 
                "GENE_Start\tGENE_End\tGeneINFO\n")
        for key, value in snp_groups.items():
            chromosome, position, minimum, maximum, snp_count = value
            region = "Chr{0:02d}:{1}-{2}".format(int(chromosome.lower().replace("chr","")), 
                    minimum, 
                    maximum) 
            features = []
            for line in gff_db.region(region, featuretype=feature_type):
                gene_id = ".".join(line.id.split('.')[0:2])
                gene_start = line.start
                gene_end = line.end
                for feature in gene_info[gene_id]:
                    if feature not in features:
                        output.write("{}\t{}\t{}\t{}\t{}\t{}\t{}\t{}\n".format(key, 
                            chromosome, 
                            position, 
                            snp_count, 
                            gene_id, 
                            gene_start,
                            gene_end,
                            ",".join(feature.split()[3:])
                            )
                            )
                    features.append(feature)
def find_overlapping_features ( snp_groups , gff_db , gene_info , feature_type , outfile ) : with open ( outfile , 'w' ) as output : output . write ( "SNP_GROUP\tCHR\tSNP_POS\tNUM_SNPs\tGENE_ID\t" + "GENE_Start\tGENE_End\tGeneINFO\n" ) for key , value in snp_groups . items ( ) : chromosome , position , minimum , maximum , snp_count = value region = "Chr{0:02d}:{1}-{2}" . format ( int ( chromosome . lower ( ) . replace ( "chr" , "" ) ) , minimum , maximum ) features = [ ] for line in gff_db . region ( region , featuretype = feature_type ) : gene_id = "." . join ( line . id . split ( '.' ) [ 0 : 2 ] ) gene_start = line . start gene_end = line . end for feature in gene_info [ gene_id ] : if feature not in features : output . write ( "{}\t{}\t{}\t{}\t{}\t{}\t{}\t{}\n" . format ( key , chromosome , position , snp_count , gene_id , gene_start , gene_end , "," . join ( feature . split ( ) [ 3 : ] ) ) ) features . append ( feature )
For each SNP group, search the gff3 (gene) file for any features that
overlap the range.
For each SNP group search the gff3 ( gene ) file for any features that overlap the range .
"""For each SNP group, search the gff3 (gene) file for any features that 
    overlap the range. Find the feature in the info file, and calculate the 
    distance from the actual SNP""" # sys.stderr.write(str(line) + "\n")
snp_groups
gff_db
gene_info
feature_type
outfile