read files

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • amoon
    New Member
    • Oct 2007
    • 5

    #1

    read files

    hello every bady
    I have a big problems please help me
    I have a file like this:
    > YAL005C YAR002W
    > YAL005C YPL240C
    > YLR335W YAL005C
    > YLR335W YGL097W
    > YLR335W YMR047C
    > YNL064C YAL005C
    > YLR335W YAR002W
    > YGL097W YAR002W
    > YMR047C YAR002W
    which is names for protins
    and I want to read this file to get matrix as output
    for every protins and it is intaractions protins
    for example; protein YAL005C interacts
    > with YAR002W, YPL240C, YLR335W and YNL064C and doesn't interact
    > with the other 2.
    > * The output will be 7X7 matrix
    >
    > 1 1 1 1 0 0 1
    > 1 1 0 1 1 1 0
    > 1 0 1 0 0 0 0
    > 1 1 0 1 1 1 0
    > 0 1 0 1 1 0 0
    > 0 1 0 1 0 1 0
    > 1 0 0 0 0 0 1
    how can i writ the cod
    I wait ASAP
  • JosAH
    Recognized Expert MVP
    • Mar 2007
    • 11453

    #2
    Consider a TreeMap<String, Set<String>>; the keys are the protein codes,
    the values are Sets of proteins that 'interact' with the key proteins.

    Adding a new protein pair can be done as follows:

    [code=java]
    public void add(Map<String> map, Set<String>>, String protein, String otherProtein) {

    Set<String others;
    if ((others= map.get(protein )) == null)
    map.put(protein , others= new HashSet<String> ());
    others.put(othe rProtein);
    }
    [/code]

    Producing a matrix given that map is easy.

    kind regards,

    Jos

    Comment

    • amoon
      New Member
      • Oct 2007
      • 5

      #3
      Dear Jos

      I don't want to add protins I want to get the interaction protins in a matrix
      package tASk1;
      import java.util.*;
      import java.io.*;
      import java.util.Scann er;


      public class read {
      public static void main(String args[]){
      try{
      FileInputStream fstream = new FileInputStream ("interactions. txt");
      DataInputStream in = new DataInputStream (fstream);
      BufferedReader br = new BufferedReader( new InputStreamRead er(in));
      String strLine;
      Protein p=new Protein();
      while ((strLine=br.re adLine())!=null ){
      if(p.getPNameIn Col1().contentE quals("YAL005C" )&&(p.getPNameI nCol2().content Equals("YAR002W ")));
      System.out.prin tln(strLine);
      }
      in.close();
      }catch (Exception e){
      System.err.prin tln("Error: "+e.getMessage( ));
      }}






      }


      I do this code put my problems in the if statment
      help me

      Comment

      • r035198x
        MVP
        • Sep 2006
        • 13225

        #4
        Originally posted by amoon
        Dear Jos

        I don't want to add protins I want to get the interaction protins in a matrix
        package tASk1;
        import java.util.*;
        import java.io.*;
        import java.util.Scann er;


        public class read {
        public static void main(String args[]){
        try{
        FileInputStream fstream = new FileInputStream ("interactions. txt");
        DataInputStream in = new DataInputStream (fstream);
        BufferedReader br = new BufferedReader( new InputStreamRead er(in));
        String strLine;
        Protein p=new Protein();
        while ((strLine=br.re adLine())!=null ){
        if(p.getPNameIn Col1().contentE quals("YAL005C" )&&(p.getPNameI nCol2().content Equals("YAR002W ")));
        System.out.prin tln(strLine);
        }
        in.close();
        }catch (Exception e){
        System.err.prin tln("Error: "+e.getMessage( ));
        }}






        }


        I do this code put my problems in the if statment
        help me
        Please use code tags for posting code.
        The correct methods of reading a text file are described here.

        Comment

        • JosAH
          Recognized Expert MVP
          • Mar 2007
          • 11453

          #5
          Originally posted by amoon
          Dear Jos

          I don't want to add protins I want to get the interaction protins in a matrix
          Maybe you don't realize it yet but you do want to add those proteins to that map.
          Given that map you can generate the matrix without even thinking.

          I think you just have problems with reading a text file.

          kind regards,

          Jos

          Comment

          • amoon
            New Member
            • Oct 2007
            • 5

            #6
            maybe I always get error in the if statmen whcih is under while loop
            can u help me in that

            Comment

            • JosAH
              Recognized Expert MVP
              • Mar 2007
              • 11453

              #7
              Originally posted by amoon
              maybe I always get error in the if statmen whcih is under while loop
              can u help me in that
              I really can't say in advance; what's the exact error message? Mondays are my
              non-psychic days ... ;-)

              kind regards,

              Jos

              Comment

              • r035198x
                MVP
                • Sep 2006
                • 13225

                #8
                Originally posted by amoon
                maybe I always get error in the if statmen whcih is under while loop
                can u help me in that
                It would help if you were reading the responses being given to you.

                Comment

                Working...