-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
create BEDUtilities for FASTAExtract
create a new class for shared methods to be used across script classes, starting with FASTAExtract's loadCoord method. This static method loads a BED file into an ArrayList of BEDCoord objects. Other minor changes: - CLI PrintStream object set to STDERR
- Loading branch information
Showing
3 changed files
with
87 additions
and
51 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
package util; | ||
|
||
import java.io.BufferedReader; | ||
import java.io.File; | ||
import java.io.FileInputStream; | ||
import java.io.IOException; | ||
import java.io.InputStreamReader; | ||
import java.io.UnsupportedEncodingException; | ||
import java.util.ArrayList; | ||
import java.util.Arrays; | ||
import java.util.zip.GZIPInputStream; | ||
|
||
import objects.CoordinateObjects.BEDCoord; | ||
|
||
/** | ||
* Class containing a set of shared methods to be used across script classes. | ||
* | ||
* @author Olivia Lang | ||
* @see scripts.Sequence_Analysis.FASTAExtract | ||
*/ | ||
public class BEDUtilities { | ||
|
||
/** | ||
* Load a list of BEDCoord objects from a file. | ||
* | ||
* @param INPUT the BED-formatted input file to load | ||
* @param HEADER the style of FASTA-header to use for the output (true = BED | ||
* coord name, false = use Genomic Coordinate) | ||
* @return | ||
* @throws IOException | ||
* @throws UnsupportedEncodingException | ||
*/ | ||
public static ArrayList<BEDCoord> loadCoord(File input, boolean HEADER) throws UnsupportedEncodingException, IOException { | ||
ArrayList<BEDCoord> COORD = new ArrayList<BEDCoord>(); | ||
// Check if file is gzipped and instantiate appropriate BufferedReader | ||
BufferedReader br; | ||
if (GZipUtilities.isGZipped(input)) { | ||
br = new BufferedReader(new InputStreamReader(new GZIPInputStream(new FileInputStream(input)), "UTF-8")); | ||
} else { | ||
br = new BufferedReader(new InputStreamReader(new FileInputStream(input), "UTF-8")); | ||
} | ||
// Initialize line variable to loop through | ||
String line = br.readLine(); | ||
while (line != null) { | ||
String[] temp = line.split("\t"); | ||
if (temp.length > 2) { | ||
if (!temp[0].contains("track") && !temp[0].contains("#")) { | ||
String name = ""; | ||
|
||
if (!HEADER) { // create genomic coordinate name if requested | ||
if (temp.length > 5) { | ||
name = temp[0] + ":" + temp[1] + "-" + temp[2] + "(" + temp[5] + ")"; | ||
} else { | ||
name = temp[0] + ":" + temp[1] + "-" + temp[2] + "(.)"; | ||
} | ||
} else { // else create name based on BED file name or create one if non-existent | ||
if (temp.length > 3) { | ||
name = temp[3]; | ||
} else { | ||
name = temp[0] + ":" + temp[1] + "-" + temp[2] + "(" + temp[5] + ")"; | ||
} | ||
} | ||
|
||
if (Integer.parseInt(temp[1]) >= 0) { | ||
if (temp[5].equals("+")) { | ||
COORD.add(new BEDCoord(temp[0], Integer.parseInt(temp[1]), Integer.parseInt(temp[2]), "+", | ||
name)); | ||
} else { | ||
COORD.add(new BEDCoord(temp[0], Integer.parseInt(temp[1]), Integer.parseInt(temp[2]), "-", | ||
name)); | ||
} | ||
} else { | ||
System.out.println("Invalid Coordinate in File!!!\n" + Arrays.toString(temp)); | ||
} | ||
} | ||
} | ||
line = br.readLine(); | ||
} | ||
br.close(); | ||
return COORD; | ||
} | ||
} |
40d3ef4
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Related too #65