def alignment_bioent(self, locus_identifier=None, strain_ids=None, are_ids=False): if locus_identifier is not None: if are_ids: bioent_id = locus_identifier else: bioent_id = get_obj_id(str(locus_identifier).upper(), class_type='BIOENTITY', subclass_type='LOCUS') alignment = get_bioentity_details(bioent_id, 'ALIGNMENT') if alignment is None: return alignment if strain_ids is None: return alignment else: alignment = json.loads(alignment) try: strain_ids = set([int(strain_id) for strain_id in strain_ids]) strain_ids.add(1) except Exception: return None alignment['aligned_dna_sequences'] = [x for x in alignment['aligned_dna_sequences'] if x['strain_id'] in strain_ids] alignment['aligned_protein_sequences'] = [x for x in alignment['aligned_protein_sequences'] if x['strain_id'] in strain_ids] from src.sgd.backend import calculate_variant_data alignment['variant_data_dna'] = calculate_variant_data('DNA', alignment['aligned_dna_sequences'], alignment['introns']) alignment['variant_data_protein'] = calculate_variant_data('Protein', alignment['aligned_protein_sequences'], alignment['introns']) return json.dumps(alignment) return None
def alignment_bioent(self, locus_identifier=None, strain_ids=None, are_ids=False): import view_sequence from src.sgd.backend import calculate_variant_data if are_ids: locus_id = locus_identifier else: locus_id = None if locus_identifier is None else get_obj_id(locus_identifier, class_type='BIOENTITY', subclass_type='LOCUS') alignment = json.dumps(view_sequence.make_alignment(locus_id=locus_id)) if strain_ids is None: return alignment else: try: strain_ids = [int(strain_id) for strain_id in strain_ids] strain_ids.append(1) except Exception: return None alignment = json.loads(alignment) alignment['aligned_dna_sequences'] = [x for x in alignment['aligned_dna_sequences'] if x['strain_id'] in strain_ids] alignment['aligned_protein_sequences'] = [x for x in alignment['aligned_protein_sequences'] if x['strain_id'] in strain_ids] alignment['variant_data_dna'] = calculate_variant_data('DNA', alignment['aligned_dna_sequences'], alignment['introns']) alignment['variant_data_protein'] = calculate_variant_data('Protein', alignment['aligned_protein_sequences'], alignment['introns']) return json.dumps(alignment)
def make_alignment(locus_id=None): if locus_id is None: return {'Error': 'No locus_id given.'} evidences = get_alignment_evidence(locus_id=locus_id) if evidences is None: return {'Error': 'Too much data to display.'} try: locus = DBSession.query(Locus).filter_by(id=locus_id).first() obj_json = locus.to_min_json() dnasequenceevidence = DBSession.query(DNAsequenceevidence).filter_by(strain_id=1).filter_by(dna_type='GENOMIC').filter_by(locus_id=locus_id).first() if dnasequenceevidence is not None: obj_json['coordinates'] = { 'start': dnasequenceevidence.start, 'end': dnasequenceevidence.end, } obj_json['contig'] = dnasequenceevidence.contig.to_min_json() obj_json['strand'] = dnasequenceevidence.strand obj_json['introns'] = [] obj_json['dna_length'] = len(dnasequenceevidence.residues) proteinsequenceevidence = DBSession.query(Proteinsequenceevidence).filter_by(strain_id=1).filter_by(locus_id=locus_id).first() if proteinsequenceevidence is not None: obj_json['protein_length'] = len(proteinsequenceevidence.residues) #Alignment data alignment_evidences = get_alignment_evidence(locus_id=locus_id) if evidences is None: return {'Error': 'Too much data to display.'} ordered_strains = ['S288C', 'X2180-1A', 'SEY6210', 'W303', 'JK9-3d', 'FL100', 'CEN.PK', 'D273-10B', 'Sigma1278b', 'RM11-1a', 'SK1', 'Y55'] alignment_evidences.sort(key=lambda x: float('infinity') if x.strain.display_name not in ordered_strains else ordered_strains.index(x.strain.display_name)) reference_aligment = [x for x in alignment_evidences if x.sequence_type == 'Genomic DNA' and x.strain_id == 1][0] if dnasequenceevidence is not None: for tag in dnasequenceevidence.tags: if tag.class_type == 'INTRON': coords = switch_to_alignment_coord(reference_aligment.residues_with_gaps, [tag.relative_start, tag.relative_end]) obj_json['introns'].append({'start': coords[0], 'end': coords[1]}) obj_json['aligned_dna_sequences'] = [{'strain_id': x.strain_id, 'strain_display_name': x.strain.display_name, 'strain_link': x.strain.link, 'sequence': x.residues_with_gaps} for x in alignment_evidences if x.sequence_type == 'Genomic DNA'] obj_json['aligned_protein_sequences'] = [{'strain_id': x.strain_id, 'strain_display_name': x.strain.display_name, 'strain_link': x.strain.link, 'sequence': x.residues_with_gaps} for x in alignment_evidences if x.sequence_type == 'Protein'] obj_json['variant_data_dna'] = calculate_variant_data('DNA', obj_json['aligned_dna_sequences'], obj_json['introns']) obj_json['variant_data_protein'] = calculate_variant_data('Protein', obj_json['aligned_protein_sequences'], obj_json['introns']) except: print locus_id return obj_json