Package: bioinfo_tools
# bioinfo_tools 0.3.1## Installation```bashpip install bioinfo_tools```## Parsers*HEADS UP!* These parsers are still under development and usage is not consistent from one parser to another.### Fasta parser```pythonfrom bioinfo_tools.parsers.fasta import FastaParserfasta_parser = FastaParser()# by default, sequence IDs are separated by the firstly found '|' or ':'for seqid, sequence in fasta_parser.read("/path/to/file.fasta"):print(seqid, sequence)# you may specify a specific separator for your sequence ID (e.g white space):for seqid, sequence in fasta_parser.read("/path/to/file.fasta", id_separator=" "):print(seqid, sequence)```### GFF parser```pythonfrom bioinfo_tools.parsers.gff import Gff3gff_parser = Gff3()with open("/path/to/file.gff", "r") as fh:for gene in gff_parser.read(fh):print(gene)import gzipwith gzip.open("/path/to/file.gz", "rb") as fh:for gene in gff_parser.read(fh):print(gene)```### OBO parser```pythonfrom bioinfo_tools.parsers.obo import OboParserobo_parser = OboParser()with open("/path/to/file.obo") as fh:go_terms = obo_parser.read(fh)for go_term in go_terms.values():print(go_term)# you may also get the GO term parents via the parserparents = obo_parser.get_parents(go_term)```## Usage Examples### Extract all introns sequences by parsing GFF and fasta filesIn this example, we focus on a genome assembly. We will first load a GFF file containing gene annotations for thisassembly, then load a fastA file containing the nucleic sequences of each chromosome in the genome.We will then collect all transcript introns and extract their nucleic sequences.**__DISCLAIMER__**: for this example to work, your GFF file must expose at least the following feature types in column #3:- `gene`- one of `transcript|mRNA|RNA` (or lowercased version)```pythonfrom bioinfo_tools.genomic_features.chromosome import Chromosomefrom bioinfo_tools.parsers.gff import Gff3from bioinfo_tools.parsers.fasta import FastaParserchromosomes = dict()  # {<chromosome_id>: <bioinfo_tools.genomic_features.Chromosome>}# start with parsing a GFF filegff_parser = Gff3()with open("/path/to/gene_models.gff", "r") as fh:for gene in gff_parser.read(fh):chromosome = gene['seqid']if chromosome not in chromosomes:chromosomes[chromosome] = Chromosome(chromosome)  # init a new Chromosome objectchromosomes[chromosome].add_gene(gene)  # add the current gene to our Chromosome object# load our chromosome sequences in memoryfasta_parser = FastaParser()for chromosome, nucleic_sequence in fasta_parser.read("/path/to/genome_chromosomes.fasta"):if chromosome not in chromosomes:chromosomes[chromosome] = Chromosome(chromosome)# attach parsed chromosome sequence to our Chromosome objectchromosomes[chromosome].attach_nucleic_sequence(nucleic_sequence)# now, collect introns and extact their nucleic sequenceintrons_sequences = dict()  #  {<intron_id>: <intron_sequence>}for chromosome in chromosomes.values():for gene in chromosome.genes:for transcript in gene.transcripts:for idx, intron in enumerate(transcript.introns):intron_id = "%s_intron_%s" % (transcript.transcript_id, idx)intron_seq = intron.extract(chromosome.nucleic_sequence)  # that we attached aboveintrons_sequences[intron_id] = intron_seq# from here, you can do what you want with the intron sequences (eg. write them to a fasta file, etc)# ...```__Note:__ when at the transcript level, you can grab its feature types as described in your GFF file by doing so:```pythonfor feature in transcript._get_features("exon"):print(feature)  # I'm an exon```For convenience and clarity, following properties are available on transcript objects:```pythonprint(transcript.introns)  # will call transcript._get_features('intron') behind the scenesprint(transcript.exons)  # will call transcript._get_features('exon') behind the scenesprint(transcript.cds)  # will call transcript._get_features('cds') behind the scenesprint(transcript.polypeptide)  # will call transcript._get_features('polypeptide') behind the scenesprint(transcript.five_prime_utr)  # will call transcript._get_features('five_prime_utr') behind the scenesprint(transcript.three_prime_utr)  # will call transcript._get_features('three_prime_utr') behind the scenes```