示例#1
0
 /**
  * Removes duplicate adjacent {@link #getPositions() positions} from this route, leaving only
  * distinct neighbours
  */
 public void removeDuplicates() {
   List<P> positions = getPositions();
   P previous = null;
   int index = 0;
   while (index < positions.size()) {
     P next = positions.get(index);
     if (previous != null && (!next.hasCoordinates() || next.calculateDistance(previous) <= 0.0)) {
       positions.remove(index);
     } else index++;
     previous = next;
   }
 }
  private static List<String> importGenomeData(
      File genome_text_file, String target_organism, int sex) throws IOException {

    List<String> temp_genome_data =
        new ArrayList<String>(); // The genome data array that contains the sizes of each chromosome
    // int haploid_number; // Used to determine the size of the first dimension in the
    // temp_genome_data array
    boolean found_target_organism =
        false; // Used to determine what action to take when a new header line in the file is found;
    // close if true, keep reading if false
    boolean end_of_genome = false; // True when the Y chromosome has been dealt with

    // Construct BufferedReader from FileReader; search for header line of target organism and
    // obtain the haploid number then create a two dimensional array, size of the first dimension
    // equals the haploid number, size of second dimension equals two (two chromosomes to form
    // deploid organism)
    // At this point, the next lines correspond to the size of each chromosome so populate the newly
    // created array
    // with this information. Stop reading when no more new lines or when a new header line is found
    BufferedReader genome_file_reader = new BufferedReader(new FileReader(genome_text_file));

    String line = null;
    StringBuilder organism_name;
    while ((line = genome_file_reader.readLine()) != null) {
      String[] split_line = line.split(" ");

      if (split_line[0].equals(">")) // If this is a first header line
      {
        organism_name =
            new StringBuilder()
                .append(split_line[1])
                .append(" ")
                .append(
                    split_line[
                        2]); // Recreate the genus and species of the organism from the strings that
        // were separated during the splitting of the line
        if (organism_name
            .toString()
            .equals(target_organism)) // If this line refers to the organism of interest
        {
          found_target_organism = true;
          haploid_number =
              Integer.parseInt(split_line[4]); // Get the haploid number stored in the header line
        } else {
          found_target_organism = false;
          continue; // This is a header line but it is not the organism of interest
        }
      } else if (found_target_organism
          && !end_of_genome) // This is not a header line and we probably want to import this line
      {
        // boolean autosome = true;
        switch (sex) {
          case 1: // Female
            {
              if (split_line[0].equals("chrX")) {
                temp_genome_data.add(split_line[1] + "," + split_line[1]);
              } else if (split_line[0].equals("chrY")) {
                end_of_genome = true;
              } // Ignore the Y chromosome
              else
                temp_genome_data.add(
                    split_line[1] + "," + split_line[1]); // The current line is an autosome
            }
            break;
          case 2: // Male
            {
              if (split_line[0].equals("chrX")) {
                temp_genome_data.add(split_line[1] + ",");
              } else if (split_line[0].equals("chrY")) {
                String temp =
                    temp_genome_data.get(
                        temp_genome_data.size() - 1); // Store the value already there
                temp_genome_data.remove(temp_genome_data.size() - 1);

                temp = temp + split_line[1];
                temp_genome_data.add(temp);

                end_of_genome = true;
              } else
                temp_genome_data.add(
                    split_line[1] + "," + split_line[1]); // The current line is an autosome
            }
            break;
        }
      }
    } // while ((line = genome_file_reader.readLine()) != null)
    genome_file_reader.close();
    return temp_genome_data;
  } // importGenomeData
示例#3
0
 public P remove(int index) {
   List<P> positions = getPositions();
   return positions.remove(index);
 }