1 |
import java.io.File; |
2 |
import java.io.FileNotFoundException; |
3 |
import java.io.IOException; |
4 |
import java.io.PrintStream; |
5 |
|
6 |
import owl.core.sequence.alignment.AlignmentConstructionException; |
7 |
import owl.core.sequence.alignment.MultipleSequenceAlignment; |
8 |
import owl.core.util.FileFormatException; |
9 |
|
10 |
public class pir2fasta { |
11 |
|
12 |
/*------------------------------ constants ------------------------------*/ |
13 |
|
14 |
/** |
15 |
* To read a input file in pir format and write to a output file or stdout in fasta format |
16 |
* @param args |
17 |
*/ |
18 |
public static void main(String[] args) { |
19 |
|
20 |
if(args.length < 1 || args.length > 2) { |
21 |
System.out.println("Usage: pir2fasta input.pir [output.fa]"); |
22 |
System.exit(1); |
23 |
} |
24 |
|
25 |
String inputfilename = args[0]; |
26 |
String outputfilename = null; |
27 |
|
28 |
if(!new File(inputfilename).canRead()) { |
29 |
System.err.println("Error: Could not read from file " + inputfilename); |
30 |
System.exit(1); |
31 |
} |
32 |
|
33 |
PrintStream ps = System.out; |
34 |
|
35 |
if (args.length == 2){ |
36 |
outputfilename = args[1]; |
37 |
try { |
38 |
ps = new PrintStream(outputfilename); |
39 |
} catch (FileNotFoundException e1) { |
40 |
System.out.println("Failed to open file " + outputfilename + ": " + e1.getMessage()); |
41 |
System.exit(1); |
42 |
} |
43 |
} |
44 |
|
45 |
|
46 |
//create a multiple sequence alignment from the input pir file |
47 |
MultipleSequenceAlignment ma = null; |
48 |
try { |
49 |
ma = new MultipleSequenceAlignment(inputfilename, MultipleSequenceAlignment.PIRFORMAT); |
50 |
ma.writeFasta(ps, 80, true); |
51 |
if(outputfilename != null) { |
52 |
System.out.println(inputfilename + " -> " + outputfilename); |
53 |
} |
54 |
} catch (IOException e) { |
55 |
System.err.println("Error while processing " + inputfilename + ": " + e.getMessage()); |
56 |
} catch (FileFormatException e) { |
57 |
System.err.println("Invalid format of " + inputfilename + ": " + e.getMessage()); |
58 |
} catch (AlignmentConstructionException e) { |
59 |
System.err.println("Failed to create alignment from file " + inputfilename + ": " + e.getMessage()); |
60 |
} |
61 |
} |
62 |
|
63 |
} |