Esempio n. 1
0
def lovd_get_gs():
    """
    LOVD bypass to get the correct GeneSymbol incl Transcript variant.

    Used by LOVD to get the correct transcript variant out of a genomic
    record. LOVD uses a genomic reference (``NC_``?) in combination with a
    gene symbol to pass variant info to mutalyzer. Mutalyzer 1.0 was only
    using the first transcript. LOVD supplies the NM of the transcript needed
    but this was ignored. This helper allows LOVD to get the requested
    transcript variant from a genomic reference.

    Parameters:

    mutationName
      The mutationname without gene symbol.
    variantRecord
      The NM reference of the variant.
    forward
      If set this forwards the request to the name checker.

    Returns: Output of name checker if `forward` is set, otherwise the
    gene symbol with the variant notation as string.
    """
    mutation_name = request.args['mutationName']
    variant_record = request.args['variantRecord']
    forward = request.args.get('forward')

    output = Output(__file__)
    output.addMessage(__file__, -1, 'INFO',
                      'Received request getGS(%s, %s, %s) from %s'
                      % (mutation_name, variant_record, forward,
                         request.remote_addr))

    variantchecker.check_variant(mutation_name, output)

    output.addMessage(__file__, -1, 'INFO',
                      'Finished request getGS(%s, %s, %s)'
                      % (mutation_name, variant_record, forward))

    legends = output.getOutput('legends')

    # Filter the transcript from the legend.
    legends = [l for l in legends if '_v' in l[0]]
    for l in legends:
        if l[1] == variant_record:
            if forward:
                p, a = mutation_name.split(':')
                return redirect(url_for('.name_checker',
                                        description='%s(%s):%s' % (p, l[0], a),
                                        standalone=1))
            else:
                response = make_response(l[0])
                response.headers['Content-Type'] = 'text/plain; charset=utf-8'
                return response

    response = make_response('Transcript not found')
    response.headers['Content-Type'] = 'text/plain; charset=utf-8'
    return response
Esempio n. 2
0
def lovd_get_gs():
    """
    LOVD bypass to get the correct GeneSymbol incl Transcript variant.

    Used by LOVD to get the correct transcript variant out of a genomic
    record. LOVD uses a genomic reference (``NC_``?) in combination with a
    gene symbol to pass variant info to mutalyzer. Mutalyzer 1.0 was only
    using the first transcript. LOVD supplies the NM of the transcript needed
    but this was ignored. This helper allows LOVD to get the requested
    transcript variant from a genomic reference.

    Parameters:

    mutationName
      The mutationname without gene symbol.
    variantRecord
      The NM reference of the variant.
    forward
      If set this forwards the request to the name checker.

    Returns: Output of name checker if `forward` is set, otherwise the
    gene symbol with the variant notation as string.
    """
    mutation_name = request.args['mutationName']
    variant_record = request.args['variantRecord']
    forward = request.args.get('forward')

    output = Output(__file__)
    output.addMessage(__file__, -1, 'INFO',
                      'Received request getGS(%s, %s, %s) from %s'
                      % (mutation_name, variant_record, forward,
                         request.remote_addr))

    variantchecker.check_variant(mutation_name, output)

    output.addMessage(__file__, -1, 'INFO',
                      'Finished request getGS(%s, %s, %s)'
                      % (mutation_name, variant_record, forward))

    legends = output.getOutput('legends')

    # Filter the transcript from the legend.
    legends = [l for l in legends if '_v' in l[0]]
    for l in legends:
        if l[1] == variant_record:
            if forward:
                p, a = mutation_name.split(':')
                return redirect(url_for('.name_checker',
                                        description='%s(%s):%s' % (p, l[0], a),
                                        standalone=1))
            else:
                response = make_response(l[0])
                response.headers['Content-Type'] = 'text/plain; charset=utf-8'
                return response

    response = make_response('Transcript not found')
    response.headers['Content-Type'] = 'text/plain; charset=utf-8'
    return response
Esempio n. 3
0
def bed():
    """
    Create a BED track for the given variant, listing the positions of its raw
    variants, e.g., for use in the UCSC Genome Browser.

    This basically just runs the variant checker and extracts the raw variants
    with positions.
    """
    # Backwards compatibility.
    if 'name' in request.args:
        return redirect(url_for('.bed',
                                description=request.args['name']),
                        code=301)

    description = request.args.get('description')

    if not description:
        abort(404)

    output = Output(__file__)

    variantchecker.check_variant(description, output)

    raw_variants = output.getIndexedOutput('rawVariantsChromosomal', 0)
    if not raw_variants:
        abort(404)

    # Todo: Hard-coded hg19.
    fields = {
        'name'       : 'Mutalyzer',
        'description': 'Mutalyzer track for ' + description,
        'visibility' : 'pack',
        'db'         : 'hg19',
        'url'        : url_for('.name_checker',
                               description=description,
                               _external=True),
        'color':       '255,0,0'}

    bed = ' '.join(['track'] +
                   ['%s="%s"' % field for field in fields.items()]) + '\n'

    for descr, positions in raw_variants[2]:
        bed += '\t'.join([raw_variants[0],
                          unicode(min(positions) - 1),
                          unicode(max(positions)),
                          descr,
                          '0',
                          raw_variants[1]]) + '\n'

    response = make_response(bed)
    response.headers['Content-Type'] = 'text/plain; charset=utf-8'
    return response
Esempio n. 4
0
def bed():
    """
    Create a BED track for the given variant, listing the positions of its raw
    variants, e.g., for use in the UCSC Genome Browser.

    This basically just runs the variant checker and extracts the raw variants
    with positions.
    """
    # Backwards compatibility.
    if 'name' in request.args:
        return redirect(url_for('.bed',
                                description=request.args['name']),
                        code=301)

    description = request.args.get('description')

    if not description:
        abort(404)

    output = Output(__file__)

    variantchecker.check_variant(description, output)

    raw_variants = output.getIndexedOutput('rawVariantsChromosomal', 0)
    if not raw_variants:
        abort(404)

    # Todo: Hard-coded hg19.
    fields = {
        'name'       : 'Mutalyzer',
        'description': 'Mutalyzer track for ' + description,
        'visibility' : 'pack',
        'db'         : 'hg19',
        'url'        : url_for('.name_checker',
                               description=description,
                               _external=True),
        'color':       '255,0,0'}

    bed = ' '.join(['track'] +
                   ['%s="%s"' % field for field in fields.items()]) + '\n'

    for descr, positions in raw_variants[2]:
        bed += '\t'.join([raw_variants[0],
                          unicode(min(positions) - 1),
                          unicode(max(positions)),
                          descr,
                          '0',
                          raw_variants[1]]) + '\n'

    response = make_response(bed)
    response.headers['Content-Type'] = 'text/plain; charset=utf-8'
    return response
Esempio n. 5
0
def name_checker():
    """
    Name checker.
    """
    # For backwards compatibility with older LOVD versions, we support the
    # `mutationName` argument. If present, we redirect and add `standalone=1`.
    #
    # Also for backwards compatibility, we support the `name` argument as an
    # alias for `description`.
    if 'name' in request.args:
        return redirect(url_for('.name_checker',
                                description=request.args['name'],
                                standalone=request.args.get('standalone')),
                        code=301)
    if 'mutationName' in request.args:
        return redirect(url_for('.name_checker',
                                description=request.args['mutationName'],
                                standalone=1),
                        code=301)

    description = request.args.get('description')

    if not description:
        return render_template('name-checker.html')

    output = Output(__file__)
    output.addMessage(__file__, -1, 'INFO', 'Received variant %s from %s'
                      % (description, request.remote_addr))
    stats.increment_counter('name-checker/website')

    variantchecker.check_variant(description, output)

    errors, warnings, summary = output.Summary()
    parse_error = output.getOutput('parseError')

    record_type = output.getIndexedOutput('recordType', 0, '')
    reference = output.getIndexedOutput('reference', 0, '')
    if reference:
        if record_type == 'LRG':
            reference_filename = reference + '.xml'
        else :
            reference_filename = reference + '.gb'
    else:
        reference_filename = None

    genomic_dna = output.getIndexedOutput('molType', 0) != 'n'
    genomic_description = output.getIndexedOutput('genomicDescription', 0, '')

    # Create a link to the UCSC Genome Browser.
    browser_link = None
    raw_variants = output.getIndexedOutput('rawVariantsChromosomal', 0)
    if raw_variants:
        positions = [pos
                     for descr, (first, last) in raw_variants[2]
                     for pos in (first, last)]
        bed_url = url_for('.bed', description=description, _external=True)
        browser_link = ('http://genome.ucsc.edu/cgi-bin/hgTracks?db=hg19&'
                        'position={chromosome}:{start}-{stop}&hgt.customText='
                        '{bed_file}'.format(chromosome=raw_variants[0],
                                            start=min(positions) - 10,
                                            stop=max(positions) + 10,
                                            bed_file=urllib.quote(bed_url)))

    # Experimental description extractor.
    if (output.getIndexedOutput('original', 0) and
        output.getIndexedOutput('mutated', 0)):
        allele = extractor.describe_dna(output.getIndexedOutput('original', 0),
                                        output.getIndexedOutput('mutated', 0))
        extracted = '(skipped)'
        if allele:
            extracted = unicode(allele)

    else:
        extracted = ''

    # Todo: Generate the fancy HTML views for the proteins here instead of in
    #   `mutalyzer.variantchecker`.
    arguments = {
        'description'         : description,
        'messages'            : map(util.message_info, output.getMessages()),
        'summary'             : summary,
        'parse_error'         : parse_error,
        'errors'              : errors,
        'genomicDescription'  : genomic_description,
        'chromDescription'    : output.getIndexedOutput(
                                  'genomicChromDescription', 0),
        'genomicDNA'          : genomic_dna,
        'visualisation'       : output.getOutput('visualisation'),
        'descriptions'        : output.getOutput('descriptions'),
        'protDescriptions'    : output.getOutput('protDescriptions'),
        'oldProtein'          : output.getOutput('oldProteinFancy'),
        'altStart'            : output.getIndexedOutput('altStart', 0),
        'altProtein'          : output.getOutput('altProteinFancy'),
        'newProtein'          : output.getOutput('newProteinFancy'),
        'transcriptInfo'      : output.getIndexedOutput('hasTranscriptInfo',
                                                        0, False),
        'transcriptCoding'    : output.getIndexedOutput('transcriptCoding', 0,
                                                        False),
        'exonInfo'            : output.getOutput('exonInfo'),
        'cdsStart_g'          : output.getIndexedOutput('cdsStart_g', 0),
        'cdsStart_c'          : output.getIndexedOutput('cdsStart_c', 0),
        'cdsStop_g'           : output.getIndexedOutput('cdsStop_g', 0),
        'cdsStop_c'           : output.getIndexedOutput('cdsStop_c', 0),
        'restrictionSites'    : output.getOutput('restrictionSites'),
        'legends'             : output.getOutput('legends'),
        'reference_filename'  : reference_filename,  # Todo: Download link is not shown...
        'browserLink'         : browser_link,
        'extractedDescription': extracted,
        'standalone'          : bool(request.args.get('standalone'))
    }

    output.addMessage(__file__, -1, 'INFO',
                      'Finished variant %s' % description)

    return render_template('name-checker.html', **arguments)
Esempio n. 6
0
def name_checker():
    """
    Name checker.
    """
    # For backwards compatibility with older LOVD versions, we support the
    # `mutationName` argument. If present, we redirect and add `standalone=1`.
    #
    # Also for backwards compatibility, we support the `name` argument as an
    # alias for `description`.
    if 'name' in request.args:
        return redirect(url_for('.name_checker',
                                description=request.args['name'],
                                standalone=request.args.get('standalone')),
                        code=301)
    if 'mutationName' in request.args:
        return redirect(url_for('.name_checker',
                                description=request.args['mutationName'],
                                standalone=1),
                        code=301)

    description = request.args.get('description')

    if not description:
        return render_template('name-checker.html')

    output = Output(__file__)
    output.addMessage(__file__, -1, 'INFO', 'Received variant %s from %s'
                      % (description, request.remote_addr))
    stats.increment_counter('name-checker/website')

    variantchecker.check_variant(description, output)

    errors, warnings, summary = output.Summary()
    parse_error = output.getOutput('parseError')

    record_type = output.getIndexedOutput('recordType', 0, '')
    reference = output.getIndexedOutput('reference', 0, '')
    if reference:
        if record_type == 'LRG':
            reference_filename = reference + '.xml'
        else :
            reference_filename = reference + '.gb'
    else:
        reference_filename = None

    genomic_dna = output.getIndexedOutput('molType', 0) != 'n'
    genomic_description = output.getIndexedOutput('genomicDescription', 0, '')

    # Create a link to the UCSC Genome Browser.
    browser_link = None
    raw_variants = output.getIndexedOutput('rawVariantsChromosomal', 0)
    if raw_variants:
        positions = [pos
                     for descr, (first, last) in raw_variants[2]
                     for pos in (first, last)]
        bed_url = url_for('.bed', description=description, _external=True)
        browser_link = ('http://genome.ucsc.edu/cgi-bin/hgTracks?db=hg19&'
                        'position={chromosome}:{start}-{stop}&hgt.customText='
                        '{bed_file}'.format(chromosome=raw_variants[0],
                                            start=min(positions) - 10,
                                            stop=max(positions) + 10,
                                            bed_file=urllib.quote(bed_url)))

    # Experimental description extractor.
    if (output.getIndexedOutput('original', 0) and
        output.getIndexedOutput('mutated', 0)):
        allele = extractor.describe_dna(output.getIndexedOutput('original', 0),
                                        output.getIndexedOutput('mutated', 0))
        extracted = '(skipped)'
        if allele:
            extracted = unicode(allele)

    else:
        extracted = ''

    # Todo: Generate the fancy HTML views for the proteins here instead of in
    #   `mutalyzer.variantchecker`.
    arguments = {
        'description'         : description,
        'messages'            : map(util.message_info, output.getMessages()),
        'summary'             : summary,
        'parse_error'         : parse_error,
        'errors'              : errors,
        'genomicDescription'  : genomic_description,
        'chromDescription'    : output.getIndexedOutput(
                                  'genomicChromDescription', 0),
        'genomicDNA'          : genomic_dna,
        'visualisation'       : output.getOutput('visualisation'),
        'descriptions'        : output.getOutput('descriptions'),
        'protDescriptions'    : output.getOutput('protDescriptions'),
        'oldProtein'          : output.getOutput('oldProteinFancy'),
        'altStart'            : output.getIndexedOutput('altStart', 0),
        'altProtein'          : output.getOutput('altProteinFancy'),
        'newProtein'          : output.getOutput('newProteinFancy'),
        'transcriptInfo'      : output.getIndexedOutput('hasTranscriptInfo',
                                                        0, False),
        'transcriptCoding'    : output.getIndexedOutput('transcriptCoding', 0,
                                                        False),
        'exonInfo'            : output.getOutput('exonInfo'),
        'cdsStart_g'          : output.getIndexedOutput('cdsStart_g', 0),
        'cdsStart_c'          : output.getIndexedOutput('cdsStart_c', 0),
        'cdsStop_g'           : output.getIndexedOutput('cdsStop_g', 0),
        'cdsStop_c'           : output.getIndexedOutput('cdsStop_c', 0),
        'restrictionSites'    : output.getOutput('restrictionSites'),
        'legends'             : output.getOutput('legends'),
        'reference_filename'  : reference_filename,  # Todo: Download link is not shown...
        'browserLink'         : browser_link,
        'extractedDescription': extracted,
        'standalone'          : bool(request.args.get('standalone'))
    }

    output.addMessage(__file__, -1, 'INFO',
                      'Finished variant %s' % description)

    return render_template('name-checker.html', **arguments)
Esempio n. 7
0
    def _processNameBatch(self, batch_job, cmd, flags):
        """
        Process an entry from the Name Batch, write the results
        to the job-file. If an Exception is raised, catch and continue.

        Side-effect:
            - Output written to outputfile.

        @arg cmd: The NameChecker input
        @type cmd:
        @arg i: The JobID
        @type i:
        @arg flags: Flags of the current entry
        @type flags:
        """
        O = Output(__file__)
        O.addMessage(__file__, -1, "INFO",
            "Received NameChecker batchvariant " + cmd)

        stats.increment_counter('name-checker/batch')

        #Read out the flags
        skip = self.__processFlags(O, flags)

        if not skip :
            #Run mutalyzer and get values from Output Object 'O'
            try :
                variantchecker.check_variant(cmd, O)
            except Exception:
                #Catch all exceptions related to the processing of cmd
                O.addMessage(__file__, 4, "EBATCHU",
                        "Unexpected error occurred, dev-team notified")
                import traceback
                O.addMessage(__file__, 4, "DEBUG", unicode(repr(traceback.format_exc())))
            #except
            finally :
                #check if we need to update the database
                self._updateDbFlags(O, batch_job.id)
        #if

        batchOutput = O.getOutput("batchDone")

        outputline =  "%s\t" % cmd
        outputline += "%s\t" % "|".join(O.getBatchMessages(2))

        if batchOutput :
            outputline += batchOutput[0]

        #Output
        filename = "%s/batch-job-%s.txt" % (settings.CACHE_DIR, batch_job.result_id)
        if not os.path.exists(filename) :
            # If the file does not yet exist, create it with the correct
            # header above it. The header is read from the config file as
            # a list. We need a tab delimited string.
            header = ['Input',
                      'Errors and warnings',
                      'AccNo',
                      'Genesymbol',
                      'Variant',
                      'Reference Sequence Start Descr.',
                      'Coding DNA Descr.',
                      'Protein Descr.',
                      'GeneSymbol Coding DNA Descr.',
                      'GeneSymbol Protein Descr.',
                      'Genomic Reference',
                      'Coding Reference',
                      'Protein Reference',
                      'Affected Transcripts',
                      'Affected Proteins',
                      'Restriction Sites Created',
                      'Restriction Sites Deleted']
            handle = io.open(filename, mode='a', encoding='utf-8')
            handle.write("%s\n" % "\t".join(header))
        #if
        else :
            handle = io.open(filename, mode='a', encoding='utf-8')

        if flags and 'C' in flags:
            separator = '\t'
        else:
            separator = '\n'

        handle.write("%s%s" % (outputline, separator))
        handle.close()
        O.addMessage(__file__, -1, "INFO",
            "Finished NameChecker batchvariant " + cmd)
Esempio n. 8
0
    def _processNameBatch(self, batch_job, cmd, flags):
        """
        Process an entry from the Name Batch, write the results
        to the job-file. If an Exception is raised, catch and continue.

        Side-effect:
            - Output written to outputfile.

        @arg cmd: The NameChecker input
        @type cmd:
        @arg i: The JobID
        @type i:
        @arg flags: Flags of the current entry
        @type flags:
        """
        O = Output(__file__)
        O.addMessage(__file__, -1, "INFO",
                     "Received NameChecker batchvariant " + cmd)

        stats.increment_counter('name-checker/batch')

        #Read out the flags
        skip = self.__processFlags(O, flags)

        if not skip:
            #Run mutalyzer and get values from Output Object 'O'
            try:
                variantchecker.check_variant(cmd, O)
            except Exception:
                #Catch all exceptions related to the processing of cmd
                O.addMessage(__file__, 4, "EBATCHU",
                             "Unexpected error occurred, dev-team notified")
                import traceback
                O.addMessage(__file__, 4, "DEBUG",
                             unicode(repr(traceback.format_exc())))
            #except
            finally:
                #check if we need to update the database
                self._updateDbFlags(O, batch_job.id)
        #if

        batchOutput = O.getOutput("batchDone")

        outputline = "%s\t" % cmd
        outputline += "%s\t" % "|".join(O.getBatchMessages(2))

        if batchOutput:
            outputline += batchOutput[0]

        #Output
        filename = "%s/batch-job-%s.txt" % (settings.CACHE_DIR,
                                            batch_job.result_id)
        if not os.path.exists(filename):
            # If the file does not yet exist, create it with the correct
            # header above it. The header is read from the config file as
            # a list. We need a tab delimited string.
            header = [
                'Input', 'Errors and warnings', 'AccNo', 'Genesymbol',
                'Variant', 'Reference Sequence Start Descr.',
                'Coding DNA Descr.', 'Protein Descr.',
                'GeneSymbol Coding DNA Descr.', 'GeneSymbol Protein Descr.',
                'Genomic Reference', 'Coding Reference', 'Protein Reference',
                'Affected Transcripts', 'Affected Proteins',
                'Restriction Sites Created', 'Restriction Sites Deleted'
            ]
            handle = io.open(filename, mode='a', encoding='utf-8')
            handle.write("%s\n" % "\t".join(header))
        #if
        else:
            handle = io.open(filename, mode='a', encoding='utf-8')

        if flags and 'C' in flags:
            separator = '\t'
        else:
            separator = '\n'

        handle.write("%s%s" % (outputline, separator))
        handle.close()
        O.addMessage(__file__, -1, "INFO",
                     "Finished NameChecker batchvariant " + cmd)