Git Product home page Git Product logo

cquence's Introduction

CQuence

CQuence is a very simple library for handling biological sequences.

##Installation
Clone the repository and install:

git clone https://github.com/shintoo/CQuence.git
cd CQuence
make
sudo make install

###Uninstall

sudo make uninstall

To update from a previous version, uninstall, clone, and reinstall.

Link the library to your programs with -lcq at compile time.

Interface

CQuence interacts with sequences stored in the FASTA file format.

Function examples

#include <cq/cq.h>

Seq *seq;
FILE *fin = fopen("infile", "r");
FILE *fout = fopen("outfile", "w");

/* Read a sequence from a fasta file */
seq = Seq_read_fasta(fin);

/* Write a sequence to a fasta file */
Seq_write_fasta(seq, fout);

/* Create a new sequence from scratch */
Seq *dna = Seq_new("DNA");
Seq *rna = Seq_new("RNA");
Seq *protein = Seq_new("protein");

/* Set a sequence ID */
Seq_set_id(dna, "dna_ID");

/* Set a sequence description */
Seq_set_description(seq, "dna description");

/* Set a sequence string */
Seq_set_string(dna, "ACTGACTG");

/* Get a sequence ID */
char *id;
id = Seq_get_id(seq);

/* Get a sequence description */
char *description;
description = Seq_get_description(seq);

/* Get a sequence string */
char *string;
string = Seq_get_string(seq);

/* Transcribe a sequence */
rna = Seq_transcribe(dna);

/* Translate a DNA sequence */
protein = Seq_translate(dna);

/* Translate an RNA sequence */
protein = Seq_translate(rna);

/* Get the GC content of a DNA or RNA sequence */
double dna_gc;
dna_gc = Seq_gc(dna);

/* Get the reverse complement of a DNA sequence */
Seq * dna_revc;
dna_revc = Seq_complement(dna);  

/* Delete a sequence from memory */
Seq_delete(seq)

Example Program

#include <stdio.h>
#include <cq/cq.h>

int main(int argc, char **argv) {
	FILE *infasta = fopen(argv[1], "r");
	FILE *outfasta = fopen(argv[2], "w");
	Seq *dna;
	Seq *rna;
	Seq *protein1;
	Seq *protein2;
	Seq *newdna;
	Seq *newdna_revc;

	/* Read a sequence from a fasta */
	dna = Seq_read_fasta(infasta);

	/* Transcribe DNA to RNA */
	rna = Seq_transcribe(dna);
	
	/* Translate from RNA to protein */
	protein1 = Seq_translate(rna);

	/* Translate from DNA to protein */
	protein2 = Seq_translate(dna);

	/* Change the ID and description of rna and proteins.     */
	/* ID and description default to the ID and description   */
	/* of the sequences they were transcribed/translated from.*/
	Seq_set_id(rna, "sample_rna");
	Seq_set_description(rna, "sample rna description");

	Seq_set_id(protein1, "sample_protein1");
	Seq_set_description(protein1, "sample protein1 description");

	Seq_set_id(protein2, "sample_protein2");
	Seq_set_description(protein2, "sample protein2 description");

	/* write RNA and protein to fasta file */
	Seq_write_fasta(rna, outfasta);
	Seq_write_fasta(protein1, outfasta);

	/* Create new DNA sequence */
	newdna = Seq_new("DNA");
	Seq_set_id(newdna, "sample2_dna");
	Seq_set_description(newdna, "sample2 dna description");
	Seq_set_string(newdna, "ACATGTCGA");

	/* Write newdna to fastaout */
	Seq_write_fasta(newdna, outfasta);

	/* Create a reverse complement of newdna */
	newdna_revc = Seq_complement(newdna);
	Seq_set_id(newdna_revc, "sample2_dna_reverse_complement");
	Seq_set_description(newdna_revc, "sample2 dna reverse complement description");
	Seq_write_fasta(newdna_revc, outfasta);
	
	/* Clean up */
	Seq_delete(dna);
	Seq_delete(rna);
	Seq_delete(protein1);
	Seq_delete(protein2);
	Seq_delete(newdna);
	Seq_delete(newdna_revc);
	fclose(infasta);
	fclose(outfasta);
	
	return 0;
}  

With the input file:

>sample_id sample description
TGTCAGAATTGTATTTCAGGCCGAGAAGCCACTACTGCCGAACGAGGCTCAATTTGTAAT
CAGTGTATACACCCTATAACTATTTCTCTTATTAAGGAAGACGCTAACGACACTCATGCT
ACCATTTGTGCTAATATGGCCAAGGAACGTGAAGCTCTTCTATACGGTCGTGAAGCTACT

Creates the output file:

>sample_rna sample rna description
UGUCAGAAUUGUAUUUCAGGCCGAGAAGCCACUACUGCCGAACGAGGCUCAAUUUGUAAU
CAGUGUAUACACCCUAUAACUAUUUCUCUUAUUAAGGAAGACGCUAACGACACUCAUGCU
ACCAUUUGUGCUAAUAUGGCCAAGGAACGUGAAGCUCUUCUAUACGGUCGUGAAGCUACU
>sample_protein1 sample protein1 description
CQNCISGREATTAERGSICNQCIHPITISLIKEDANDTHATICANMAKEREALLYGREAT
>sample2_dna sample2 dna description
ACATGTCGA
>sample2_dna_reverse_complement sample2 dna reverse complement description
TCGACATGT  

cquence's People

Contributors

shintoo avatar

Stargazers

 avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.