User:ShawnDouglas
From FreeBio
(Difference between revisions)
| Revision as of 04:19, 13 December 2005 ShawnDouglas (Talk | contribs) � Previous diff |
Revision as of 04:32, 13 December 2005 ShawnDouglas (Talk | contribs) Next diff → |
||
| Line 1: | Line 1: | ||
| - | '''ins-contig.pl''' - uses loop to insert random contigs via insert-contig.php | + | '''ins-contig.pl''' - inserts 1 contig |
| <pre> | <pre> | ||
| - | #!/usr/bin/perl -w | ||
| - | |||
| - | use strict; | ||
| - | use LWP::UserAgent; | ||
| - | |||
| - | my $ua = LWP::UserAgent->new; | ||
| - | |||
| - | my $group = "a"; | ||
| - | #my $group = "b"; | ||
| - | #my $group = "c"; | ||
| - | my $description = "foo"; | ||
| - | |||
| - | for (my $i = 100; $i < 110; $i++) { # insert 10 contigs | ||
| - | |||
| - | my $roll; | ||
| - | my $seq = ""; | ||
| - | |||
| - | for (my $j = 0; $j < 20; $j++) { # sequences 20 bp long | ||
| - | my $base; | ||
| - | $roll = int(rand 4) + 1; | ||
| - | if ($roll == 1) {$base = "A";} | ||
| - | elsif ($roll == 2) {$base = "T";} | ||
| - | elsif ($roll == 3) {$base = "C";} | ||
| - | elsif ($roll == 4) {$base = "G";} | ||
| - | $seq = $seq . "$base"; | ||
| - | } | ||
| - | |||
| - | #print "$i $seq\n"; | ||
| - | |||
| - | my $insert = 'http://personalgenome.org/101/insert-contig.php?'. | ||
| - | "group=$group". | ||
| - | "&id=$i". | ||
| - | "&sequence=$seq". | ||
| - | "&description=$description"; | ||
| - | |||
| - | my $req = HTTP::Request->new(GET => "$insert"); | ||
| - | $req->header(Accept => 'text/html'); | ||
| - | |||
| - | # send request to server and get response back | ||
| - | my $res = $ua->request($req); | ||
| - | |||
| - | # check the outcome | ||
| - | if ($res->is_success) { | ||
| - | print $res->content; # for instance | ||
| - | } else { | ||
| - | print "Error: " . $res->status_line . "\n"; | ||
| - | } | ||
| - | |||
| - | } | ||
| </pre> | </pre> | ||
| - | '''get-contig.pl''' - retrieves entire contents of contig table for specified group | + | '''get-contig.pl''' - gets 1 contig for specified id |
| - | + | ||
| <pre> | <pre> | ||
| - | #!/usr/bin/perl -w | ||
| - | |||
| - | use strict; | ||
| - | use LWP::UserAgent; | ||
| - | |||
| - | my $ua = LWP::UserAgent->new; | ||
| - | |||
| - | my $group = "a"; | ||
| - | #my $group = "b"; | ||
| - | #my $group = "c"; | ||
| - | |||
| - | my $query = "http://personalgenome.org/101/contig.php?group=$group"; | ||
| - | |||
| - | my $req = HTTP::Request->new(GET => "$query"); | ||
| - | $req->header(Accept => 'text/html'); | ||
| - | |||
| - | # send request to server and get response back | ||
| - | my $res = $ua->request($req); | ||
| - | |||
| - | # check the outcome | ||
| - | if ($res->is_success) { | ||
| - | print $res->content; # for instance | ||
| - | } else { | ||
| - | print "Error: " . $res->status_line . "\n"; | ||
| - | } | ||
| </pre> | </pre> | ||
| - | ---- | + | '''get-all-contig.pl''' - gets all contigs in the table |
| - | + | ||
| - | '''ins-subst.pl''' | + | |
| <pre> | <pre> | ||
| - | #!/usr/bin/perl -w | ||
| - | |||
| - | use strict; | ||
| - | use LWP::UserAgent; | ||
| - | |||
| - | my $ua = LWP::UserAgent->new; | ||
| - | |||
| - | my $group = "a"; # uncomment appropriate group | ||
| - | #my $group = "b"; | ||
| - | #my $group = "c"; | ||
| - | |||
| - | my $id; # unique identifier for substitution record (int) | ||
| - | my $genotype_id = 4; # placeholder to point to separate genotype table (int) | ||
| - | my $contig_id = "100"; # id of previously inserted contig (int) | ||
| - | my $pos = 0; # position of substitution (int) | ||
| - | my $base; # new base (A, T, C, G) (char) | ||
| - | |||
| - | for (my $i = 1; $i < 10; $i++) { # 10 subsitutions | ||
| - | |||
| - | my $roll = int(rand 4) + 1; | ||
| - | if ($roll == 1) {$base = "A";} | ||
| - | elsif ($roll == 2) {$base = "T";} | ||
| - | elsif ($roll == 3) {$base = "C";} | ||
| - | elsif ($roll == 4) {$base = "G";} | ||
| - | |||
| - | my $jump = int(rand 1000) + 1; # random distance to next position of substitution | ||
| - | $pos += $jump; | ||
| - | |||
| - | my $insert = 'http://personalgenome.org/101/insert-substitution.php?'. | ||
| - | "group=$group". | ||
| - | "&id=$i". # we use $i as the id | ||
| - | "&genotype_id=$genotype_id". | ||
| - | "&contig_id=$contig_id". | ||
| - | "&pos=$pos". | ||
| - | "&bp=$base"; | ||
| - | |||
| - | my $req = HTTP::Request->new(GET => "$insert"); | ||
| - | $req->header(Accept => 'text/html'); | ||
| - | |||
| - | # send request to server and get response back | ||
| - | my $res = $ua->request($req); | ||
| - | |||
| - | # check the outcome | ||
| - | if ($res->is_success) { | ||
| - | print $res->content; # for instance | ||
| - | } else { | ||
| - | print "Error: " . $res->status_line . "\n"; | ||
| - | } | ||
| - | |||
| - | } | ||
| - | |||
| </pre> | </pre> | ||
| - | '''get-subst.pl''' | + | '''ins-subst.pl''' - loops through insertions of substitutions |
| <pre> | <pre> | ||
| - | #!/usr/bin/perl -w | ||
| - | |||
| - | use strict; | ||
| - | use LWP::UserAgent; | ||
| - | |||
| - | my $ua = LWP::UserAgent->new; | ||
| - | |||
| - | my $group = "a"; | ||
| - | #my $group = "b"; | ||
| - | #my $group = "c"; | ||
| - | |||
| - | my $id = 3; # id of the substitution to retrieve | ||
| - | |||
| - | my $query = "http://personalgenome.org/101/substitution.php?group=$group&id=$id"; | ||
| - | |||
| - | my $req = HTTP::Request->new(GET => "$query"); | ||
| - | $req->header(Accept => 'text/html'); | ||
| - | |||
| - | # send request to server and get response back | ||
| - | my $res = $ua->request($req); | ||
| - | |||
| - | # check the outcome | ||
| - | if ($res->is_success) { | ||
| - | print $res->content; # for instance | ||
| - | } else { | ||
| - | print "Error: " . $res->status_line . "\n"; | ||
| - | } | ||
| </pre> | </pre> | ||
| - | + | '''get-subst.pl''' - gets substitution by id | |
| - | '''get-all-subst.pl''' | + | |
| <pre> | <pre> | ||
| - | #!/usr/bin/perl -w | ||
| - | |||
| - | use strict; | ||
| - | use LWP::UserAgent; | ||
| - | |||
| - | my $ua = LWP::UserAgent->new; | ||
| - | |||
| - | my $group = "a"; | ||
| - | #my $group = "b"; | ||
| - | #my $group = "c"; | ||
| - | |||
| - | my $id = 3; # id of the substitution to retrieve | ||
| - | |||
| - | my $query = "http://personalgenome.org/101/all-subst.php?group=$group"; | ||
| - | |||
| - | my $req = HTTP::Request->new(GET => "$query"); | ||
| - | $req->header(Accept => 'text/html'); | ||
| - | |||
| - | # send request to server and get response back | ||
| - | my $res = $ua->request($req); | ||
| - | |||
| - | # check the outcome | ||
| - | if ($res->is_success) { | ||
| - | print $res->content; # for instance | ||
| - | } else { | ||
| - | print "Error: " . $res->status_line . "\n"; | ||
| - | } | ||
| </pre> | </pre> | ||
| - | ---- | + | '''get-all-subst.pl''' - gets all substitutions |
| - | http://search.cpan.org/~gaas/libwww-perl-5.803/lib/LWP/UserAgent.pm | + | |
| - | + | ||
| - | '''client-query.pl''' | + | |
| <pre> | <pre> | ||
| - | #!/usr/bin/perl -w | ||
| - | |||
| - | use strict; | ||
| - | use LWP::UserAgent; | ||
| - | |||
| - | my $ua = LWP::UserAgent->new; | ||
| - | |||
| - | my $id = 5; | ||
| - | my $group = ""; | ||
| - | |||
| - | my $query = 'http://personalgenome.org/101/query.php?'. | ||
| - | "id=$id". | ||
| - | "&group=$group"; | ||
| - | |||
| - | print "query $query\n"; | ||
| - | |||
| - | |||
| - | my $req = HTTP::Request->new(GET => "$query"); | ||
| - | $req->header(Accept => 'text/html'); | ||
| - | |||
| - | # send request to server and get response back | ||
| - | my $res = $ua->request($req); | ||
| - | |||
| - | # check the outcome | ||
| - | if ($res->is_success) { | ||
| - | print $res->content; # for instance | ||
| - | } else { | ||
| - | print "Error: " . $res->status_line . "\n"; | ||
| - | } | ||
| </pre> | </pre> | ||
| - | |||
| - | '''client-insert.pl''' | ||
| - | <pre> | ||
| - | #!/usr/bin/perl -w | ||
| - | |||
| - | use strict; | ||
| - | use LWP::UserAgent; | ||
| - | |||
| - | my $ua = LWP::UserAgent->new; | ||
| - | |||
| - | my $genotype = 4; | ||
| - | my $contig = 1; | ||
| - | my $pos = 1; | ||
| - | my $bp = "a"; | ||
| - | my $id = 11; | ||
| - | my $group = ""; | ||
| - | |||
| - | my $insert = 'http://personalgenome.org/101/insert.php?'. | ||
| - | "genotype=$genotype". | ||
| - | "&contig=$contig". | ||
| - | "&pos=$pos". | ||
| - | "&bp=$bp". | ||
| - | "&group=$group". | ||
| - | "&id=$id"; | ||
| - | |||
| - | print "visiting url: $insert\n"; | ||
| - | |||
| - | my $req = HTTP::Request->new(GET => "$insert"); | ||
| - | $req->header(Accept => 'text/html'); | ||
| - | |||
| - | # send request to server and get response back | ||
| - | my $res = $ua->request($req); | ||
| - | |||
| - | # check the outcome | ||
| - | if ($res->is_success) { | ||
| - | print $res->content; # for instance | ||
| - | } else { | ||
| - | print "Error: " . $res->status_line . "\n"; | ||
| - | } | ||
| - | </pre> | ||
| - | |||
Revision as of 04:32, 13 December 2005
ins-contig.pl - inserts 1 contig
get-contig.pl - gets 1 contig for specified id
get-all-contig.pl - gets all contigs in the table
ins-subst.pl - loops through insertions of substitutions
get-subst.pl - gets substitution by id
get-all-subst.pl - gets all substitutions
#!/usr/bin/perl -w
use strict;
open (FILE, "<DNA");
my $seq = <FILE>;
close(FILE);
chomp $seq; # remove trailing newline
my $comp = reverse $seq;
$comp =~ tr/ATCG/TAGC/;
my $at = $seq;
$at =~ s/[AT]//g;
my $gc = 100 * length($at) / length($seq);
my $eco;
my $i = 0;
my $pos = 0;
for (;;) {
$i = index($seq, "GAATTC", $pos);
if ($i >= 0) {
$pos = $i + 1;
$eco .= " $i,";
} else {
last;
}
}
print "original sequence:\t$seq\n";
print "reverse complement:\t$comp\n";
printf "GC content:\t\t%.3f%%\n", $gc;
if ($eco) {
chop $eco;
print "EcoRI site(s) at index:$eco\n";
} else {
print "No EcoRI sites found.\n";
}
For info about me, here's a link to my website

