Exemplo n.º 1
0
def import_genes(filename, chromosome, genome, verbose = False):
    from gene_crawler import crawl_genes
    from tridentdb.models import Genes, Genome
    from django.db.utils import DatabaseError
    
    if not chromosome:
        raise Exception("Missing Chromosome information")

    if not genome:
        raise Exception("Missing Genome information")
    genome = Genome.objects.filter(genome_ver = genome)
    if len(genome) != 1:
        raise ImportException("Genome, '{0}', has not yet been loaded into the database.".format(genome))
    
    genes = crawl_genes(filename)
    genome = genome[0]
    for gene in genes:
        if verbose:
            print("Importing {0}".format(gene.name))
        (start, end) = gene.get_coords()
        dbentry = Genes(name = gene.name, genomic_start = start, genomic_end = end,synonyms = gene.synonym, is_on_positive_strand = (gene.direction == "+"), chromosome = chromosome, db_xref = ",".join(gene.db_xref), genome_id = genome.id)
        try:
            dbentry.save()
        except DatabaseError as de:
            from sys import stderr
            from gene_crawler import write_gene
            stderr.write("Error loading gene:")
            write_gene(gene, stderr)
            raise de
Exemplo n.º 2
0
def test_gene_indexer():
    from gene_crawler import crawl_genes, write_gene
    import StringIO as SIO
    from os.path import join
    canonical = open(join("test", "indexer.out.expected"), "r")
    genes = crawl_genes(join("test", "test.gbs"))

    buf = SIO.StringIO()
    for gene in genes:
        write_gene(gene, buf)
    buf.seek(0)
    if buf.read() == canonical.read():
        print("Gene Indexer test passed")
        return

    buf.seek(0)
    canonical.seek(0)
    print("Expected:")
    print(canonical.read())
    print("Produced:")
    print(buf.read())
    raise Exception("Gene Indexter test failed")
Exemplo n.º 3
0
def import_genes(filename, chromosome, genome, verbose=False):
    from gene_crawler import crawl_genes
    from tridentdb.models import Genes, Genome
    from django.db.utils import DatabaseError

    if not chromosome:
        raise Exception("Missing Chromosome information")

    if not genome:
        raise Exception("Missing Genome information")
    genome = Genome.objects.filter(genome_ver=genome)
    if len(genome) != 1:
        raise ImportException(
            "Genome, '{0}', has not yet been loaded into the database.".format(
                genome))

    genes = crawl_genes(filename)
    genome = genome[0]
    for gene in genes:
        if verbose:
            print("Importing {0}".format(gene.name))
        (start, end) = gene.get_coords()
        dbentry = Genes(name=gene.name,
                        genomic_start=start,
                        genomic_end=end,
                        synonyms=gene.synonym,
                        is_on_positive_strand=(gene.direction == "+"),
                        chromosome=chromosome,
                        db_xref=",".join(gene.db_xref),
                        genome_id=genome.id)
        try:
            dbentry.save()
        except DatabaseError as de:
            from sys import stderr
            from gene_crawler import write_gene
            stderr.write("Error loading gene:")
            write_gene(gene, stderr)
            raise de