[Bio] / FigKernelScripts / reformat_circular_contigs.pl Repository:
ViewVC logotype

View of /FigKernelScripts/reformat_circular_contigs.pl

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.1 - (download) (as text) (annotate)
Thu Apr 16 22:34:22 2009 UTC (10 years, 10 months ago) by arodri7
Branch: MAIN
CVS Tags: mgrast_dev_08112011, rast_rel_2009_05_18, mgrast_dev_08022011, rast_rel_2014_0912, myrast_rel40, mgrast_dev_05262011, mgrast_dev_04082011, rast_rel_2010_0928, mgrast_version_3_2, mgrast_dev_12152011, mgrast_dev_06072011, rast_rel_2009_0925, rast_rel_2010_0526, rast_rel_2014_0729, mgrast_dev_02212011, rast_rel_2010_1206, mgrast_release_3_0, mgrast_dev_03252011, rast_rel_2010_0118, rast_rel_2011_0119, mgrast_release_3_0_4, mgrast_release_3_0_2, mgrast_release_3_0_3, mgrast_release_3_0_1, mgrast_dev_03312011, mgrast_release_3_1_2, mgrast_release_3_1_1, mgrast_release_3_1_0, mgrast_dev_04132011, mgrast_dev_04012011, rast_rel_2009_07_09, rast_rel_2010_0827, myrast_33, rast_rel_2011_0928, mgrast_dev_04052011, mgrast_dev_02222011, mgrast_dev_10262011, HEAD
added reformat_circular_contigs for rapid_propagation_plasmids

# -*- perl -*-
########################################################################
# Copyright (c) 2003-2006 University of Chicago and Fellowship
# for Interpretations of Genomes. All Rights Reserved.
#
# This file is part of the SEED Toolkit.
#
# The SEED Toolkit is free software. You can redistribute
# it and/or modify it under the terms of the SEED Toolkit
# Public License.
#
# You should have received a copy of the SEED Toolkit Public License
# along with this program; if not write to the University of Chicago
# at info@ci.uchicago.edu or the Fellowship for Interpretation of
# Genomes at veronika@thefig.info or download a copy from
# http://www.theseed.org/LICENSE.TXT.
########################################################################

use FIG;
use File::Basename;
use strict;
use Pod::Text;
use FIG_Config;

# This script works only for fasta files with one contig which is assumed to be circular
# This script will just double the size of the contig at the end of the original contig.

#my $contig_file = shift @ARGV;
my $usage = "reformat_circular_contig tmp_dir < input_fasta > output_fasta\n";

my $bin    = $FIG_Config::bin;
my ($seq,$contig_id);
my $tmp = shift @ARGV;
my $tmp_file = "$tmp/double_contig";
open (CONTIG, ">$tmp_file");
while (my $line = <STDIN>)
{
    if ($line =~ /^>/)
    {
	$contig_id = $line;
	print CONTIG $line;
    }
    else
    {
	chomp $line;
	$seq .= $line;
    }
}

# double the size of the contig
my $contig_length = length $seq;
$seq .= $seq;

# print the contig
print_fasta($seq,\*CONTIG);
close CONTIG;

# run the extract_metagene_contig tool
my $feature_mapF = "$tmp/tmp_contig.map";
my $fasta_tmp = "$tmp/tmp_contig.fasta";
system("$bin/extract_metagene_contigs -exec=mga -peg=T -AA=T -genome=tmp -featuremap=$feature_mapF -output-directory=$tmp $tmp_file $fasta_tmp >& $tmp/extract_metagene_contigs_circular.stderr");

# parse through the map file output
open (MAP, $feature_mapF);
my $contig_start;
while (my $line = <MAP>)
{
    chomp $line;
    my ($id, $feature) = split (/\t/, $line);
    my ($contig,$start,$end) = &FIG::boundaries_of($feature);

    # skip any features that start at the first 6 nucleotide of the sequence
    next if ( ($start <= 6) || ($end <= 6) );

    $contig_start = $start;
    if ($start > $end)
    {
	$contig_start = $end;
    }
    $contig_start = $contig_start-1;
    last;
}

my $new_contig = substr($seq,$contig_start,$contig_length);
print STDOUT $contig_id;
print_fasta($new_contig,\*STDOUT);



sub print_fasta {
    my ($seq,$fh) = @_;

    my $max = 50;
    my $count = 0;
    foreach my $nuc (split (//, $seq))
    {
	if ($count < $max)
	{
	    print $fh $nuc;
	    $count++;
	}
	else
	{
	    print $fh "\n$nuc";
	    $count = 0;
	}
    }
    print $fh "\n";
}

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3