Advertisement
Guest User

Untitled

a guest
Apr 22nd, 2019
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.63 KB | None | 0 0
  1. package task_3.task_3;
  2. /*
  3. import java.io.BufferedReader;
  4. import java.io.FileNotFoundException;
  5. import java.io.FileReader;
  6. import java.util.Iterator;
  7.  
  8. //import javax.swing.text.html.HTMLDocument.Iterator;
  9.  
  10. import org.biojava.bio.BioException;
  11. import org.biojava.bio.seq.Feature;
  12. import org.biojava.bio.seq.FeatureFilter;
  13. import org.biojava.bio.seq.FeatureHolder;
  14. import org.biojavax.Note;
  15. import org.biojavax.RichAnnotation;
  16. import org.biojavax.RichObjectFactory;
  17. import org.biojavax.bio.seq.RichFeature;
  18. import org.biojavax.bio.seq.RichSequence;
  19. import org.biojavax.ontology.ComparableTerm;
  20. */
  21. //Java libraries
  22. import java.io.*;
  23. import java.util.*;
  24. //BioJava libraries
  25. import org.biojava.bio.*;
  26. import org.biojava.bio.seq.*;
  27. import org.biojava.bio.seq.io.*;
  28. //BioJava extension libraries
  29. import org.biojavax.*;
  30. import org.biojavax.ontology.*;
  31. import org.biojavax.bio.*;
  32. import org.biojavax.bio.seq.*;
  33.  
  34. public class ExtractInformation {
  35.  
  36. //Create the RichSequence object
  37. RichSequence richSeq;
  38.  
  39. //ExtractInformation constructor
  40. public ExtractInformation(String fileName){
  41. //fileName = "ACTG1.gb" ;
  42. //Load the sequence file
  43. try {
  44. richSeq = RichSequence.IOTools.readGenbankDNA(new BufferedReader(new FileReader(fileName)),null).nextRichSequence();
  45. }
  46. catch(FileNotFoundException fnfe){
  47. System.out.println("FileNotFoundException: " + fnfe);
  48. }
  49. catch(BioException bioe1){
  50. System.err.println("Not a Genbank sequence trying EMBL");
  51. try {
  52. richSeq = RichSequence.IOTools.readEMBLDNA(new BufferedReader(new FileReader(fileName)),null).nextRichSequence();
  53. }
  54. catch(BioException bioe2){
  55. System.err.println("Not an EMBL sequence either");
  56. System.exit(1);
  57. }
  58. catch(FileNotFoundException fnfe){
  59. System.out.println("FileNotFoundException: " + fnfe);
  60. }
  61. }
  62. //Filter the sequence on CDS features
  63. FeatureFilter ff = new FeatureFilter.ByType("CDS");
  64. FeatureHolder fh = richSeq.filter(ff);
  65.  
  66. //Iterate through the CDS features
  67. for (Iterator i = fh.features(); i.hasNext();){//мб косяк в итераторе будет
  68. RichFeature rf = (RichFeature)i.next();
  69. //Get the strand orientation of the feature
  70. char featureStrand = rf.getStrand().getToken();
  71.  
  72. //Get the location of the feature
  73. String featureLocation = rf.getLocation().toString();
  74. System.out.println(featureLocation);
  75. }
  76. }
  77. //Main method
  78. public static void main(String args []) {
  79. if (args.length != 1){
  80. System.out.println("Usage: java ExtractInformation ``");
  81. System.exit(1);
  82. } else {
  83. new ExtractInformation(args[0]);
  84. }
  85. }
  86. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement