Created
December 24, 2013 02:49
-
-
Save kos59125/8108152 to your computer and use it in GitHub Desktop.
マルチファスタファイルを個別に分割する。各ファスタファイル名は ID ベースで作成される。ファイル名に使えない文字の例外処理などは行わない。
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| >gene_a | |
| CTAGCTAGTCTAGCTATCTATCGTATCGTAGCTGATGCTAGTCGTAGCTGATCGTAGCTG | |
| ATGCTGTAGCGATGCTGATCGTAGCTGATCGTAGCTGATCGTAGCTGATCGTAGCTGATC | |
| GTAGCTGATCGTAGCTAGTCGATGTGTGTGTGGGGGCGCGCCGGCGCGGCGC | |
| >gene_b | |
| TGACTGATGCTATACGACGATGCTAGCTACGTAGCTAGCTAGCTAGCTGATGAATATATT | |
| TATTTCTGCTAGCTATAGCTGATGCTAGTCGTAGTGGGGGCTAGCTAGTCGTAGCTAGTC | |
| GTAGTCGTAGCTGATGAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA | |
| AAAAA | |
| >gene_c | |
| CGATGCTATTTTTTTTTTTTTTTTTTTCCCCCCCCCCCCCAAAAAAAAGCTGTAGCTAGC | |
| ATCTATCTACTATCGTATCACTGACGGCGGCGCGGCGCGCGGGCCGGAGAGCGGACGTCA | |
| TACGTCAGTACTGTCAGTCAGTACTGCAGTACGTCGTGTCGTAGTCATGACTGTACGTGT | |
| AGCACGTCGTACGTACGTCGAGCGAGCTGATTCGATCTGATCTGATTCGTAGCGGCGTGC | |
| GCGATCGTAGCTATCGATGCTGATCGAGCTGAACTGGTACTCTGGTAGCTAGCTAGCTTG | |
| ACGTCATGTACGTCATGTCAGTCAGTACTGTCAGTACGTACTGACTGACGGTCAGTACG |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Install .NET Bio to run. | |
| // http://bio.codeplex.com/ | |
| #if INTERACTIVE | |
| #r "C:/Program Files (x86)/.NET Bio/1.1/Tools/Bin/Bio.dll" | |
| #endif | |
| open System.IO | |
| open Bio.IO.FastA | |
| let split (inputFasta:string) outputDir = | |
| use parser = new FastAParser () | |
| use reader = new StreamReader (inputFasta) | |
| if not (Directory.Exists (outputDir)) then | |
| Directory.CreateDirectory (outputDir) |> ignore | |
| for sequence in parser.Parse (reader) do | |
| use formatter = new FastAFormatter () | |
| let output = Path.Combine (outputDir, sprintf "%s.fasta" sequence.ID) | |
| formatter.Open (output) | |
| formatter.Write (sequence) | |
| formatter.Close () | |
| #if INTERACTIVE | |
| // example | |
| split "multi.fasta" "output" | |
| #endif |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment