1 /* Copyright (c) 2011 Peter Troshin
\r
3 * JAva Bioinformatics Analysis Web Services (JABAWS) @version: 2.0
\r
5 * This library is free software; you can redistribute it and/or modify it under the terms of the
\r
6 * Apache License version 2 as published by the Apache Software Foundation
\r
8 * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
\r
9 * even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the Apache
\r
10 * License for more details.
\r
12 * A copy of the license is in apache_license.txt. It is also available here:
\r
13 * @see: http://www.apache.org/licenses/LICENSE-2.0.txt
\r
15 * Any republication or derived work distributed in source code form
\r
16 * must include this copyright and license notice.
\r
19 package compbio.data.sequence;
\r
21 import java.io.BufferedReader;
\r
22 import java.io.BufferedWriter;
\r
23 import java.io.Closeable;
\r
24 import java.io.File;
\r
25 import java.io.FileInputStream;
\r
26 import java.io.IOException;
\r
27 import java.io.InputStream;
\r
28 import java.io.InputStreamReader;
\r
29 import java.io.OutputStream;
\r
30 import java.io.OutputStreamWriter;
\r
31 import java.util.ArrayList;
\r
32 import java.util.HashMap;
\r
33 import java.util.HashSet;
\r
34 import java.util.List;
\r
35 import java.util.Map;
\r
36 import java.util.Scanner;
\r
37 import java.util.Set;
\r
38 import java.util.TreeSet;
\r
39 import java.util.logging.Level;
\r
40 import java.util.regex.Matcher;
\r
41 import java.util.regex.Pattern;
\r
43 import compbio.util.Util;
\r
46 * Utility class for operations on sequences
\r
48 * @author Peter Troshin
\r
50 * @version 2.0 June 2011
\r
52 public final class SequenceUtil {
\r
55 * A whitespace character: [\t\n\x0B\f\r]
\r
57 public static final Pattern WHITE_SPACE = Pattern.compile("\\s");
\r
62 public static final Pattern DIGIT = Pattern.compile("\\d");
\r
67 public static final Pattern NONWORD = Pattern.compile("\\W");
\r
72 public static final Pattern AA = Pattern.compile("[ARNDCQEGHILKMFPSTWYV]+",
\r
73 Pattern.CASE_INSENSITIVE);
\r
76 * inversion of AA pattern
\r
78 public static final Pattern NON_AA = Pattern.compile(
\r
79 "[^ARNDCQEGHILKMFPSTWYV]+", Pattern.CASE_INSENSITIVE);
\r
82 * Same as AA pattern but with two additional letters - XU
\r
84 public static final Pattern AMBIGUOUS_AA = Pattern.compile(
\r
85 "[ARNDCQEGHILKMFPSTWYVXU]+", Pattern.CASE_INSENSITIVE);
\r
88 * Nucleotides a, t, g, c, u
\r
90 public static final Pattern NUCLEOTIDE = Pattern.compile("[AGTCU]+",
\r
91 Pattern.CASE_INSENSITIVE);
\r
94 * Ambiguous nucleotide
\r
96 public static final Pattern AMBIGUOUS_NUCLEOTIDE = Pattern.compile(
\r
97 "[AGTCRYMKSWHBVDNU]+", Pattern.CASE_INSENSITIVE); // see IUPAC
\r
101 public static final Pattern NON_NUCLEOTIDE = Pattern.compile("[^AGTCU]+",
\r
102 Pattern.CASE_INSENSITIVE);
\r
104 private SequenceUtil() {
\r
105 } // utility class, no instantiation
\r
108 * @return true is the sequence contains only letters a,c, t, g, u
\r
110 public static boolean isNucleotideSequence(final FastaSequence s) {
\r
111 return SequenceUtil.isNonAmbNucleotideSequence(s.getSequence());
\r
115 * Ambiguous DNA chars : AGTCRYMKSWHBVDN // differs from protein in only one
\r
118 public static boolean isNonAmbNucleotideSequence(String sequence) {
\r
119 sequence = SequenceUtil.cleanSequence(sequence);
\r
120 if (SequenceUtil.DIGIT.matcher(sequence).find()) {
\r
123 if (SequenceUtil.NON_NUCLEOTIDE.matcher(sequence).find()) {
\r
126 * System.out.format("I found the text starting at " +
\r
127 * "index %d and ending at index %d.%n", nonDNAmatcher .start(),
\r
128 * nonDNAmatcher.end());
\r
131 final Matcher DNAmatcher = SequenceUtil.NUCLEOTIDE.matcher(sequence);
\r
132 return DNAmatcher.find();
\r
136 * Removes all whitespace chars in the sequence string
\r
139 * @return cleaned up sequence
\r
141 public static String cleanSequence(String sequence) {
\r
142 assert sequence != null;
\r
143 final Matcher m = SequenceUtil.WHITE_SPACE.matcher(sequence);
\r
144 sequence = m.replaceAll("").toUpperCase();
\r
149 * Removes all special characters and digits as well as whitespace chars
\r
150 * from the sequence
\r
153 * @return cleaned up sequence
\r
155 public static String deepCleanSequence(String sequence) {
\r
156 sequence = SequenceUtil.cleanSequence(sequence);
\r
157 sequence = SequenceUtil.DIGIT.matcher(sequence).replaceAll("");
\r
158 sequence = SequenceUtil.NONWORD.matcher(sequence).replaceAll("");
\r
159 final Pattern othernonSeqChars = Pattern.compile("[_-]+");
\r
160 sequence = othernonSeqChars.matcher(sequence).replaceAll("");
\r
165 * Remove all non AA chars from the sequence
\r
168 * the sequence to clean
\r
169 * @return cleaned sequence
\r
171 public static String cleanProteinSequence(String sequence) {
\r
172 return SequenceUtil.NON_AA.matcher(sequence).replaceAll("");
\r
177 * @return true is the sequence is a protein sequence, false overwise
\r
179 public static boolean isProteinSequence(String sequence) {
\r
180 sequence = SequenceUtil.cleanSequence(sequence);
\r
181 if (SequenceUtil.isNonAmbNucleotideSequence(sequence)) {
\r
184 if (SequenceUtil.DIGIT.matcher(sequence).find()) {
\r
187 if (SequenceUtil.NON_AA.matcher(sequence).find()) {
\r
190 final Matcher protmatcher = SequenceUtil.AA.matcher(sequence);
\r
191 return protmatcher.find();
\r
195 * Check whether the sequence confirms to amboguous protein sequence
\r
198 * @return return true only if the sequence if ambiguous protein sequence
\r
199 * Return false otherwise. e.g. if the sequence is non-ambiguous
\r
202 public static boolean isAmbiguosProtein(String sequence) {
\r
203 sequence = SequenceUtil.cleanSequence(sequence);
\r
204 if (SequenceUtil.isNonAmbNucleotideSequence(sequence)) {
\r
207 if (SequenceUtil.DIGIT.matcher(sequence).find()) {
\r
210 if (SequenceUtil.NON_AA.matcher(sequence).find()) {
\r
213 if (SequenceUtil.AA.matcher(sequence).find()) {
\r
216 final Matcher amb_prot = SequenceUtil.AMBIGUOUS_AA.matcher(sequence);
\r
217 return amb_prot.find();
\r
221 * Writes list of FastaSequeces into the outstream formatting the sequence
\r
222 * so that it contains width chars on each line
\r
227 * - the maximum number of characters to write in one line
\r
228 * @throws IOException
\r
230 public static void writeFasta(final OutputStream outstream,
\r
231 final List<FastaSequence> sequences, final int width)
\r
232 throws IOException {
\r
233 writeFastaKeepTheStream(outstream, sequences, width);
\r
237 public static void writeFastaKeepTheStream(final OutputStream outstream,
\r
238 final List<FastaSequence> sequences, final int width)
\r
239 throws IOException {
\r
240 final OutputStreamWriter writer = new OutputStreamWriter(outstream);
\r
241 final BufferedWriter fastawriter = new BufferedWriter(writer);
\r
242 for (final FastaSequence fs : sequences) {
\r
243 fastawriter.write(">" + fs.getId() + "\n");
\r
244 fastawriter.write(fs.getFormatedSequence(width));
\r
245 fastawriter.write("\n");
\r
247 fastawriter.flush();
\r
252 * Reads fasta sequences from inStream into the list of FastaSequence
\r
257 * @return list of FastaSequence objects
\r
258 * @throws IOException
\r
260 public static List<FastaSequence> readFasta(final InputStream inStream)
\r
261 throws IOException {
\r
262 final List<FastaSequence> seqs = new ArrayList<FastaSequence>();
\r
263 FastaReader reader = new FastaReader(inStream);
\r
264 while (reader.hasNext()) {
\r
265 seqs.add(reader.next());
\r
272 * Writes FastaSequence in the file, each sequence will take one line only
\r
276 * @throws IOException
\r
278 public static void writeFasta(final OutputStream os,
\r
279 final List<FastaSequence> sequences) throws IOException {
\r
280 final OutputStreamWriter outWriter = new OutputStreamWriter(os);
\r
281 final BufferedWriter fasta_out = new BufferedWriter(outWriter);
\r
282 for (final FastaSequence fs : sequences) {
\r
283 fasta_out.write(fs.getOnelineFasta());
\r
290 * Read IUPred output
\r
293 * @return Map key->sequence name, value->Score
\r
294 * @throws IOException
\r
295 * @throws UnknownFileFormatException
\r
297 public static Map<String, Score> readIUPred(final File result)
\r
298 throws IOException, UnknownFileFormatException {
\r
299 InputStream input = new FileInputStream(result);
\r
300 Map<String, Score> sequences = readIUPred(input,
\r
301 IUPredResult.getType(result));
\r
306 // Check the type of the file e.g. long| short or domain
\r
321 * @throws IOException
\r
322 * @throws UnknownFileFormatException
\r
326 private static Map<String, Score> readIUPred(InputStream input,
\r
327 IUPredResult type) throws IOException, UnknownFileFormatException {
\r
329 Score score = null;
\r
330 final Map<String, Score> seqs = new HashMap<String, Score>();
\r
331 Scanner scan = new Scanner(input);
\r
332 scan.useDelimiter("#");
\r
333 while (scan.hasNext()) {
\r
334 String nextEntry = scan.next();
\r
335 Scanner entry = new Scanner(nextEntry);
\r
336 String name = entry.nextLine().trim();
\r
338 if (IUPredResult.Glob == type) {
\r
340 TreeSet<Range> ranges = parseIUPredDomains(entry);
\r
341 score = new Score(type, ranges);
\r
343 // parse short | long
\r
344 float[] scores = parseIUPredScores(entry);
\r
345 score = new Score(type, scores);
\r
348 seqs.put(name, score);
\r
358 * Number of globular domains: 2
\r
360 * globular domain 1. 98 - 269
\r
362 * globular domain 2. 431 - 482
\r
366 * meepqsdpsv epplsqetfs dlwkllpenn vlsplpsqam ddlmlspddi eqwftedpgp
\r
370 private static TreeSet<Range> parseIUPredDomains(Scanner scan) {
\r
371 String header = "Number of globular domains:";
\r
372 String domainPref = "globular domain";
\r
373 TreeSet<Range> ranges = new TreeSet<Range>();
\r
374 String line = scan.nextLine().trim();
\r
375 assert line.startsWith(header);
\r
376 line = line.substring(header.length()).trim();
\r
377 int domainNum = Integer.parseInt(line);
\r
378 if (domainNum == 0) {
\r
382 for (int i = 0; i < domainNum; i++) {
\r
383 assert scan.hasNextLine();
\r
384 line = scan.nextLine();
\r
385 assert line.trim().startsWith(domainPref);
\r
386 line = line.substring(line.indexOf(".") + 1).trim();
\r
387 Range r = new Range(line.split("-"));
\r
398 private static float[] parseIUPredScores(Scanner scan)
\r
399 throws UnknownFileFormatException {
\r
400 List<String> annotation = new ArrayList<String>();
\r
401 while (scan.hasNextLine()) {
\r
402 String line = scan.nextLine().trim();
\r
403 String[] val = line.split("\\s+");
\r
404 annotation.add(val[2]);
\r
406 return convertToNumber(annotation
\r
407 .toArray(new String[annotation.size()]));
\r
410 public static Map<String, Score> readJRonn(final File result)
\r
411 throws IOException, UnknownFileFormatException {
\r
412 InputStream input = new FileInputStream(result);
\r
413 Map<String, Score> sequences = readJRonn(input);
\r
419 * Reader for JRonn horizontal file format
\r
422 * >Foobar M G D T T A G 0.48 0.42
\r
423 * 0.42 0.48 0.52 0.53 0.54
\r
426 * Where all values are tab delimited
\r
429 * the InputStream connected to the JRonn output file
\r
430 * @return Map key=sequence name value=Score
\r
431 * @throws IOException
\r
432 * is thrown if the inStream has problems accessing the data
\r
433 * @throws UnknownFileFormatException
\r
434 * is thrown if the inStream represents an unknown source of
\r
435 * data, i.e. not a JRonn output
\r
437 public static Map<String, Score> readJRonn(final InputStream inStream)
\r
438 throws IOException, UnknownFileFormatException {
\r
439 final Map<String, Score> seqs = new HashMap<String, Score>();
\r
441 final BufferedReader infasta = new BufferedReader(
\r
442 new InputStreamReader(inStream, "UTF8"), 16000);
\r
447 line = infasta.readLine();
\r
448 if (line == null || line.isEmpty()) {
\r
449 // skip empty lines
\r
452 if (line.startsWith(">")) {
\r
454 sname = line.trim().substring(1);
\r
455 // read sequence line
\r
456 line = infasta.readLine();
\r
457 final String sequence = line.replace("\t", "");
\r
458 // read annotation line
\r
459 line = infasta.readLine();
\r
460 String[] annotValues = line.split("\t");
\r
461 float[] annotation = convertToNumber(annotValues);
\r
462 if (annotation.length != sequence.length()) {
\r
463 throw new UnknownFileFormatException(
\r
464 "File does not look like Jronn horizontally formatted output file!\n"
\r
465 + JRONN_WRONG_FORMAT_MESSAGE);
\r
467 seqs.put(sname, new Score(DisorderMethod.JRonn, annotation));
\r
469 } while (line != null);
\r
475 private static float[] convertToNumber(String[] annotValues)
\r
476 throws UnknownFileFormatException {
\r
477 float[] annotation = new float[annotValues.length];
\r
479 for (int i = 0; i < annotation.length; i++) {
\r
480 annotation[i] = Float.parseFloat(annotValues[i]);
\r
482 } catch (NumberFormatException e) {
\r
483 throw new UnknownFileFormatException(JRONN_WRONG_FORMAT_MESSAGE,
\r
489 private static final String JRONN_WRONG_FORMAT_MESSAGE = "Jronn file must be in the following format:\n"
\r
490 + ">sequence_name\n "
\r
492 + "0.43 0.22 0.65\n"
\r
493 + "Where first line is the sequence name,\n"
\r
494 + "second line is the tab delimited sequence,\n"
\r
495 + "third line contains tab delimited disorder prediction values.\n"
\r
496 + "No lines are allowed between these three. Additionally, the number of "
\r
497 + "sequence residues must be equal to the number of the disorder values.";
\r
500 * Closes the Closable and logs the exception if any
\r
505 public final static void closeSilently(java.util.logging.Logger log,
\r
506 Closeable stream) {
\r
507 if (stream != null) {
\r
510 } catch (IOException e) {
\r
511 log.log(Level.WARNING, e.getLocalizedMessage(), e.getCause());
\r
518 > Foobar_dundeefriends
\r
520 * # COILS 34-41, 50-58, 83-91, 118-127, 160-169, 191-220, 243-252, 287-343
\r
524 * # HOTLOOPS 190-204
\r
526 * # RESIDUE COILS REM465 HOTLOOPS
\r
528 * M 0.86010 0.88512 0.37094
\r
530 * T 0.79983 0.85864 0.44331
\r
532 * >Next Sequence name
\r
537 * @return Map key=sequence name, value=set of score
\r
538 * @throws IOException
\r
539 * @throws UnknownFileFormatException
\r
541 public static HashMap<String, Set<Score>> readDisembl(
\r
542 final InputStream input) throws IOException,
\r
543 UnknownFileFormatException {
\r
544 Scanner scan = new Scanner(input);
\r
545 scan.useDelimiter(">");
\r
546 if (!scan.hasNext()) {
\r
547 throw new UnknownFileFormatException(
\r
548 "In Disembl score format each sequence score is expected "
\r
549 + "to start from the line: >Sequence name "
\r
550 + " No such line was found!");
\r
553 HashMap<String, Set<Score>> results = new HashMap<String, Set<Score>>();
\r
554 int seqCounter = 0;
\r
555 while (scan.hasNext()) {
\r
557 String singleSeq = scan.next();
\r
558 Scanner scansingle = new Scanner(singleSeq);
\r
559 if (!scansingle.hasNextLine()) {
\r
560 throw new RuntimeException(
\r
561 "The input looks like an incomplete disembl file - cannot parse!");
\r
564 StringBuffer seqbuffer = new StringBuffer();
\r
565 ArrayList<Float> coils = new ArrayList<Float>();
\r
566 ArrayList<Float> rem = new ArrayList<Float>();
\r
567 ArrayList<Float> hotloops = new ArrayList<Float>();
\r
569 String sequenceName = scansingle.nextLine().trim();
\r
570 TreeSet<Range> coilsR = parseRanges(DisemblResult.COILS,
\r
571 scansingle.nextLine());
\r
572 TreeSet<Range> rem465R = parseRanges(DisemblResult.REM465,
\r
573 scansingle.nextLine());
\r
574 TreeSet<Range> loopsR = parseRanges(DisemblResult.HOTLOOPS,
\r
575 scansingle.nextLine());
\r
577 String title = scansingle.nextLine();
\r
578 assert title.startsWith("# RESIDUE COILS REM465 HOTLOOPS") : ">Sequence_name must follow column title: # RESIDUE COILS REM465 HOTLOOPS!";
\r
580 while (scansingle.hasNext()) {
\r
581 seqbuffer.append(scansingle.next());
\r
582 coils.add(scansingle.nextFloat());
\r
583 rem.add(scansingle.nextFloat());
\r
584 hotloops.add(scansingle.nextFloat());
\r
587 * Also possible FastaSequence fs = new FastaSequence(sequenceName,
\r
588 * seqbuffer.toString());
\r
590 HashSet<Score> scores = new HashSet<Score>();
\r
591 scores.add(new Score(DisemblResult.COILS, coils, coilsR));
\r
592 scores.add(new Score(DisemblResult.HOTLOOPS, hotloops, rem465R));
\r
593 scores.add(new Score(DisemblResult.REM465, rem, loopsR));
\r
594 results.put(sequenceName, scores);
\r
596 scansingle.close();
\r
606 * # COILS 34-41, 50-58, 83-91, 118-127, 160-169, 191-220, 243-252, 287-343,
\r
607 * 350-391, 429-485, 497-506, 539-547
\r
611 * # HOTLOOPS 190-204
\r
616 private static TreeSet<Range> parseRanges(Enum resultType, String lines) {
\r
617 TreeSet<Range> ranges = new TreeSet<Range>();
\r
619 Scanner scan = new Scanner(lines);
\r
621 assert scan.hasNext();
\r
622 String del = scan.next();
\r
623 assert "#".equals(del); // pass delimiter #
\r
624 String type = scan.next(); // pass enum name e.g. COILS
\r
625 assert resultType.toString().equalsIgnoreCase(type) : "Unknown result type: "
\r
626 + resultType.toString();
\r
628 // beginning of the ranges
\r
629 scan.useDelimiter(",");
\r
630 while (scan.hasNext()) {
\r
631 String range = scan.next();
\r
632 if (!Util.isEmpty(range)) {
\r
633 ranges.add(new Range(range.split("-")));
\r
641 > Foobar_dundeefriends
\r
643 * # COILS 34-41, 50-58, 83-91, 118-127, 160-169, 191-220, 243-252, 287-343
\r
647 * # HOTLOOPS 190-204
\r
649 * # RESIDUE COILS REM465 HOTLOOPS
\r
651 * M 0.86010 0.88512 0.37094
\r
653 * T 0.79983 0.85864 0.44331
\r
655 * >Next Sequence name
\r
659 * @return Map key=sequence name, value=set of score
\r
660 * @throws IOException
\r
661 * @throws UnknownFileFormatException
\r
663 public static HashMap<String, Set<Score>> readGlobPlot(
\r
664 final InputStream input) throws IOException,
\r
665 UnknownFileFormatException {
\r
666 Scanner scan = new Scanner(input);
\r
667 scan.useDelimiter(">");
\r
668 if (!scan.hasNext()) {
\r
669 throw new UnknownFileFormatException(
\r
670 "In GlobPlot score format each sequence score is expected "
\r
671 + "to start from the line: >Sequence name "
\r
672 + " No such line was found!");
\r
675 HashMap<String, Set<Score>> results = new HashMap<String, Set<Score>>();
\r
676 int seqCounter = 0;
\r
677 while (scan.hasNext()) {
\r
679 String singleSeq = scan.next();
\r
680 Scanner scansingle = new Scanner(singleSeq);
\r
681 if (!scansingle.hasNextLine()) {
\r
682 throw new RuntimeException(
\r
683 "The input looks like an incomplete GlobPlot file - cannot parse!");
\r
686 StringBuffer seqbuffer = new StringBuffer();
\r
687 ArrayList<Float> dydxScore = new ArrayList<Float>();
\r
688 ArrayList<Float> rawScore = new ArrayList<Float>();
\r
689 ArrayList<Float> smoothedScore = new ArrayList<Float>();
\r
691 String sequenceName = scansingle.nextLine().trim();
\r
692 TreeSet<Range> domsR = parseRanges(GlobProtResult.GlobDoms,
\r
693 scansingle.nextLine());
\r
694 TreeSet<Range> disorderR = parseRanges(GlobProtResult.Disorder,
\r
695 scansingle.nextLine());
\r
697 String title = scansingle.nextLine();
\r
698 assert title.startsWith("# RESIDUE DYDX") : ">Sequence_name must follow column title: # RESIDUE DYDX RAW SMOOTHED!";
\r
700 while (scansingle.hasNext()) {
\r
701 seqbuffer.append(scansingle.next());
\r
702 dydxScore.add(scansingle.nextFloat());
\r
703 rawScore.add(scansingle.nextFloat());
\r
704 smoothedScore.add(scansingle.nextFloat());
\r
707 * Also possible FastaSequence fs = new FastaSequence(sequenceName,
\r
708 * seqbuffer.toString());
\r
710 Set<Score> scores = new TreeSet<Score>();
\r
711 scores.add(new Score(GlobProtResult.Disorder, disorderR));
\r
712 scores.add(new Score(GlobProtResult.GlobDoms, domsR));
\r
713 scores.add(new Score(GlobProtResult.Dydx, dydxScore));
\r
714 scores.add(new Score(GlobProtResult.RawScore, rawScore));
\r
715 scores.add(new Score(GlobProtResult.SmoothedScore, smoothedScore));
\r
716 results.put(sequenceName, scores);
\r
718 scansingle.close();
\r
725 * Read AACon result with no alignment files. This method leaves incoming
\r
726 * InputStream open!
\r
729 * output file of AAConservation
\r
730 * @return Map with keys {@link ConservationMethod} -> float[]
\r
732 public static HashSet<Score> readAAConResults(InputStream results) {
\r
733 if (results == null) {
\r
734 throw new NullPointerException(
\r
735 "InputStream with results must be provided");
\r
737 HashSet<Score> annotations = new HashSet<Score>();
\r
738 Scanner sc = new Scanner(results);
\r
739 sc.useDelimiter("#");
\r
740 while (sc.hasNext()) {
\r
741 String line = sc.next();
\r
742 int spacePos = line.indexOf(" ");
\r
743 assert spacePos > 0 : "Space is expected as delimited between method "
\r
744 + "name and values!";
\r
745 String methodLine = line.substring(0, spacePos);
\r
746 ConservationMethod method = ConservationMethod
\r
747 .getMethod(methodLine);
\r
748 assert method != null : "Method " + methodLine
\r
749 + " is not recognized! ";
\r
750 Scanner valuesScanner = new Scanner(line.substring(spacePos));
\r
751 ArrayList<Float> values = new ArrayList<Float>();
\r
752 while (valuesScanner.hasNextDouble()) {
\r
753 Double value = valuesScanner.nextDouble();
\r
754 values.add(value.floatValue());
\r
756 annotations.add(new Score(method, values));
\r
758 return annotations;
\r
762 * Reads and parses Fasta or Clustal formatted file into a list of
\r
763 * FastaSequence objects
\r
765 * @param inFilePath
\r
766 * the path to the input file
\r
767 * @throws IOException
\r
768 * if the file denoted by inFilePath cannot be read
\r
769 * @throws UnknownFileFormatException
\r
770 * if the inFilePath points to the file which format cannot be
\r
772 * @return the List of FastaSequence objects
\r
775 public static List<FastaSequence> openInputStream(String inFilePath)
\r
776 throws IOException, UnknownFileFormatException {
\r
778 // This stream gets closed in isValidClustalFile method
\r
779 InputStream inStrForValidation = new FileInputStream(inFilePath);
\r
780 // This stream is closed in the calling methods
\r
781 InputStream inStr = new FileInputStream(inFilePath);
\r
782 List<FastaSequence> fastaSeqs = null;
\r
783 if (ClustalAlignmentUtil.isValidClustalFile(inStrForValidation)) {
\r
784 Alignment al = ClustalAlignmentUtil.readClustalFile(inStr);
\r
785 // alignment cannot be null see
\r
786 // ClustalAlignmentUtil.readClustalFile(inStr);
\r
787 fastaSeqs = al.getSequences();
\r
789 fastaSeqs = SequenceUtil.readFasta(inStr);
\r
796 enum DisemblResult {
\r
797 /** These contains ranges and scores */
\r
798 COILS, REM465, HOTLOOPS
\r
800 enum GlobProtResult {
\r
801 /** This a range with no scores */
\r
803 /** This a range with no scores */
\r
805 /** This a score with no range */
\r
807 /** This a score with no range */
\r
809 /** This a score with no range */
\r
813 enum IUPredResult {
\r
827 static IUPredResult getType(File file) {
\r
828 assert file != null;
\r
829 String name = file.getName();
\r
830 if (name.endsWith(Long.toString().toLowerCase())) {
\r
833 if (name.endsWith(Short.toString().toLowerCase())) {
\r
836 if (name.endsWith(Glob.toString().toLowerCase())) {
\r
839 throw new AssertionError(
\r
840 "IUPred result file type cannot be recognised! "
\r
841 + "\nFile must ends with one of [glob, long or short]"
\r
842 + "\n but given file name was: " + file.getName());
\r