def add(self): adder = Add() if self.args['one_sample'] is not None: new_sample = [tuple(entry.strip('}').strip('{').strip(',').split(':')) for entry in self.args['one_sample']] new_sample = dict(new_sample) adder.add_one_sample(new_sample) if len(self.args['email']) > 0: if not sampleinfo_mongo.is_fully_annotated(new_sample['SAMPLE']): annotate = Annotate() annotate.annotate_sample(new_sample['SAMPLE'], 'orig') output_files = Output() final_file = output_files.sample_variants_csv(new_sample['SAMPLE'], 'orig') message = "Here are all the variants for the sample %s with their QC status." % new_sample['SAMPLE'] for address in self.args['email']: self.__log_sending_email(address) output_bash.email_file(message, final_file, address) elif self.args['sample_info'] is not None: adder.add_sample_info(self.args['sample_info'])
def output(self): if self.args['type'] == 'sample': if not sampleinfo_mongo.is_fully_annotated(self.args['name']): annotate = Annotate() annotate.annotate_sample(self.args['name'], 'orig') output_files = Output() output_files.sample_variants_csv(self.args['name'], 'orig')
def callpeaks(self, peakscaller, controlsample=None, name=None): ''' This will call the peak caller of choice on selected lane. :param peakscaller: :param controlsample: :param name: :return: ''' if not hasattr(peakscaller, 'run_peakcaller'): raise AttributeError( 'First parameter to call peaks should be a peak caller and %s was missing %s' % (peakscaller, 'run_peakcaller') ) temp_dir = os.path.join(self.lane.base_path, 'cache', peakscaller.peakcaller_name, name) alignment.commons.ensure_path(temp_dir) peakscaller.run_peakcaller(self, controlsample, temp_dir) #print(temp_dir) res = peakscaller.load_peaks(temp_dir) annotation = annotate.AnnotatePeaks(res, self.genome.data_path) anno_peaks = annotation.call_me() if name is None: name = self.name + '_peaks_' + peakscaller.peakcaller_name if controlsample: name += '_vs_' + controlsample.name peak_file_path = os.path.join(self.lane.base_path, 'results', 'Peaks', name) alignment.commons.ensure_path(peak_file_path) anno_peaks.to_csv(os.path.join(peak_file_path, name+'.tsv'), sep='\t', header=True, index=False)
def output(self): # The output option handler that will write the sample_variants_csv containing important information about # the sample variants. if self.args['type'] == 'sample': if self.args['name'] == "all": output_files = Output() output_files.output_all_variants() else: if not sampleinfo_mongo.is_fully_annotated(self.args['name']): annotate = Annotate() annotate.annotate_sample(self.args['name'], 'orig') output_files = Output() output_files.sample_variants_csv(self.args['name'], 'orig')
def run(self, number=0): if number == 0: number = hotspothist_mongo.get_next_number() else: if not hotspothist_mongo.is_hotspot_hist(number): self.__log_not_hotspot_number() sys.exit(1) hotspothist_mongo.add_new_hist(number) hotspot_dir = self.__ensure_directory(number) if not hotspothist_mongo.has_loaded_hotspots(number): if not self.__has_complete_hotspot_vcfs(hotspot_dir): # CREATING HOTSPOT FILE self.create_hotspot_file(hotspot_dir) print "Perform hotspotting" print "Load hotspot" # ANNOTATING annotate = Annotate() annovar_input = self.create_annovar_input(hotspot_dir) annovar_output = annotate.annotate_hotspot(annovar_input) annotate.save_annotations(annovar_output)
def add(self): """ This carries out the appropriate operation if add is selected from the parser. :return: """ adder = Add() # This is the adding procedure performed for when one sample is added from the command line. if self.args['one_sample'] is not None: new_sample = [tuple(entry.strip('}').strip('{').strip(',').split(':')) for entry in self.args['one_sample']] new_sample = dict(new_sample) # The adder actually adds the sample to the database. adder.add_one_sample(new_sample) # This is what is carried out if an email is desired, it will actually peform an additional # annotation to make sure that the result has all of the necessary information. if len(self.args['email']) > 0: if not sampleinfo_mongo.is_fully_annotated(new_sample['SAMPLE']): annotate = Annotate() annotate.annotate_sample(new_sample['SAMPLE'], 'orig') output_files = Output() final_file = output_files.sample_variants_csv(new_sample['SAMPLE'], 'orig') # This actually carries out the emailing. message = "Here are all the variants for the sample %s with their QC status." % new_sample['SAMPLE'] for address in self.args['email']: self.__log_sending_email(address) output_bash.email_file(message, final_file, address) # This is how the samples are added from a file of many samples. elif self.args['sample_info'] is not None: adder.add_sample_info(self.args['sample_info'])
import psycopg2 from flask import Flask, request, jsonify from flask_cors import CORS, cross_origin from psycopg2 import sql from ingest import ingest from annotate import Annotate from extract import WebDriver app = Flask(__name__) cors = CORS(app) annotate = Annotate() webdriver = WebDriver() webdriver.visit("http://localhost:3000") def setup(): with psycopg2.connect("host=localhost") as conn: with conn.cursor() as cur: cur.execute(""" create table if not exists metamapper ( uri text, field text, xpath text, value text, primary key (uri, field) ); """)
def main(self, args, command): ''' Parameters ---------- Output ------ ''' self._check_general(args) self._logging_setup(args) logging.info("Running command: %s" % ' '.join(command)) if args.subparser_name == self.DATA: self._check_data(args) d = Data() d.do() if args.subparser_name == self.ANNOTATE: self._check_annotate(args) a = Annotate(# Define inputs and outputs args.output, # Define type of annotation to be carried out args.ko, args.pfam, args.tigrfam, args.cog, args.hypothetical, # Cutoffs args.evalue, args.bit, args.id, args.aln_query, args.aln_reference, args.cascaded, args.c, # Parameters args.threads, args.parallel, args.suffix) a.do(args.genome_directory, args.protein_directory, args.genome_files, args.protein_files) elif args.subparser_name == self.CLASSIFY: self._check_classify(args) c = Classify() c.do(args.custom_modules, args.cutoff, args.genome_and_annotation_file, args.genome_and_annotation_matrix, args.output) elif args.subparser_name == self.ENRICHMENT: self._check_enrichment(args) e = Enrichment() e.do(# Inputs args.annotation_matrix, args.annotation_file, args.metadata, args.modules, args.abundances, args.do_all, args.do_ivi, args.do_gvg, args.do_ivg, args.pval_cutoff, args.proportions_cutoff, args.threshold, args.multi_test_correction, args.output) elif args.subparser_name == self.COMPARE: self._check_compare(args) c = Compare() c.do(args.enrichm_annotate_output) elif(args.subparser_name == NetworkAnalyser.PATHWAY or args.subparser_name == NetworkAnalyser.EXPLORE or args.subparser_name == NetworkAnalyser.TRAVERSE): self._check_network(args) na=NetworkAnalyser(args.metadata) na.do(args.matrix, args.transcriptome, args.metabolome, args.depth, args.filter, args.limit, args.queries, args.subparser_name, args.starting_compounds, args.steps, args.number_of_queries, args.output) logging.info('Done!')
args = parser.parse_args() classes_file=args.classes_file annotation_dir=args.annotation_dir output_dir = args.output_dir image_file = args.image_file mapper = get_mapper(classes_file) files=[] if image_file: files.append(image_file) else: for f in os.listdir(annotation_dir): if annotation_dir[:-1] =='/': files.append(annotation_dir+f) else: files.append(annotation_dir + '/' + f) if output_dir: if not os.path.isdir(output_dir): os.makedirs(output_dir) a = Annotate(files, mapper, save_folder=output_dir) #annotation_file is always turned into a list for f in a.annotation_file: obj_key = a.get_objects(f) # image labels generated a.label_image(obj_key)