def process_formdata(self, input_data): if input_data: self.data = input_data[0] else: self.data = None self.processed_data = None return self.error_items = [] # Cells to highlight as having errors try: data = json.loads(input_data[0]) except ValueError as e: raise ValidationError(e.msg) # Read in data headers = data.pop(0) df = pd.DataFrame(data, columns=headers) \ .replace('', np.nan) \ .dropna(how='all') \ .dropna(how='all', axis=1) if 'STRAIN' in df.columns: self.strain_list = list(df.STRAIN) # Resolve isotypes and insert as second column try: df = df.assign(ISOTYPE=[query_strains(x, resolve_isotype=True) for x in df.STRAIN]) isotype_col = df.pop("ISOTYPE") df.insert(1, "ISOTYPE", isotype_col) logger.info(df) except AttributeError: # If the user fails to pass data it will be flagged pass self.processed_data = df
def isotype_page(isotype_name, release=config['DATASET_RELEASE']): """ Isotype page """ isotype = query_strains(isotype_name=isotype_name) if not isotype: abort(404) # Fetch isotype images photos = list_release_files(f"photos/isolation/{isotype_name}") photo_set = {} for row in photos: if 'thumb' not in row: strains = basename(row).replace(".jpg", "").split("_")[1:] photo_set[row.replace(".jpg", ".thumb.jpg")] = strains # High impact variants logger.info(release) VARS = { "title": f"Isotype {isotype_name}", "isotype": isotype, "isotype_name": isotype_name, "isotype_ref_strain": [x for x in isotype if x.isotype_ref_strain][0], "strain_json_output": dump_json(isotype), "photo_set": photo_set } return render_template('strain/isotype.html', **VARS)
def data(selected_release=DATASET_RELEASE): """ Default data page - lists available releases. """ title = "Releases" strain_listing = query_strains(release=selected_release) # Fetch variant data url = "https://storage.googleapis.com/elegansvariation.org/releases/{selected_release}/multiqc_bcftools_stats.json".format( selected_release=selected_release) vcf_summary = requests.get(url).json() release_summary = strain_m.release_summary(selected_release) try: phylo_url = list_release_files( f"releases/{DATASET_RELEASE}/popgen/trees/genome.pdf")[0] except IndexError: pass VARS = { 'title': title, 'strain_listing': strain_listing, 'vcf_summary': vcf_summary, 'phylo_url': phylo_url, 'RELEASES': RELEASES, 'release_summary': release_summary, 'selected_release': selected_release, 'wormbase_genome_version': dict(RELEASES)[selected_release] } return render_template('data.html', **VARS)
def download_script_strain_v2(): v2 = True strain_listing = query_strains(release=config["DATASET_RELEASE"]) download_page = render_template('download_script.sh', **locals()) response = make_response(download_page) response.headers["Content-Type"] = "text/plain" return response
def generate(): first = True if first: first = False header = [x.name for x in list(strain_m.__mapper__.columns)] yield ('\t'.join(header) + "\n").encode('utf-8') for row in query_strains(): row = [getattr(row, column.name) for column in col_list] yield ('\t'.join(map(str, row)) + "\n").encode('utf-8')
def generate(): col_list = list(Strain.__mapper__.columns) col_order = [ 1, 0, 3, 4, 5, 7, 8, 9, 10, 28, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 2, 6 ] col_list[:] = [col_list[i] for i in col_order] header = [x.name for x in col_list] yield '\t'.join(header) + "\n" for row in query_strains(issues=False): row = [getattr(row, column.name) for column in col_list] yield '\t'.join(map(str, row)) + "\n"
def data(selected_release=config["DATASET_RELEASE"]): """ Default data page - lists available releases. """ # Pre-2020 releases used BAMs grouped by isotype. if int(selected_release) < 20200101: return data_v01(selected_release) # Post-2020 releases keep strain-level bams separate. title = "Releases" sub_page = selected_release strain_listing = query_strains(release=selected_release) strain_listing_issues = query_strains(release=selected_release, issues=True) release_summary = Strain.release_summary(selected_release) RELEASES = config["RELEASES"] DATASET_RELEASE, WORMBASE_VERSION = list( filter(lambda x: x[0] == selected_release, RELEASES))[0] REPORTS = ["alignment"] return render_template('data_v2.html', **locals())
def strain_catalog(): # [ ] REVERT; TEMPORARY BAN ON NEW ORDERS flash(Markup( "<strong>Due to COVID-19, we are unable to accept new orders until further notice.</strong>" ), category="danger") VARS = { "title": "Strain Catalog", "warning": request.args.get('warning'), "strain_listing": query_strains() } return render_template('strain/strain_catalog.html', **VARS)
def data_v01(selected_release): # Legacy releases (Pre 20200101) title = "Releases" subtitle = selected_release strain_listing = query_strains(release=selected_release) # Fetch variant data url = "https://storage.googleapis.com/elegansvariation.org/releases/{selected_release}/multiqc_bcftools_stats.json".format( selected_release=selected_release) try: vcf_summary = requests.get(url).json() except JSONDecodeError: vcf_summary = None release_summary = Strain.release_summary(selected_release) try: phylo_url = list_release_files( f"releases/{config['DATASET_RELEASE']}/popgen/trees/genome.pdf")[0] except IndexError: phylo_url = None RELEASES = config["RELEASES"] wormbase_genome_version = dict(config["RELEASES"])[selected_release] return render_template('data.html', **locals())
def isotype_page(isotype_name): """ Isotype page """ isotype = query_strains(isotype_name=isotype_name) if not isotype: abort(404) # Fetch isotype images photos = list_release_files(f"photos/isolation/{isotype_name}") photo_set = {} for row in photos: if 'thumb' not in row: strains = basename(row).replace(".jpg", "").split("_")[1:] photo_set[row.replace(".jpg", ".thumb.jpg")] = strains # High impact variants soft_variant = requests.get( f"https://storage.googleapis.com/elegansvariation.org/releases/{DATASET_RELEASE}/variation/sample_summary/soft.isotype_summary.json" ).json() hard_variant = requests.get( f"https://storage.googleapis.com/elegansvariation.org/releases/{DATASET_RELEASE}/variation/sample_summary/hard.isotype_summary.json" ).json() soft_variant = [x for x in soft_variant if x['isotype'] == isotype_name][0] hard_variant = [x for x in hard_variant if x['isotype'] == isotype_name][0] VARS = { "title": isotype_name, "isotype": isotype, "isotype_name": isotype_name, "reference_strain": [x for x in isotype if x.reference_strain][0], "strain_json_output": dump_json(isotype), "photo_set": photo_set, "soft_variant": soft_variant, "hard_variant": hard_variant } return render_template('strain/strain.html', **VARS)