def get(self, request, entry_name=None, segments=None): if entry_name is not None: ref = Protein.objects.get(sequence_type__slug='wt', entry_name=entry_name) structures = Structure.objects.order_by('protein_conformation__protein__parent', 'state', 'resolution').distinct('protein_conformation__protein__parent', 'state') ps = [] for structure in structures: ps.append(structure.protein_conformation.protein.parent) if segments is not None: input_list = segments.split(",") ss = ProteinSegment.objects.filter(slug__in=input_list, partial=False) else: ss = ProteinSegment.objects.filter(partial=False, category='helix') # create an alignment object a = Alignment() a.show_padding = False # load data from selection into the alignment a.load_reference_protein(ref) a.load_proteins(ps) a.load_segments(ss) # build the alignment data matrix a.build_alignment() # calculate identity and similarity of each row compared to the reference a.calculate_similarity() # return the entry_name of the closest template return Response(a.proteins[1].protein.entry_name)
def get(self, request, slug=None, segments=None): if slug is not None: ps = Protein.objects.filter(sequence_type__slug='wt', source__id=1, family__slug__startswith=slug) if segments is not None: segment_list = segments.split(",") ss = ProteinSegment.objects.filter(slug__in=segment_list, partial=False) else: ss = ProteinSegment.objects.filter(partial=False) # create an alignment object a = Alignment() a.show_padding = False # load data from selection into the alignment a.load_proteins(ps) a.load_segments(ss) # build the alignment data matrix a.build_alignment() # render the fasta template as string response = render_to_string('alignment/alignment_fasta.html', {'a': a}).split("\n") # convert the list to a dict ali_dict = {} for row in response: if row.startswith(">"): k = row[1:] else: ali_dict[k] = row k = False return Response(ali_dict)
def get(self, request, proteins=None, segments=None): if proteins is not None: protein_list = proteins.split(",") ps = Protein.objects.filter( entry_name__in=protein_list) if segments is not None: segment_list = segments.split(",") ss = ProteinSegment.objects.filter(slug__in=segment_list, partial=False) else: ss = ProteinSegment.objects.filter(partial=False) # create an alignment object a = Alignment() a.show_padding = False # load data from selection into the alignment a.load_proteins(ps) a.load_segments(ss) # build the alignment data matrix a.build_alignment() # render the fasta template as string #response = render_to_string('alignment/alignment_fasta.html', {'a': a}).split("\n") # convert the list to a dict ali_dict = {} k = False num_of_sequences = len(a.proteins) num_residue_columns = len(a.positions) + len(a.segments) renderer_classes = (StaticHTMLRenderer,) response = render(request, 'alignment/alignment_ws.html', {'a': a, 'num_of_sequences': num_of_sequences,'num_residue_columns': num_residue_columns}) response['X-Frame-Options'] = "ALLOWALL" # for row in response: # if row.startswith(">"): # k = row[1:] # elif k: # ali_dict[k] = row # k = False #return Response(ali_dict) return response
def get(self, request, proteins=None, segments=None): if proteins is not None: protein_list = proteins.split(",") ps = Protein.objects.filter(sequence_type__slug='wt', entry_name__in=protein_list) if segments is not None: segment_list = segments.split(",") ss = ProteinSegment.objects.filter(slug__in=segment_list, partial=False) else: ss = ProteinSegment.objects.filter(partial=False) # create an alignment object a = Alignment() a.show_padding = False # load data from selection into the alignment a.load_proteins(ps) a.load_segments(ss) # build the alignment data matrix a.build_alignment() # render the fasta template as string response = render_to_string('alignment/alignment_fasta.html', { 'a': a }).split("\n") # convert the list to a dict ali_dict = {} k = False for row in response: if row.startswith(">"): k = row[1:] elif k: ali_dict[k] = row k = False return Response(ali_dict)
def get(self, request, entry_name=None, segments=None): if entry_name is not None: ref = Protein.objects.get(sequence_type__slug='wt', entry_name=entry_name) structures = Structure.objects.order_by( 'protein_conformation__protein__parent', 'state', 'resolution').distinct('protein_conformation__protein__parent', 'state') ps = [] for structure in structures: ps.append(structure.protein_conformation.protein.parent) if segments is not None: input_list = segments.split(",") ss = ProteinSegment.objects.filter(slug__in=input_list, partial=False) else: ss = ProteinSegment.objects.filter(partial=False, category='helix') # create an alignment object a = Alignment() a.show_padding = False # load data from selection into the alignment a.load_reference_protein(ref) a.load_proteins(ps) a.load_segments(ss) # build the alignment data matrix a.build_alignment() # calculate identity and similarity of each row compared to the reference a.calculate_similarity() # return the entry_name of the closest template return Response(a.proteins[1].protein.entry_name)
def get(self, request, proteins=None, segments=None, statistics=False): if proteins is not None: protein_list = proteins.split(",") ps = Protein.objects.filter(sequence_type__slug='wt', entry_name__in=protein_list) # take the numbering scheme from the first protein s_slug = Protein.objects.get( entry_name=protein_list[0]).residue_numbering_scheme_id gen_list = [] segment_list = [] if segments is not None: input_list = segments.split(",") # fetch a list of all segments protein_segments = ProteinSegment.objects.filter( partial=False).values_list('slug', flat=True) for s in input_list: # add to segment list if s in protein_segments: segment_list.append(s) # get generic numbering object for generic positions else: gen_object = ResidueGenericNumberEquivalent.objects.get( label=s, scheme__id=s_slug) gen_object.properties = {} gen_list.append(gen_object) # fetch all complete protein_segments ss = ProteinSegment.objects.filter(slug__in=segment_list, partial=False) else: ss = ProteinSegment.objects.filter(partial=False) # create an alignment object a = Alignment() a.show_padding = False # load data from selection into the alignment a.load_proteins(ps) # load generic numbers and TMs seperately if gen_list: a.load_segments(gen_list) a.load_segments(ss) # build the alignment data matrix a.build_alignment() # calculate statistics if statistics == True: a.calculate_statistics() # render the fasta template as string response = render_to_string('alignment/alignment_fasta.html', { 'a': a }).split("\n") # convert the list to a dict ali_dict = {} k = False for row in response: if row.startswith(">"): k = row[1:] elif k: ali_dict[k] = row k = False # render statistics for output if statistics == True: feat = {} for i, feature in enumerate(AMINO_ACID_GROUPS): feature_stats = a.feature_stats[i] feature_stats_clean = [] for d in feature_stats: sub_list = [x[0] for x in d] feature_stats_clean.append( sub_list) # remove feature frequencies # print(feature_stats_clean) feat[feature] = [ item for sublist in feature_stats_clean for item in sublist ] for i, AA in enumerate(AMINO_ACIDS): feature_stats = a.amino_acid_stats[i] feature_stats_clean = [] for d in feature_stats: sub_list = [x[0] for x in d] feature_stats_clean.append( sub_list) # remove feature frequencies # print(feature_stats_clean) feat[AA] = [ item for sublist in feature_stats_clean for item in sublist ] ali_dict["statistics"] = feat return Response(ali_dict)
def get(self, request, proteins=None, segments=None): if proteins is not None: protein_list = proteins.split(",") # first in API should be reference ps = Protein.objects.filter(sequence_type__slug='wt', entry_name__in=protein_list[1:]) reference = Protein.objects.filter( sequence_type__slug='wt', entry_name__in=[protein_list[0]]) # take the numbering scheme from the first protein s_slug = Protein.objects.get( entry_name=protein_list[0]).residue_numbering_scheme_id if segments is not None: input_list = segments.split(",") # fetch a list of all segments protein_segments = ProteinSegment.objects.filter( partial=False).values_list('slug', flat=True) gen_list = [] segment_list = [] for s in input_list: # add to segment list if s in protein_segments: segment_list.append(s) # get generic numbering object for generic positions else: # make sure the query works for all positions gen_object = ResidueGenericNumberEquivalent.objects.get( label=s, scheme__id=s_slug) gen_object.properties = {} gen_list.append(gen_object) # fetch all complete protein_segments ss = ProteinSegment.objects.filter(slug__in=segment_list, partial=False) # create an alignment object a = Alignment() a.show_padding = False # load data from API into the alignment a.load_reference_protein(reference) a.load_proteins(ps) # load generic numbers and TMs seperately a.load_segments(gen_list) a.load_segments(ss) # build the alignment data matrix a.build_alignment() # calculate identity and similarity of each row compared to the reference a.calculate_similarity() # render the fasta template as string response = render_to_string('alignment/alignment_fasta.html', { 'a': a }).split("\n") # convert the list to a dict ali_dict = {} k = False num = 0 for i, row in enumerate(response): if row.startswith(">"): k = row[1:] elif k: # add the query as 100 identical/similar to the beginning (like on the website) if num == 0: a.proteins[num].identity = 100 a.proteins[num].similarity = 100 # order dict after custom list keyorder = ["similarity", "identity", "AA"] ali_dict[k] = { "AA": row, "identity": int(str(a.proteins[num].identity).replace(" ", "")), "similarity": int(str(a.proteins[num].similarity).replace(" ", "")) } ali_dict[k] = OrderedDict( sorted(ali_dict[k].items(), key=lambda t: keyorder.index(t[0]))) num += 1 k = False ali_dict_ordered = OrderedDict( sorted(ali_dict.items(), key=lambda x: x[1]['similarity'], reverse=True)) return Response(ali_dict_ordered)
def get(self, request, proteins=None, segments=None, statistics=False): if proteins is not None: protein_list = proteins.split(",") ps = Protein.objects.filter(sequence_type__slug='wt', entry_name__in=protein_list) # take the numbering scheme from the first protein s_slug = Protein.objects.get(entry_name=protein_list[0]).residue_numbering_scheme_id gen_list = [] segment_list = [] if segments is not None: input_list = segments.split(",") # fetch a list of all segments protein_segments = ProteinSegment.objects.filter(partial=False).values_list('slug', flat=True) for s in input_list: # add to segment list if s in protein_segments: segment_list.append(s) # get generic numbering object for generic positions else: gen_object = ResidueGenericNumberEquivalent.objects.get(label=s, scheme__id=s_slug) gen_object.properties = {} gen_list.append(gen_object) # fetch all complete protein_segments ss = ProteinSegment.objects.filter(slug__in=segment_list, partial=False) else: ss = ProteinSegment.objects.filter(partial=False) # create an alignment object a = Alignment() a.show_padding = False # load data from selection into the alignment a.load_proteins(ps) # load generic numbers and TMs seperately if gen_list: a.load_segments(gen_list) a.load_segments(ss) # build the alignment data matrix a.build_alignment() # calculate statistics if statistics == True: a.calculate_statistics() # render the fasta template as string response = render_to_string('alignment/alignment_fasta.html', {'a': a}).split("\n") # convert the list to a dict ali_dict = {} k = False for row in response: if row.startswith(">"): k = row[1:] elif k: ali_dict[k] = row k = False # render statistics for output if statistics == True: feat = {} for i, feature in enumerate(AMINO_ACID_GROUPS): feature_stats = a.feature_stats[i] feature_stats_clean = [] for d in feature_stats: sub_list = [x[0] for x in d] feature_stats_clean.append(sub_list) # remove feature frequencies # print(feature_stats_clean) feat[feature] = [item for sublist in feature_stats_clean for item in sublist] for i, AA in enumerate(AMINO_ACIDS): feature_stats = a.amino_acid_stats[i] feature_stats_clean = [] for d in feature_stats: sub_list = [x[0] for x in d] feature_stats_clean.append(sub_list) # remove feature frequencies # print(feature_stats_clean) feat[AA] = [item for sublist in feature_stats_clean for item in sublist] ali_dict["statistics"] = feat return Response(ali_dict)
def get(self, request, proteins=None, segments=None): if proteins is not None: protein_list = proteins.split(",") # first in API should be reference ps = Protein.objects.filter(sequence_type__slug='wt', entry_name__in=protein_list[1:]) reference = Protein.objects.filter(sequence_type__slug='wt', entry_name__in=[protein_list[0]]) # take the numbering scheme from the first protein s_slug = Protein.objects.get(entry_name=protein_list[0]).residue_numbering_scheme_id if segments is not None: input_list = segments.split(",") # fetch a list of all segments protein_segments = ProteinSegment.objects.filter(partial=False).values_list('slug', flat=True) gen_list = [] segment_list = [] for s in input_list: # add to segment list if s in protein_segments: segment_list.append(s) # get generic numbering object for generic positions else: # make sure the query works for all positions gen_object = ResidueGenericNumberEquivalent.objects.get(label=s, scheme__id=s_slug) gen_object.properties = {} gen_list.append(gen_object) # fetch all complete protein_segments ss = ProteinSegment.objects.filter(slug__in=segment_list, partial=False) # create an alignment object a = Alignment() a.show_padding = False # load data from API into the alignment a.load_reference_protein(reference) a.load_proteins(ps) # load generic numbers and TMs seperately a.load_segments(gen_list) a.load_segments(ss) # build the alignment data matrix a.build_alignment() # calculate identity and similarity of each row compared to the reference a.calculate_similarity() # render the fasta template as string response = render_to_string('alignment/alignment_fasta.html', {'a': a}).split("\n") # convert the list to a dict ali_dict = {} k = False num = 0 for i, row in enumerate(response): if row.startswith(">"): k = row[1:] elif k: # add the query as 100 identical/similar to the beginning (like on the website) if num == 0: a.proteins[num].identity = 100 a.proteins[num].similarity = 100 # order dict after custom list keyorder = ["similarity","identity","AA"] ali_dict[k] = {"AA": row, "identity": int(str(a.proteins[num].identity).replace(" ","")), "similarity": int(str(a.proteins[num].similarity).replace(" ",""))} ali_dict[k] = OrderedDict(sorted(ali_dict[k].items(), key=lambda t: keyorder.index(t[0]))) num+=1 k = False ali_dict_ordered = OrderedDict(sorted(ali_dict.items(), key=lambda x: x[1]['similarity'], reverse=True)) return Response(ali_dict_ordered)
def get(self, request, slug=None, segments=None, latin_name=None, statistics=False): if slug is not None: # Check for specific species if latin_name is not None: ps = Protein.objects.filter(sequence_type__slug='wt', source__id=1, family__slug__startswith=slug, species__latin_name=latin_name) else: ps = Protein.objects.filter(sequence_type__slug='wt', source__id=1, family__slug__startswith=slug) # take the numbering scheme from the first protein #s_slug = Protein.objects.get(entry_name=ps[0]).residue_numbering_scheme_id s_slug = ps[0].residue_numbering_scheme_id protein_family = ps[0].family.slug[:3] gen_list = [] segment_list = [] if segments is not None: input_list = segments.split(",") # fetch a list of all segments protein_segments = ProteinSegment.objects.filter( partial=False).values_list('slug', flat=True) for s in input_list: # add to segment list if s in protein_segments: segment_list.append(s) # get generic numbering object for generic positions else: # make sure the query works for all positions gen_object = ResidueGenericNumberEquivalent.objects.get( label=s, scheme__id=s_slug) gen_object.properties = {} gen_list.append(gen_object) # fetch all complete protein_segments ss = ProteinSegment.objects.filter(slug__in=segment_list, partial=False) else: ss = ProteinSegment.objects.filter(partial=False) if int(protein_family) < 100: ss = [s for s in ss if s.proteinfamily == 'GPCR'] elif protein_family == "100": ss = [s for s in ss if s.proteinfamily == 'Gprotein'] elif protein_family == "200": ss = [s for s in ss if s.proteinfamily == 'Arrestin'] # create an alignment object a = Alignment() a.show_padding = False # load data from selection into the alignment a.load_proteins(ps) # load generic numbers and TMs seperately if gen_list: a.load_segments(gen_list) a.load_segments(ss) # build the alignment data matrix a.build_alignment() a.calculate_statistics() residue_list = [] for aa in a.full_consensus: residue_list.append(aa.amino_acid) # render the fasta template as string response = render_to_string('alignment/alignment_fasta.html', { 'a': a }).split("\n") # convert the list to a dict ali_dict = OrderedDict({}) for row in response: if row.startswith(">"): k = row[1:] else: ali_dict[k] = row k = False ali_dict['CONSENSUS'] = ''.join(residue_list) # render statistics for output if statistics == True: feat = {} for i, feature in enumerate(AMINO_ACID_GROUPS): feature_stats = a.feature_stats[i] feature_stats_clean = [] for d in feature_stats: sub_list = [x[0] for x in d] feature_stats_clean.append( sub_list) # remove feature frequencies # print(feature_stats_clean) feat[feature] = [ item for sublist in feature_stats_clean for item in sublist ] for i, AA in enumerate(AMINO_ACIDS): feature_stats = a.amino_acid_stats[i] feature_stats_clean = [] for d in feature_stats: sub_list = [x[0] for x in d] feature_stats_clean.append( sub_list) # remove feature frequencies # print(feature_stats_clean) feat[AA] = [ item for sublist in feature_stats_clean for item in sublist ] ali_dict["statistics"] = feat return Response(ali_dict)
def get(self, request, slug=None, segments=None, latin_name=None, statistics=False): if slug is not None: # Check for specific species if latin_name is not None: ps = Protein.objects.filter(sequence_type__slug='wt', source__id=1, family__slug__startswith=slug, species__latin_name=latin_name) else: ps = Protein.objects.filter(sequence_type__slug='wt', source__id=1, family__slug__startswith=slug) # take the numbering scheme from the first protein #s_slug = Protein.objects.get(entry_name=ps[0]).residue_numbering_scheme_id s_slug = ps[0].residue_numbering_scheme_id protein_family = ps[0].family.slug[:3] gen_list = [] segment_list = [] if segments is not None: input_list = segments.split(",") # fetch a list of all segments protein_segments = ProteinSegment.objects.filter(partial=False).values_list('slug', flat=True) for s in input_list: # add to segment list if s in protein_segments: segment_list.append(s) # get generic numbering object for generic positions else: # make sure the query works for all positions gen_object = ResidueGenericNumberEquivalent.objects.get(label=s, scheme__id=s_slug) gen_object.properties = {} gen_list.append(gen_object) # fetch all complete protein_segments ss = ProteinSegment.objects.filter(slug__in=segment_list, partial=False) else: ss = ProteinSegment.objects.filter(partial=False) if int(protein_family) < 100: ss = [ s for s in ss if s.proteinfamily == 'GPCR'] elif protein_family == "100": ss = [ s for s in ss if s.proteinfamily == 'Gprotein'] elif protein_family == "200": ss = [ s for s in ss if s.proteinfamily == 'Arrestin'] # create an alignment object a = Alignment() a.show_padding = False # load data from selection into the alignment a.load_proteins(ps) # load generic numbers and TMs seperately if gen_list: a.load_segments(gen_list) a.load_segments(ss) # build the alignment data matrix a.build_alignment() a.calculate_statistics() residue_list = [] for aa in a.full_consensus: residue_list.append(aa.amino_acid) # render the fasta template as string response = render_to_string('alignment/alignment_fasta.html', {'a': a}).split("\n") # convert the list to a dict ali_dict = OrderedDict({}) for row in response: if row.startswith(">"): k = row[1:] else: ali_dict[k] = row k = False ali_dict['CONSENSUS'] = ''.join(residue_list) # render statistics for output if statistics == True: feat = {} for i, feature in enumerate(AMINO_ACID_GROUPS): feature_stats = a.feature_stats[i] feature_stats_clean = [] for d in feature_stats: sub_list = [x[0] for x in d] feature_stats_clean.append(sub_list) # remove feature frequencies # print(feature_stats_clean) feat[feature] = [item for sublist in feature_stats_clean for item in sublist] for i, AA in enumerate(AMINO_ACIDS): feature_stats = a.amino_acid_stats[i] feature_stats_clean = [] for d in feature_stats: sub_list = [x[0] for x in d] feature_stats_clean.append(sub_list) # remove feature frequencies # print(feature_stats_clean) feat[AA] = [item for sublist in feature_stats_clean for item in sublist] ali_dict["statistics"] = feat return Response(ali_dict)