Best Python code snippet using localstack_python
gtf.py
Source:gtf.py  
1import tests.util2def _format_attributes(attrs):3    formatted_pairs = list()4    for k, v in attrs:5        formatted_pairs.append(' '.join([k, tests.util.double_quote(v)]))6    return '; '.join(formatted_pairs)7def _group_transcripts_by_gene_id(transcripts):8    transcripts_by_gene_id = dict()9    for transcript in transcripts:10        gene_id = transcript.gene_id11        transcripts_for_gene_id = transcripts_by_gene_id.get(gene_id)12        if not transcripts_for_gene_id:13            transcripts_for_gene_id = list()14            transcripts_by_gene_id[gene_id] = transcripts_for_gene_id15        transcripts_for_gene_id.append(transcript)16    return transcripts_by_gene_id17def _get_lines_for_transcript(transcript, gene_id, gene_name, chromosome,18                              strand, score_placeholder, frame_placeholder):19    lines_for_transcript = list()20    trans_min_start, trans_max_end = transcript.exons[0]21    for exon_start, exon_end in transcript.exons:22        if exon_start < trans_min_start:23            trans_min_start = exon_start24        if exon_end > trans_max_end:25            trans_max_end = exon_end26        attributes = [('gene_id', gene_id),27                      ('transcript_id', transcript.transcript_id),28                      ('gene_name', gene_name)]29        formatted_attributes = _format_attributes(attributes)30        lines_for_transcript.append('\t'.join([31            chromosome,32            'processed_transcript',33            'exon',34            str(exon_start),35            str(exon_end),36            score_placeholder,37            strand,38            frame_placeholder,39            formatted_attributes,40        ]))41    attributes = [('gene_id', gene_id),42                  ('transcript_id', transcript.transcript_id),43                  ('gene_name', gene_name)]44    formatted_attributes = _format_attributes(attributes)45    lines_for_transcript.insert(46        0, '\t'.join([47            chromosome,48            'processed_transcript',49            'transcript',50            str(trans_min_start),51            str(trans_max_end),52            score_placeholder,53            strand,54            frame_placeholder,55            formatted_attributes,56        ]))57    return {58        'lines_for_transcript': lines_for_transcript,59        'trans_min_start': trans_min_start,60        'trans_max_end': trans_max_end61    }62def _write_lines_for_gene_id(f_handle, gene_id, transcripts):63    score_placeholder = '.'64    frame_placeholder = '.'65    lines_for_gene = list()66    gene_min_start = None67    gene_max_end = None68    gene_name = None69    chromosome = None70    strand = None71    for transcript in transcripts:72        gene_name = transcript.gene_name73        chromosome = transcript.chromosome74        strand = transcript.strand75        if not transcript.exons:76            return 'no exons in transcript'77        lines_for_transcript_result = _get_lines_for_transcript(78            transcript, gene_id, gene_name, chromosome, strand,79            score_placeholder, frame_placeholder)80        lines_for_transcript = lines_for_transcript_result[81            'lines_for_transcript']82        trans_min_start = lines_for_transcript_result['trans_min_start']83        trans_max_end = lines_for_transcript_result['trans_max_end']84        lines_for_gene.extend(lines_for_transcript)85        if gene_min_start is None or trans_min_start < gene_min_start:86            gene_min_start = trans_min_start87        if gene_max_end is None or trans_max_end > gene_max_end:88            gene_max_end = trans_max_end89    attributes = [('gene_id', gene_id), ('gene_name', gene_name)]90    formatted_attributes = _format_attributes(attributes)91    lines_for_gene.insert(92        0, '\t'.join([93            chromosome,94            'pseudogene',95            'gene',96            str(gene_min_start),97            str(gene_max_end),98            score_placeholder,99            strand,100            frame_placeholder,101            formatted_attributes,102        ]))103    for line in lines_for_gene:104        f_handle.write('{}\n'.format(line))...htmlbuilder.py
Source:htmlbuilder.py  
...20                self.contents.append(obj)21    def __str__(self):22        html = "<{}{}>{}</{}>".format(23            self.name,24            self._format_attributes(),25            self._format_contents(),26            self.name,27        )28        if self.pretty:29            return BeautifulSoup(html, features="html.parser").prettify()30        return html31    def _format_attributes(self):32        string = "".join(33            ' {}="{}"'.format(attr, val) for attr, val in zip(34                self.attributes.keys(), self.attributes.values()35            )36        )37        return string38    def _format_contents(self):39        string = "".join(str(item) for item in self.contents)40        return string41    def add(self, item_list):42        """add an element to this tag."""...Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!
