Here are the examples of the python api django.template.loader.render_to_string.split taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.
3 Examples
0
View Complete Implementation : views.py
Copyright Apache License 2.0
Author : protwis
Copyright Apache License 2.0
Author : protwis
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)
0
View Complete Implementation : views.py
Copyright Apache License 2.0
Author : protwis
Copyright Apache License 2.0
Author : protwis
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
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 API into the alignment
a.load_reference_protein(reference[0])
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 idensaty 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].idensaty = 100
a.proteins[num].similarity = 100
# order dict after custom list
keyorder = ["similarity","idensaty","AA"]
ali_dict[k] = {"AA": row, "idensaty": int(str(a.proteins[num].idensaty).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)
0
View Complete Implementation : views.py
Copyright Apache License 2.0
Author : protwis
Copyright Apache License 2.0
Author : protwis
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
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:
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()
# 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)