Esempio n. 1
0
def run_parser(filepath, request):

    print >>sys.stderr, 'Parsing started with {}'.format(filepath)
    base_file_path = os.getcwd()
    try:
        padding = 300
        file_type = check_file_type(filepath)
        if file_type == 'file error':
            error = 'This file is not the correct input type, please try an LRG or GB file'
            document_list = created_documents.objects.order_by('-created_on')
            return render(request, 'web_interface/app_homepage.html', {'form': UploadForm(),
                                                                       'document_list': document_list,
                                                                       'error_message': error})
        dictionary = {}
        if file_type == 'gbk':
            gbk_reader = GbkParser(filepath, padding, True)
            dictionary = gbk_reader.run()
            parser_details = gbk_reader.get_version
        elif file_type == 'lrg':
            lrg_reader = LrgParser(filepath, padding, True)
            dictionary  = lrg_reader.run()
            parser_details = lrg_reader.get_version
        parser_details = '{0} {1} {2}'.format(file_type.upper(), 'Parser:', parser_details)
        os.chdir('web_interface')
        os.chdir('output')
        for transcript in dictionary['transcripts']:
            input_reader = Reader()
            writer = LatexWriter()
            reader_details = 'Reader: ' + input_reader.get_version
            writer_details = 'Writer: ' + writer.get_version
            xml_gui_details = 'Control: {}'.format(get_version)
            list_of_versions = [parser_details, reader_details, writer_details, xml_gui_details]
            input_list, nm = input_reader.run(dictionary, transcript, True, list_of_versions, True, file_type, 'web user')
            transcript_accession = dictionary['transcripts'][transcript]['NM_number']
            file_name = transcript_accession
            latex_file, pdf_file = writer.run(input_list, file_name)
            call(["pdflatex", "-interaction=batchmode", latex_file])
            save_as_model = created_documents(transcript=transcript_accession,
                                              location=pdf_file,
                                              gene=dictionary['genename'],
                                              created_on=datetime.now())
            save_as_model.save()
            delete_all_but_most_recent()
    except:
        os.chdir(base_file_path)
    os.chdir(base_file_path)
    clean_up(os.path.join('web_interface', 'output'))
    clean_up(os.path.join('web_interface', 'input'))
Esempio n. 2
0
def run_parser():

    padding = 300
    directory_and_file = entry.get()
    file_name = directory_and_file.split(
        '/')[-2] + '/' + directory_and_file.split('/')[-1]
    file_type = check_file_type(file_name)
    username = entry_name.get()
    dictionary = {}
    nm = ''
    parser_details = ''
    #primer_list = [name.split('.')[0] for name in os.listdir('primers')]
    primer_list = os.listdir('primers')
    primer_applied = False
    if file_type == 'gbk':
        print 'Running parser'
        gbk_reader = GbkParser(file_name, padding, args.trim_flanking)
        dictionary = gbk_reader.run()
        parser_details = gbk_reader.get_version
    elif file_type == 'lrg':
        print 'Running parser'
        lrg_reader = LrgParser(file_name, padding, args.trim_flanking)
        dictionary = lrg_reader.run()
        parser_details = lrg_reader.get_version

    if dictionary['genename'] + '.csv' in primer_list:
        primer_applied = True
        primer_label = primer()
        primer_details = 'Primer Labels: ' + primer_label.get_version
        dictionary = primer_label.run(dictionary, os.getcwd())

    parser_details = '{0} {1} {2}'.format(file_type.upper(), 'Parser:',
                                          parser_details)

    os.chdir("output")
    for transcript in dictionary['transcripts']:
        print 'transcript: %d' % transcript

        input_reader = Reader()
        writer = LatexWriter()
        reader_details = 'Reader: ' + input_reader.get_version
        writer_details = 'Writer: ' + writer.get_version
        xml_gui_details = 'Control: ' + get_version()
        if primer_applied:
            list_of_versions = [parser_details, reader_details, \
                            writer_details, xml_gui_details, primer_details]
        else:
            list_of_versions = [parser_details, reader_details, \
                            writer_details, xml_gui_details]
        lrg_num = file_name.split('.')[0].split('/')[1].replace(
            '_', '\_') + 't' + str(transcript)
        input_list, nm = input_reader.run(dictionary, transcript,
                                          args.write_as_latex,
                                          list_of_versions, args.print_clashes,
                                          file_type, lrg_num, username)
        if file_type == 'gbk':
            filename = dictionary['genename'] + '_' + nm
        else:
            filename = dictionary['genename'] + '_' + file_name.split(
                '.')[0].split('/')[1] + 't' + str(transcript)
        if args.write_as_latex:
            latex_file, pdf_file = writer.run(input_list, filename,
                                              args.write_as_latex)
            call(["pdflatex", "-interaction=batchmode", latex_file])
            clean_up(os.getcwd(), pdf_file)
            move_files(latex_file)
        else:
            latex_file = writer.run(input_list, filename, args.write_as_latex)

        # quick step to allow for non-overlapping writes
        print str(transcript) + ' has been printed'

    print "Process has completed successfully"
    root.quit()
Esempio n. 3
0
def run_parser():

    padding = 300
    directory_and_file = entry.get()
    file_name = directory_and_file.split('/')[-2] + '/' + directory_and_file.split('/')[-1]
    file_type = check_file_type(file_name)
    username = entry_name.get()
    dictionary = {}
    nm = ''
    parser_details = ''
    #primer_list = [name.split('.')[0] for name in os.listdir('primers')]
    primer_list = os.listdir('primers')
    primer_applied = False
    if file_type == 'gbk':
        print 'Running parser'
        gbk_reader = GbkParser(file_name, padding, args.trim_flanking)
        dictionary = gbk_reader.run()
        parser_details = gbk_reader.get_version
    elif file_type == 'lrg':
        print 'Running parser'
        lrg_reader = LrgParser(file_name, padding, args.trim_flanking)
        dictionary  = lrg_reader.run()
        parser_details = lrg_reader.get_version

    if dictionary['genename']+'.csv' in primer_list:
        primer_applied = True
        primer_label = primer()
        primer_details = 'Primer Labels: ' + primer_label.get_version
        dictionary = primer_label.run(dictionary, os.getcwd())

    parser_details = '{0} {1} {2}'.format(file_type.upper(), 'Parser:', parser_details)


    os.chdir("output")
    for transcript in dictionary['transcripts']:  
        print 'transcript: %d' % transcript  
        
        input_reader = Reader()
        writer = LatexWriter()
        reader_details = 'Reader: ' + input_reader.get_version
        writer_details = 'Writer: ' + writer.get_version
        xml_gui_details = 'Control: ' + get_version()
        if primer_applied:
            list_of_versions = [parser_details, reader_details, \
                            writer_details, xml_gui_details, primer_details]
        else:
            list_of_versions = [parser_details, reader_details, \
                            writer_details, xml_gui_details]
        lrg_num = file_name.split('.')[0].split('/')[1].replace('_', '\_')+'t'+str(transcript)
        input_list, nm = input_reader.run(dictionary, transcript, args.write_as_latex, list_of_versions, args.print_clashes, file_type, lrg_num, username)
        if file_type == 'gbk':
            filename = dictionary['genename']+'_'+ nm
        else:
            filename = dictionary['genename']+'_'+ file_name.split('.')[0].split('/')[1]+'t'+str(transcript)
        if args.write_as_latex:
            latex_file, pdf_file = writer.run(input_list, filename, args.write_as_latex)
            call(["pdflatex", "-interaction=batchmode", latex_file])
            clean_up(os.getcwd(), pdf_file)
            move_files(latex_file)
        else:
            latex_file = writer.run(input_list, filename, args.write_as_latex)
        
        
        # quick step to allow for non-overlapping writes
        print str(transcript) + ' has been printed'

    print "Process has completed successfully"
    root.quit()