SEQanswers

Go Back   SEQanswers > Bioinformatics > Bioinformatics



Similar Threads
Thread Thread Starter Forum Replies Last Post
Searching tool to convert MACS output (chr + coordinates) into genomic feature SS Santos Epigenetics 2 04-17-2013 07:29 AM
gene name and position list in a chr* of a genome sirmark Bioinformatics 3 04-16-2013 02:49 AM
Problem with samtools view chr joe_stubbs Bioinformatics 6 07-09-2012 03:07 PM
convert hg19 to hg18, chr mismatch ahli1981 Bioinformatics 2 01-23-2012 07:39 AM
BOWTIE - match with empty chr and 0 position dukevn Bioinformatics 6 12-01-2009 12:22 PM

Reply
 
Thread Tools
Old 07-21-2013, 09:07 PM   #1
krafiq
Junior Member
 
Location: USA

Join Date: Jul 2013
Posts: 9
Default How to convert genoma.fa to chr*.fa

I am working with a genome file which is not on the USC genome browser. I have my own Genome.fa file and I want to separate the genome fasta file into chromosomes, so that there is one chr*.fa file for each chromosome.

Could someone please guide me as to how? I am just beginning to use Linux!

Thanks so much!
krafiq is offline   Reply With Quote
Old 07-21-2013, 11:50 PM   #2
SNPsaurus
Registered Vendor
 
Location: Eugene, OR

Join Date: May 2013
Posts: 422
Default

Hi krafiq,

Here is some Perl to do that. You just need to save it (as split.pl) to the folder you have your fasta file, then in the command line, write "perl split.pl genome.fa" where genome.fa is the name of your file. It will save a file for whatever is used as the header (I'm assuming it looks like ">chr1".

Code:
#!/usr/bin/perl

$f = $ARGV[0]; #get the file name

 open (INFILE, "<$f")
	or die "Can't open: $f $!";
		
while (<INFILE>) {
	$line = $_;
	chomp $line;
	if ($line =~ /\>/) { #if has fasta >
		close OUTFILE;
		$new_file = substr($line,1);
		$new_file .= ".fa";
		open (OUTFILE, ">$new_file")
			or die "Can't open: $new_file $!";
	}
	print OUTFILE "$line\n";
}
close OUTFILE;
__________________
Providing nextRAD genotyping and PacBio sequencing services. http://snpsaurus.com
SNPsaurus is offline   Reply With Quote
Old 07-22-2013, 12:18 AM   #3
krafiq
Junior Member
 
Location: USA

Join Date: Jul 2013
Posts: 9
Default

Dear SNPsaurus,

Thanks for your response! Howevr, my genome.fa file contains scaffold files and not chr files. So if I use your code above, it would create one file per scaffold. How do I get to one chr*.fa file for each chromosome from here?
krafiq is offline   Reply With Quote
Old 07-22-2013, 01:30 AM   #4
dpryan
Devon Ryan
 
Location: Freiburg, Germany

Join Date: Jul 2011
Posts: 3,476
Default

Do you mean to say that there are no ">chr..." lines in the Genome.fa file, only ">scaffold..." or something like that? If that's the case then there's no way to do it without assembling the scaffolds into chromosomes (which would take more sequencing and likely some wet-bench experiments).

If you mean to say that you have a mixture of ">chr..." and ">scaffold..." entries, then you can just modify the perl script above (just add a variable to store the context that you're in and only write output if you're in a ">chr..." context).
dpryan is offline   Reply With Quote
Old 07-22-2013, 02:40 PM   #5
krafiq
Junior Member
 
Location: USA

Join Date: Jul 2013
Posts: 9
Default

Dear dpryan,

I'm trying to use the hotspot software and I'm trying to run their enumerateUniquelyMappableSpace script on my custom genome file. However, we don't have chromosome information for my genome. The genome.fa file only has >scaffolds. Is there a way to run hotspot without separating the genome fasta file into chromosomes/obtaining chr*.fa for every chromosome?
krafiq is offline   Reply With Quote
Old 07-22-2013, 05:30 PM   #6
EricHaugen
Member
 
Location: Seattle, WA

Join Date: Sep 2009
Posts: 13
Default

Two options:

1. Change "chr" to "scaffold" in the enumerateUniquelyMappableSpace bash wrapper script, to list the individual fasta files.

2. Just run the whole genome fasta file, after building a bowtie index, with:

enumerateUniquelyMappableSpace.pl read_length bowtie_index_prefix genome.fa | sort-bed - | bedops -m - > genome.read_length.mappable_only.bed

If "sort-bed" runs out of memory here, the BEDOPS suite includes a "bbms" script that can be used in place of sort-bed.
EricHaugen is offline   Reply With Quote
Old 07-23-2013, 05:30 PM   #7
fengqi
Member
 
Location: US

Join Date: Aug 2012
Posts: 10
Default

Did you try
'samtools faidx genome.fasta chrX > chrX.fasta'
fengqi is offline   Reply With Quote
Old 07-23-2013, 07:17 PM   #8
krafiq
Junior Member
 
Location: USA

Join Date: Jul 2013
Posts: 9
Default

Thanks all!!

EricHaugen: I'm trying option 1 for now. I'm trying to run the script again with bowtie and bowtie-build in the same folder as the script. But it's giving me the following error:
./enumerateUniquelyMappableSpace: line 30: bowtie-build: command not found

And then it goes on to give the following error multiple times:
Failed to find bowtie index file Genome.1.ebwt

Does anyone know why and what I should change?

Thanks!

Last edited by krafiq; 07-25-2013 at 10:02 PM.
krafiq is offline   Reply With Quote
Old 07-23-2013, 08:23 PM   #9
EricHaugen
Member
 
Location: Seattle, WA

Join Date: Sep 2009
Posts: 13
Default

It looks like "bowtie-build" isn't in your PATH, so the shell couldn't find it.

Try adding a line near the top of "enumerateUniquelyMappableSpace" like:

export PATH=$PATH:/location/of/this/script/folder

Then it should be able to find bowtie-build, and the Perl script it calls later will be able to find your bowtie executable there also.
EricHaugen is offline   Reply With Quote
Old 07-23-2013, 09:02 PM   #10
sivasubramani
Member
 
Location: India

Join Date: Apr 2011
Posts: 14
Default

In HHblits package, there is a script which does the way you want.

HHblits_src/scripts/splitfasta.pl
sivasubramani is offline   Reply With Quote
Old 07-24-2013, 01:48 AM   #11
krafiq
Junior Member
 
Location: USA

Join Date: Jul 2013
Posts: 9
Default

My enumerateUniquelyMappableSpace script is calling this line:
bowtie-build $chromosomeFiles $genome

The chromosome files variable in this case is a list of 30,000 file names. So when I run the script, it gives me the following error:

Argument list too long

is there a way around this?
krafiq is offline   Reply With Quote
Old 07-24-2013, 01:52 AM   #12
dpryan
Devon Ryan
 
Location: Freiburg, Germany

Join Date: Jul 2011
Posts: 3,476
Default

Try concatenating the files together first (you'll have to do it in a couple batches, since the command will be too long for "cat" too) and just use the multifasta file.
dpryan is offline   Reply With Quote
Old 07-24-2013, 01:56 AM   #13
krafiq
Junior Member
 
Location: USA

Join Date: Jul 2013
Posts: 9
Default

dpryan: I had to split the genome.fa file to get the individual files in the first place to use the hotspot software. should i still cat them? won't that bring it back to genome.fa?
krafiq is offline   Reply With Quote
Old 07-24-2013, 02:13 AM   #14
dpryan
Devon Ryan
 
Location: Freiburg, Germany

Join Date: Jul 2011
Posts: 3,476
Default

Well, if you read through the perl scripts, it'll become pretty apparent that they only designed hotspot around human/mouse/etc. genomes (rather than your situation with scaffolds), so you're probably going to have to just edit the script. It's just trying to run bowtie-build, which will effectively concatentate everything together anyway (it looks like they normally use individual chromosome files so things can more easily be split to later run on a cluster). The script is pretty simple, so go ahead and change it to suite your usage needs.
dpryan is offline   Reply With Quote
Old 07-24-2013, 11:52 PM   #15
krafiq
Junior Member
 
Location: USA

Join Date: Jul 2013
Posts: 9
Default

dpryan: I'm sorry-could you please clarify a bit as to what exactly I should do?
Also, is there a way to get the source code for bowtie?
krafiq is offline   Reply With Quote
Old 07-25-2013, 12:09 AM   #16
krafiq
Junior Member
 
Location: USA

Join Date: Jul 2013
Posts: 9
Default

EricHaugen: What's the "bowtie_index_prefix" in the 2nd option you gave me above?
krafiq is offline   Reply With Quote
Old 07-25-2013, 01:15 AM   #17
dpryan
Devon Ryan
 
Location: Freiburg, Germany

Join Date: Jul 2011
Posts: 3,476
Default

Quote:
Originally Posted by krafiq View Post
dpryan: I'm sorry-could you please clarify a bit as to what exactly I should do?
Also, is there a way to get the source code for bowtie?
The source code for bowtie is available on its website here or here.

Regarding the remainder, enumerateUniquelyMappableSpace is just a perl script that executes a few other commands, some of which won't work for you because of how the script is structured. I already deleted the Hotspot code (I don't use it) so I can't immediately give you exact changes, but the gist is that you can just edit the code to have bowtie-build index genome.fa rather than a too-long list of scaffold.fa files. There may be a few other lines that will throw errors for similar reasons and you can likely use the same strategy. This all assumes that you know enough to edit a bit of code, of course.
dpryan is offline   Reply With Quote
Old 07-25-2013, 01:17 AM   #18
dpryan
Devon Ryan
 
Location: Freiburg, Germany

Join Date: Jul 2011
Posts: 3,476
Default

Quote:
Originally Posted by krafiq View Post
EricHaugen: What's the "bowtie_index_prefix" in the 2nd option you gave me above?
It's the prefix for the output index files, so it can be anything you want. Normal examples would be "hg19", "mm9" and "mm10", for human and two mouse genome versions. When bowtie is later invoked to do alignments, this same prefix is given to it so it knows what to align things against.
dpryan is offline   Reply With Quote
Old 07-25-2013, 10:03 PM   #19
krafiq
Junior Member
 
Location: USA

Join Date: Jul 2013
Posts: 9
Default

I just tried building a bowtie index using the genome.fa file (without splitting it) and it gave me 4 .ebwt files. And then I used the script:

./enumerateUniquelyMappableSpace.pl 50 Genome | sort-bed - | bedops -m - > Genome.50.mappable_only.bed

but it gave the following error:

Failed to read 50
Warning: Could not find any reads in "-"
# reads processed: 0
# reads with at least one reported alignment: 0 (0.00%)
# reads that failed to align: 0 (0.00%)
No alignments
krafiq is offline   Reply With Quote
Old 07-26-2013, 01:22 AM   #20
dpryan
Devon Ryan
 
Location: Freiburg, Germany

Join Date: Jul 2011
Posts: 3,476
Default

It's difficult to diagnose your problem when you use multiple pipes. Just run the enumerate command and save that to a file, then try the subsequent commands one at a time and then post which didn't work (probably sort-bed or bedops) and some of the input you're giving it.
dpryan is offline   Reply With Quote
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off




All times are GMT -8. The time now is 10:03 PM.


Powered by vBulletin® Version 3.8.9
Copyright ©2000 - 2017, vBulletin Solutions, Inc.
Single Sign On provided by vBSSO