Exemplo n.º 1
0
def import_json(args):
    #set up logging
    logger = logging.getLogger('snapperdb.snpdb.import_json')
    json_path = untar_file(args.json_file)
    json_dict = {}

    #import json
    try:
        with open(json_path) as json_data:
            json_dict = json.load(json_data)
        json_data.close()
    except IOError:
        print "Issue with JSON file. Exiting."
        exit()

    #parse config
    args.config_file = json_dict['config_file']
    config_dict = parse_config(args)

    #initalise snpdb class
    snpdb = SNPdb(config_dict)
    #parse confif
    snpdb.parse_config_dict(config_dict)
    #get reference genome path
    ref_seq_file = os.path.join(snapperdb.__ref_genome_dir__,
                                snpdb.reference_genome + '.fa')
    #read the reference fasta
    ref_seq = read_multi_contig_fasta(ref_seq_file)

    #create VCF class
    vcf = Vcf()
    vcf.parse_json_dict(json_dict, ref_seq)
    vcf.depth_average = json_dict['strain_stats']
    vcf.sample_name = json_dict['sample']

    logger.info('Uploading to SNPdb')
    #upload vcf
    #connect to snpdb postgres
    snpdb._connect_to_snpdb()
    snpdb.snpdb_conn = psycopg2.connect(snpdb.conn_string)

    if args.write_flag == 'W':

        snpdb.snpdb_upload(vcf, args)
        #annotate vars
        logger.info('Annotating new variants')

        snpdb.snpdb_annotate_vars(vcf)
    elif args.write_flag == 'R':
        print "under development"
Exemplo n.º 2
0
def vcf_to_db(args, config_dict, vcf):
    #set up loggging
    logger = logging.getLogger('snapperdb.snpdb.vcf_to_db')
    logger.info('Initialising SNPdb class')

    #create snpdb class
    snpdb = SNPdb(config_dict)

    #parse config into snpdb object
    logger.info('Parsing config dict')
    snpdb.parse_config_dict(config_dict)

    #connect to snpdb postgres
    snpdb._connect_to_snpdb()
    snpdb.snpdb_conn = psycopg2.connect(snpdb.conn_string)

    #check stack?
    if inspect.stack()[0][3] == 'fastq_to_db':
        # fastq_to_db we will alread have a vcf object to work wih
        logger.info('You are running fastq_to_db.')

    elif inspect.stack()[0][3] == 'vcf_to_db':
        ## there is no existing vcf class here, but there will definitely be a vcf
        logger.info('You are running vcf_to_db. Initialising Vcf class.')
        vcf = Vcf()
        logger.info('Making SNPdb variables and output files')
        #set up variables
        snpdb.define_class_variables_and_make_output_files(args, vcf)

    #read vcf
    vcf.read_multi_contig_vcf()
    logger.info('Uploading to SNPdb')
    #upload vcf
    snpdb.snpdb_upload(vcf, args)
    #annotate vars
    logger.info('Annotating new variants')

    snpdb.snpdb_annotate_vars(vcf)